refactoring

This commit is contained in:
Philipp Kühn 2020-03-07 23:37:58 +01:00
parent 486d0e0f5f
commit a067259da1
3 changed files with 11 additions and 7 deletions

View File

@ -11,14 +11,16 @@ import { gapCursor } from 'prosemirror-gapcursor'
import elementFromString from './utils/elementFromString'
import injectCSS from './utils/injectCSS'
import ExtensionManager from './ExtensionManager'
import Extension from './Extension'
import Node from './Node'
type EditorContent = string | JSON
type Command = (next: Function, editor: Editor, ...args: any) => any
interface Options {
element?: Node
element?: globalThis.Node
content: EditorContent
extensions: [any?]
extensions: (Extension | Node)[]
injectCSS: Boolean
}

View File

@ -18,9 +18,9 @@ export default abstract class Extension {
public type = 'extension'
protected created() {}
public created() {}
protected bindEditor(editor: Editor): void {
public bindEditor(editor: Editor): void {
this.editor = editor
}

View File

@ -1,12 +1,14 @@
import { keymap } from 'prosemirror-keymap'
import collect from 'collect.js'
import { Editor } from './Editor'
import Extension from './Extension'
import Node from './Node'
export default class ExtensionManager {
extensions: [any?]
extensions: (Extension | Node)[]
constructor(extensions: any = [], editor: Editor) {
constructor(extensions: (Extension | Node)[], editor: Editor) {
this.extensions = extensions
this.extensions.forEach(extension => {
extension.bindEditor(editor)
@ -15,7 +17,7 @@ export default class ExtensionManager {
}
get topNode() {
const topNode = this.extensions.find(extension => extension.topNode)
const topNode = collect(this.extensions).firstWhere('topNode', true)
if (topNode) {
return topNode.name