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