diff --git a/packages/vscode/package.json b/packages/vscode/package.json index a3e22bf9..c22ed4c5 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -3,7 +3,7 @@ "displayName": "any-reader", "description": "any-reader for vscode", "icon": "resources/icon.png", - "version": "0.5.4", + "version": "0.5.5", "preview": true, "publisher": "aooiu", "qna": "https://github.com/aooiuu/any-reader/issues", diff --git a/packages/vscode/src/webview/index.ts b/packages/vscode/src/webview/index.ts index 8d7db4df..bcb8d300 100644 --- a/packages/vscode/src/webview/index.ts +++ b/packages/vscode/src/webview/index.ts @@ -54,7 +54,7 @@ export class WebView { this.pm.emit('getBookSource', ruleFileManager.list(), source); } - // 获取单个谷子额 + // 获取单个规则 onGetRule({ source, data }: { source: WebView; data: Rule }) { const rules = ruleFileManager.list(); this.pm.emit( diff --git a/packages/web/package.json b/packages/web/package.json index 37dd26ee..9b068ec3 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "any-reader-web", - "version": "0.5.4", + "version": "0.5.5", "private": true, "type": "module", "scripts": { @@ -21,6 +21,7 @@ "dplayer": "^1.27.1", "easy-post-message": "^0.1.0", "hls.js": "^1.5.3", + "monaco-editor": "0.47.0", "pinia": "^2.1.7", "uuid": "^9.0.1", "vue": "^3.4.15", diff --git a/packages/web/src/main.ts b/packages/web/src/main.ts index f4aaaee0..bb374b46 100644 --- a/packages/web/src/main.ts +++ b/packages/web/src/main.ts @@ -13,6 +13,8 @@ import '@arco-design/web-vue/dist/arco.css'; import { createPinia } from 'pinia'; +import '@/utils/monaco'; + const app = createApp(App); app.use(router); diff --git a/packages/web/src/pages/rule-info/MonacoEditor.vue b/packages/web/src/pages/rule-info/MonacoEditor.vue new file mode 100644 index 00000000..4c270478 --- /dev/null +++ b/packages/web/src/pages/rule-info/MonacoEditor.vue @@ -0,0 +1,43 @@ + + + diff --git a/packages/web/src/pages/rule-info/index.vue b/packages/web/src/pages/rule-info/index.vue index d0cb7d64..06ea9ade 100644 --- a/packages/web/src/pages/rule-info/index.vue +++ b/packages/web/src/pages/rule-info/index.vue @@ -4,26 +4,32 @@
+ 双栏 Form JSON
- - - -
{{ JSON.stringify(formData, null, 4) }}
+
+ + + + +
+ +
+
@@ -38,13 +44,14 @@ import { v4 as uuidV4 } from 'uuid'; import { CONTENT_TYPES, CONTENT_TYPE } from '@/constants'; import { postMessage, useMessage } from '@/utils/postMessage'; +import MonacoEditor from './MonacoEditor.vue'; const loading = ref(false); const router = useRouter(); const route = useRoute(); -const formType = ref('Form'); +const formType = ref('All'); const formItems = [ { prop: 'id', label: 'uuid', show: () => false }, @@ -140,6 +147,17 @@ const formData = reactive({ viewStyle: '' }); +// 规则字符串 +const formDataText = computed(() => JSON.stringify(formData, null, 4)); + +// 更新规则 +function setFormData(v) { + const json = JSON.parse(v); + Object.keys(formData).forEach((k) => { + formData[k] = json[k]; + }); +} + function submit() { postMessage('addRule', { ...formData, diff --git a/packages/web/src/utils/monaco.ts b/packages/web/src/utils/monaco.ts new file mode 100644 index 00000000..76049e04 --- /dev/null +++ b/packages/web/src/utils/monaco.ts @@ -0,0 +1,27 @@ +import * as monaco from 'monaco-editor'; +import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; +import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'; +// import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'; +// import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'; +// import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'; + +// @ts-ignore +self.MonacoEnvironment = { + getWorker(_: any, label: string) { + if (label === 'json') { + return new jsonWorker(); + } + // if (label === 'css' || label === 'scss' || label === 'less') { + // return new cssWorker(); + // } + // if (label === 'html' || label === 'handlebars' || label === 'razor') { + // return new htmlWorker(); + // } + // if (label === 'typescript' || label === 'javascript') { + // return new tsWorker(); + // } + return new editorWorker(); + } +}; + +monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aeb46caf..3dbc9daf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -202,6 +202,9 @@ importers: hls.js: specifier: ^1.5.3 version: 1.5.3 + monaco-editor: + specifier: 0.47.0 + version: 0.47.0 pinia: specifier: ^2.1.7 version: 2.1.7(typescript@5.3.3)(vue@3.4.15) @@ -8086,6 +8089,10 @@ packages: commander: 7.2.0 dev: true + /monaco-editor@0.47.0: + resolution: {integrity: sha512-VabVvHvQ9QmMwXu4du008ZDuyLnHs9j7ThVFsiJoXSOQk18+LF89N4ADzPbFenm0W4V2bGHnFBztIRQTgBfxzw==} + dev: false + /mrmime@2.0.0: resolution: {integrity: sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==} engines: {node: '>=10'}