refactoring

This commit is contained in:
Philipp Kühn 2020-03-30 14:49:48 +02:00
parent 1bc75751b3
commit 7aa173f45a

View File

@ -1,3 +1,4 @@
import collect from 'collect.js'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { EditorState, TextSelection } from 'prosemirror-state' import { EditorState, TextSelection } from 'prosemirror-state'
import { EditorView} from 'prosemirror-view' import { EditorView} from 'prosemirror-view'
@ -182,27 +183,17 @@ export class Editor extends EventEmitter {
} }
setActiveNodesAndMarks() { setActiveNodesAndMarks() {
this.activeMarks = Object this.activeMarks = collect(this.schema.marks)
.entries(this.schema.marks) .mapWithKeys((mark: any) => [mark.name, () => markIsActive(this.state, mark)])
.reduce((marks, [name, mark]) => ({ .all()
...marks,
// [name]: (attrs = {}) => markIsActive(this.state, mark, attrs),
[name]: () => markIsActive(this.state, mark),
}), {})
this.activeMarkAttrs = Object this.activeMarkAttrs = collect(this.schema.marks)
.entries(this.schema.marks) .mapWithKeys((mark: any) => [mark.name, () => getMarkAttrs(this.state, mark)])
.reduce((marks, [name, mark]) => ({ .all()
...marks,
[name]: getMarkAttrs(this.state, mark),
}), {})
this.activeNodes = Object this.activeNodes = collect(this.schema.nodes)
.entries(this.schema.nodes) .mapWithKeys((node: any) => [node.name, (attrs = {}) => nodeIsActive(this.state, node, attrs)])
.reduce((nodes, [name, node]) => ({ .all()
...nodes,
[name]: (attrs = {}) => nodeIsActive(this.state, node, attrs),
}), {})
} }
getMarkAttrs(name: string) { getMarkAttrs(name: string) {