From 1c7b2181bc86b5afe9bd0641ea68cf8a0a2ddb53 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu <1171051090@qq.com> Date: Fri, 1 Jan 2021 15:21:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=85=83=E7=B4=A0=E6=8E=A5?= =?UTF-8?q?=E5=85=A5ProseMirror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/styles/prosemirror.scss | 53 ++++++++++ src/main.ts | 2 + src/mocks/index.ts | 2 +- src/prosemirror/index.ts | 28 ++++++ src/prosemirror/plugins/inputrules.ts | 2 +- src/prosemirror/schema/marks.ts | 58 +++++------ src/prosemirror/schema/nodes.ts | 87 +++++++++-------- src/utils/selection.ts | 4 + src/views/Editor/Canvas/index.vue | 2 + src/views/Editor/useHotkey.ts | 27 ++++-- .../element/LineElement/BaseLineElement.vue | 3 +- .../components/element/LineElement/index.vue | 3 +- .../element/ShapeElement/BaseShapeElement.vue | 3 +- .../components/element/ShapeElement/index.vue | 3 +- .../element/TextElement/BaseTextElement.vue | 16 +-- .../components/element/TextElement/index.vue | 97 ++++++++++++++++--- 16 files changed, 277 insertions(+), 113 deletions(-) create mode 100644 src/assets/styles/prosemirror.scss create mode 100644 src/prosemirror/index.ts create mode 100644 src/utils/selection.ts diff --git a/src/assets/styles/prosemirror.scss b/src/assets/styles/prosemirror.scss new file mode 100644 index 00000000..3867cbde --- /dev/null +++ b/src/assets/styles/prosemirror.scss @@ -0,0 +1,53 @@ +.ProseMirror, .ProseMirror-static { + outline: 0; + border: 0; + font-size: 20px; + line-height: 1.5; + word-break: break-word; + font-family: '微软雅黑'; + + ::selection { + background-color: rgba(27, 110, 232, 0.3); + color: inherit; + } + + p + p { + margin-top: 5px; + } + + ul { + list-style-type: disc; + padding-inline-start: 20px; + + li { + list-style-type: disc; + } + } + + ol { + list-style-type: decimal; + padding-inline-start: 20px; + + li { + list-style-type: decimal; + } + } + + code { + background-color: #eee; + padding: 1px 3px; + margin: 0 1px; + border-radius: 2px; + font-family: inherit; + } + + blockquote { + overflow: hidden; + padding-right: 1.2em; + padding-left: 1.2em; + margin-left: 0; + margin-right: 0; + font-style: italic; + border-left: 5px solid #ccc; + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index fe8e7f8e..3814f646 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,8 @@ import { createApp } from 'vue' import App from './App.vue' import store from './store' +import 'prosemirror-view/style/prosemirror.css' +import '@/assets/styles/prosemirror.scss' import '@/assets/styles/global.scss' import 'animate.css' diff --git a/src/mocks/index.ts b/src/mocks/index.ts index 306bb751..62741730 100644 --- a/src/mocks/index.ts +++ b/src/mocks/index.ts @@ -24,7 +24,7 @@ export const slides: Slide[] = [ }, opacity: 1, lock: false, - content: '
一段测试文字,字号固定为28px
', }, { id: 'xxx3', diff --git a/src/prosemirror/index.ts b/src/prosemirror/index.ts new file mode 100644 index 00000000..42a75bb9 --- /dev/null +++ b/src/prosemirror/index.ts @@ -0,0 +1,28 @@ +import { EditorState } from 'prosemirror-state' +import { EditorView } from 'prosemirror-view' +import { Schema, DOMParser } from 'prosemirror-model' + +import { buildPlugins } from './plugins/index' +import { schemaNodes, schemaMarks } from './schema/index' + +const schema = new Schema({ + nodes: schemaNodes, + marks: schemaMarks, +}) + +export const createDocument = (content: string) => { + const htmlString = `