Skip to content

Commit

Permalink
feat(monaco-editor): 实现侧边栏编辑器 | Implement sidebar editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuoqiu-Yingyi committed Jul 15, 2023
1 parent 7d5ac79 commit bae5ddd
Show file tree
Hide file tree
Showing 25 changed files with 1,225 additions and 153 deletions.
File renamed without changes.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:^"
}
}
Empty file added public/README.md
Empty file.
Empty file added public/README_zh_CN.md
Empty file.
21 changes: 20 additions & 1 deletion public/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
21 changes: 20 additions & 1 deletion public/i18n/zh_CHT.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{
"displayName": "代碼編輯器"
"displayName": "程式碼編輯器",
"dock": {
"kramdown": {
"ariaLabel": "編輯 kramdown"
},
"title": "程式碼編輯"
},
"editor": {
"action": {
"save": {
"label": "保存"
},
"saveAs": {
"label": "另存為"
},
"toggleWordWrap": {
"label": "切換自動換行"
}
}
}
}
21 changes: 20 additions & 1 deletion public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{
"displayName": "代码编辑器"
"displayName": "代码编辑器",
"dock": {
"kramdown": {
"ariaLabel": "编辑 kramdown"
},
"title": "代码编辑"
},
"editor": {
"action": {
"save": {
"label": "保存"
},
"saveAs": {
"label": "另存为"
},
"toggleWordWrap": {
"label": "切换自动换行"
}
}
}
}
Binary file added public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions public/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "monaco-editor",
"author": "Zuoqiu Yingyi",
"url": "https://github.com/Zuoqiu-Yingyi/siyuan-plugin-webview",
"version": "0.0.0",
"minAppVersion": "2.9.5",
"backends": [
"all"
],
"frontends": [
"desktop",
"desktop-window",
"browser-desktop"
],
"displayName": {
"default": "Code Editor",
"zh_CN": "代码编辑器",
"zh_CHT": "程式碼編輯器"
},
"description": {
"default": "Use the <a href='https://microsoft.github.io/monaco-editor/'>Monaco Editor</a> to view and edit code.",
"zh_CN": "使用 <a href='https://microsoft.github.io/monaco-editor/'>Monaco Editor</a> 查看与编辑代码。",
"zh_CHT": "使用 <a href='https://microsoft.github.io/monaco-editor/'>Monaco Editor</a> 檢視與編輯程式碼。"
},
"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"
]
}
}
74 changes: 74 additions & 0 deletions src/components/Dock.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--
Copyright (C) 2023 Zuoqiu Yingyi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<script lang="ts">
import type { ComponentEvents } from "svelte";
import Bar from "@workspace/components/siyuan/dock/block/Bar.svelte";
import Editor from "./Editor.svelte";
import regexp from "@workspace/utils/regexp";
import type { IBar } from "@workspace/components/siyuan/dock/block/index";
import type MonacoEditorPlugin from "@/index";
import type { IDockEditor } from "@/types/editor";
export let plugin: InstanceType<typeof MonacoEditorPlugin>; // 插件对象
export let id: string; // 块 ID
export let kramdown: boolean; // 是否启用 kramdown 模式
export let bar: IBar; // 标题栏配置
export let editor: IDockEditor; // 编辑器配置
$: {
if (regexp.id.test(id)) {
if (kramdown) {
plugin.client
.getBlockKramdown({ id })
.then(response => {
editor.modified.value = response.data.kramdown;
})
.catch(err => plugin.logger.error(err));
} else {
// TODO: markdown 模式
}
}
}
function save(e: ComponentEvents<Editor>["save"]) {
if (kramdown) {
plugin.client
.updateBlock({
id,
dataType: "markdown",
data: e.detail.value,
})
.catch(err => plugin.logger.error(err));
} else {
// TODO: markdown 模式
}
}
</script>

<Bar {...bar} />
<Editor
on:save={save}
{...editor}
{plugin}
embed={true}
savable={true}
locale={globalThis.siyuan.config.lang}
/>
Loading

0 comments on commit bae5ddd

Please sign in to comment.