add commands to extension manager
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Editor } from './src/Editor'
|
||||
import { Editor, CommandSpec } from './src/Editor'
|
||||
|
||||
export default Editor
|
||||
export { Editor }
|
||||
export { Editor, CommandSpec }
|
||||
export { default as Extension } from './src/Extension'
|
||||
export { default as Node } from './src/Node'
|
||||
export { default as Mark } from './src/Mark'
|
||||
|
||||
@@ -21,7 +21,10 @@ import Node from './Node'
|
||||
import EventEmitter from './EventEmitter'
|
||||
|
||||
type EditorContent = string | JSON | null
|
||||
type Command = (next: Function, editor: Editor, ...args: any) => any
|
||||
export type Command = (next: Function, editor: Editor, ...args: any) => any
|
||||
export interface CommandSpec {
|
||||
[key: string]: Command
|
||||
}
|
||||
|
||||
interface Options {
|
||||
content: EditorContent
|
||||
|
||||
@@ -41,6 +41,10 @@ export default abstract class Extension {
|
||||
|
||||
keys(): { [key: string]: any } {
|
||||
return {}
|
||||
}
|
||||
|
||||
commands(): { [key: string]: any } {
|
||||
return {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import collect from 'collect.js'
|
||||
import { keymap } from 'prosemirror-keymap'
|
||||
import { inputRules } from 'prosemirror-inputrules'
|
||||
import { Editor } from './Editor'
|
||||
import { Editor, CommandSpec } from './Editor'
|
||||
import Extension from './Extension'
|
||||
import Node from './Node'
|
||||
|
||||
@@ -16,11 +16,20 @@ export default class ExtensionManager {
|
||||
this.extensions.forEach(extension => {
|
||||
extension.bindEditor(editor)
|
||||
editor.on('schemaCreated', () => {
|
||||
this.registerCommands(extension.commands())
|
||||
extension.created()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
registerCommands(commands: CommandSpec) {
|
||||
Object
|
||||
.entries(commands)
|
||||
.forEach(([name, command]) => {
|
||||
this.editor.registerCommand(name, command)
|
||||
})
|
||||
}
|
||||
|
||||
get topNode() {
|
||||
const topNode = collect(this.extensions).firstWhere('topNode', true)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user