From 968b538acf38895b4433d63955f81b0e9ad91dbd Mon Sep 17 00:00:00 2001 From: jocs Date: Thu, 8 Nov 2018 22:44:45 +0800 Subject: [PATCH] opti: make UI components to plugins, disable spellcheck --- src/muya/lib/index.js | 27 ++++++++++--------- src/muya/lib/ui/codePicker/index.js | 1 + src/muya/lib/ui/emojiPicker/index.js | 1 + src/muya/lib/ui/formatPicker/index.js | 1 + src/muya/lib/ui/imagePicker/index.js | 1 + src/muya/lib/ui/quickInsert/index.js | 1 + src/muya/lib/ui/tablePicker/index.js | 1 + .../components/editorWithTabs/editor.vue | 14 +++++++++- 8 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/muya/lib/index.js b/src/muya/lib/index.js index 7a99c61c..74138904 100644 --- a/src/muya/lib/index.js +++ b/src/muya/lib/index.js @@ -7,16 +7,14 @@ import { CLASS_OR_ID, MUYA_DEFAULT_OPTION } from './config' import { wordCount } from './utils' import ExportMarkdown from './utils/exportMarkdown' import ExportHtml from './utils/exportHtml' -import TablePicker from './ui/tablePicker' import ToolTip from './ui/tooltip' -import QuickInsert from './ui/quickInsert' -import CodePicker from './ui/codePicker' -import EmojiPicker from './ui/emojiPicker' -import ImagePathPicker from './ui/imagePicker' -import FormatPicker from './ui/formatPicker' import './assets/styles/index.css' class Muya { + static plugins = [] + static use (plugin) { + this.plugins.push(plugin) + } constructor (container, options) { this.options = Object.assign({}, MUYA_DEFAULT_OPTION, options) const { focusMode, theme, markdown } = this.options @@ -26,12 +24,13 @@ class Muya { this.container = getContainer(container) this.eventCenter = new EventCenter() this.tooltip = new ToolTip(this) - this.quickInsert = new QuickInsert(this) - this.codePicker = new CodePicker(this) - this.tablePicker = new TablePicker(this) - this.emojiPicker = new EmojiPicker(this) - this.imagePathPicker = new ImagePathPicker(this) - this.formatPicker = new FormatPicker(this) + // UI plugins + if (Muya.plugins.length) { + for (const Plugin of Muya.plugins) { + this[Plugin.pluginName] = new Plugin(this) + } + } + this.contentState = new ContentState(this, this.options) this.clipboard = new Clipboard(this) this.clickEvent = new ClickEvent(this) @@ -276,7 +275,11 @@ function getContainer (originContainer) { Array.from(attrs).forEach(attr => { container.setAttribute(attr.name, attr.value) }) + container.setAttribute('contenteditable', true) + container.setAttribute('autocorrect', false) + container.setAttribute('autocomplete', 'off') + container.setAttribute('spellcheck', false) container.appendChild(rootDom) originContainer.replaceWith(container) return container diff --git a/src/muya/lib/ui/codePicker/index.js b/src/muya/lib/ui/codePicker/index.js index 53045ea4..b25e9638 100644 --- a/src/muya/lib/ui/codePicker/index.js +++ b/src/muya/lib/ui/codePicker/index.js @@ -6,6 +6,7 @@ import fileIcons from '../fileIcons' import './index.css' class CodePicker extends BaseScrollFloat { + static pluginName = 'codePicker' constructor (muya) { const name = 'ag-list-picker' super(muya, name) diff --git a/src/muya/lib/ui/emojiPicker/index.js b/src/muya/lib/ui/emojiPicker/index.js index e17be0fc..8636c792 100644 --- a/src/muya/lib/ui/emojiPicker/index.js +++ b/src/muya/lib/ui/emojiPicker/index.js @@ -4,6 +4,7 @@ import { patch, h } from '../../parser/render/snabbdom' import './index.css' class EmojiPicker extends BaseScrollFloat { + static pluginName = 'emojiPicker' constructor (muya) { const name = 'ag-emoji-picker' super(muya, name) diff --git a/src/muya/lib/ui/formatPicker/index.js b/src/muya/lib/ui/formatPicker/index.js index 802ad7bf..47205ffa 100644 --- a/src/muya/lib/ui/formatPicker/index.js +++ b/src/muya/lib/ui/formatPicker/index.js @@ -15,6 +15,7 @@ const defaultOptions = { } class FormatPicker extends BaseFloat { + static pluginName = 'formatPicker' constructor (muya, options = {}) { const name = 'ag-format-picker' const opts = Object.assign({}, defaultOptions, options) diff --git a/src/muya/lib/ui/imagePicker/index.js b/src/muya/lib/ui/imagePicker/index.js index d27a5684..6311ca09 100644 --- a/src/muya/lib/ui/imagePicker/index.js +++ b/src/muya/lib/ui/imagePicker/index.js @@ -11,6 +11,7 @@ const iconhash = { } class ImagePathPicker extends BaseScrollFloat { + static pluginName = 'imagePathPicker' constructor (muya) { const name = 'ag-list-picker' super(muya, name) diff --git a/src/muya/lib/ui/quickInsert/index.js b/src/muya/lib/ui/quickInsert/index.js index e1bb4bf7..8a4f57b3 100644 --- a/src/muya/lib/ui/quickInsert/index.js +++ b/src/muya/lib/ui/quickInsert/index.js @@ -6,6 +6,7 @@ import { quicInsertObj } from './config' import './index.css' class QuickInsert extends BaseScrollFloat { + static pluginName = 'quickInsert' constructor (muya) { const name = 'ag-quick-insert' super(muya, name) diff --git a/src/muya/lib/ui/tablePicker/index.js b/src/muya/lib/ui/tablePicker/index.js index 09579a0a..b9871a35 100644 --- a/src/muya/lib/ui/tablePicker/index.js +++ b/src/muya/lib/ui/tablePicker/index.js @@ -4,6 +4,7 @@ import './index.css' import { EVENT_KEYS } from '../../config' class TablePicker extends BaseFloat { + static pluginName = 'tablePicker' constructor (muya) { const name = 'ag-table-picker' super(muya, name) diff --git a/src/renderer/components/editorWithTabs/editor.vue b/src/renderer/components/editorWithTabs/editor.vue index 3cf48612..2564fc7e 100644 --- a/src/renderer/components/editorWithTabs/editor.vue +++ b/src/renderer/components/editorWithTabs/editor.vue @@ -64,6 +64,12 @@