refactoring
This commit is contained in:
@@ -13,9 +13,10 @@ import injectCSS from './utils/injectCSS'
|
|||||||
|
|
||||||
type EditorContent = string | JSON
|
type EditorContent = string | JSON
|
||||||
|
|
||||||
interface EditorOptions {
|
interface Options {
|
||||||
element: Node
|
element?: Node
|
||||||
content: EditorContent
|
content: EditorContent
|
||||||
|
injectCSS: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Editor {
|
export class Editor {
|
||||||
@@ -31,17 +32,22 @@ export class Editor {
|
|||||||
|
|
||||||
view: EditorView
|
view: EditorView
|
||||||
|
|
||||||
options: EditorOptions
|
options: Options = {
|
||||||
|
content: '',
|
||||||
|
injectCSS: true,
|
||||||
|
}
|
||||||
|
|
||||||
constructor(options: EditorOptions) {
|
constructor(options: Options) {
|
||||||
this.options = options
|
this.options = { ...this.options, ...options }
|
||||||
this.view = this.createView()
|
this.view = this.createView()
|
||||||
this.registerCommand('focus', require('./commands/focus').default)
|
this.registerCommand('focus', require('./commands/focus').default)
|
||||||
this.registerCommand('insertText', require('./commands/insertText').default)
|
this.registerCommand('insertText', require('./commands/insertText').default)
|
||||||
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
||||||
|
|
||||||
|
if (this.options.injectCSS) {
|
||||||
injectCSS(require('./style.css'))
|
injectCSS(require('./style.css'))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get state() {
|
get state() {
|
||||||
return this.view.state
|
return this.view.state
|
||||||
@@ -95,12 +101,12 @@ export class Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private dispatchTransaction(transaction: any): void {
|
private dispatchTransaction(transaction: any): void {
|
||||||
const newState = this.state.apply(transaction)
|
const state = this.state.apply(transaction)
|
||||||
this.view.updateState(newState)
|
this.view.updateState(state)
|
||||||
this.selection = {
|
|
||||||
from: this.state.selection.from,
|
const { from, to } = this.state.selection
|
||||||
to: this.state.selection.to,
|
this.selection = { from, to }
|
||||||
}
|
|
||||||
// this.setActiveNodesAndMarks()
|
// this.setActiveNodesAndMarks()
|
||||||
|
|
||||||
// this.emit('transaction', {
|
// this.emit('transaction', {
|
||||||
|
|||||||
Reference in New Issue
Block a user