From 3195a2e338f899360b01ff5eaa0a0fb0eaa5c9d5 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 16 May 2022 16:10:46 +0800 Subject: [PATCH] ui: milkdown: upgrade prose version --- package.json | 1 + packages/ui-default/build/config/webpack.js | 1 + packages/ui-default/components/editor/index.ts | 15 ++++----------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 8c569b6de..a7d8dc93e 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "typescript": "^4.6.4" }, "resolutions": { + "@milkdown/prose": "^6.1.0", "esbuild": "0.14.3" } } diff --git a/packages/ui-default/build/config/webpack.js b/packages/ui-default/build/config/webpack.js index f9b4a8f8c..bf566bffe 100644 --- a/packages/ui-default/build/config/webpack.js +++ b/packages/ui-default/build/config/webpack.js @@ -100,6 +100,7 @@ export default function (env = {}) { modules: [root('node_modules'), root('../../node_modules')], extensions: ['.js', '.jsx', '.ts', '.tsx'], alias: { + '@milkdown/prose': '@milkdown/prose/lib', vj: root(), }, }, diff --git a/packages/ui-default/components/editor/index.ts b/packages/ui-default/components/editor/index.ts index ce1eb0ecf..31783a8e4 100644 --- a/packages/ui-default/components/editor/index.ts +++ b/packages/ui-default/components/editor/index.ts @@ -151,14 +151,14 @@ export default class VjEditor extends DOMAttachedObject { const isProblemEdit = pagename === 'problem_edit'; const [ { - Editor, rootCtx, defaultValueCtx, editorViewCtx, parserCtx, serializerCtx, + Editor, rootCtx, defaultValueCtx, editorViewCtx, serializerCtx, }, - { nord }, { Slice }, { gfm }, { listener, listenerCtx }, + { nord }, { replaceAll }, { gfm }, { listener, listenerCtx }, { math }, { history }, { clipboard }, { tooltip }, { slash }, { emoji }, { upload, uploadPlugin }, { diagram }, { prism }, { cursor }, { menu }, ] = await Promise.all([ - import('@milkdown/core'), import('./theme'), import('@milkdown/prose'), + import('@milkdown/core'), import('./theme'), import('@milkdown/utils'), import('@milkdown/preset-gfm'), import('@milkdown/plugin-listener'), import('@milkdown/plugin-math'), import('@milkdown/plugin-history'), @@ -223,14 +223,7 @@ export default class VjEditor extends DOMAttachedObject { this.height = $(ele).height(); }); }); - this.milkdown.setValue = (val) => { - this.milkdown.action((ctx) => { - const view = ctx.get(editorViewCtx); - const doc = ctx.get(parserCtx)(val); - if (!doc) return; - view.dispatch(view.state.tr.replace(0, view.state.doc.content.size, new Slice(doc.content, 0, 0))); - }); - }; + this.milkdown.setValue = (val) => this.milkdown.action(replaceAll(val)); this.milkdown.getValue = () => this.milkdown.action((ctx) => { const editorView = ctx.get(editorViewCtx); const serializer = ctx.get(serializerCtx);