From 36198ed2ab74a1fca97c41f47d027f826d194203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 4 Mar 2020 22:40:08 +0100 Subject: [PATCH] refactoring --- packages/tiptap-core/src/Editor.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts index 301ce247..f629e1a2 100644 --- a/packages/tiptap-core/src/Editor.ts +++ b/packages/tiptap-core/src/Editor.ts @@ -13,9 +13,10 @@ import injectCSS from './utils/injectCSS' type EditorContent = string | JSON -interface EditorOptions { - element: Node +interface Options { + element?: Node content: EditorContent + injectCSS: Boolean } export class Editor { @@ -31,16 +32,21 @@ export class Editor { view: EditorView - options: EditorOptions + options: Options = { + content: '', + injectCSS: true, + } - constructor(options: EditorOptions) { - this.options = options + constructor(options: Options) { + this.options = { ...this.options, ...options } this.view = this.createView() this.registerCommand('focus', require('./commands/focus').default) this.registerCommand('insertText', require('./commands/insertText').default) this.registerCommand('insertHTML', require('./commands/insertHTML').default) - injectCSS(require('./style.css')) + if (this.options.injectCSS) { + injectCSS(require('./style.css')) + } } get state() { @@ -95,12 +101,12 @@ export class Editor { } private dispatchTransaction(transaction: any): void { - const newState = this.state.apply(transaction) - this.view.updateState(newState) - this.selection = { - from: this.state.selection.from, - to: this.state.selection.to, - } + const state = this.state.apply(transaction) + this.view.updateState(state) + + const { from, to } = this.state.selection + this.selection = { from, to } + // this.setActiveNodesAndMarks() // this.emit('transaction', {