remove old commands

This commit is contained in:
Philipp Kühn
2018-10-28 22:17:21 +01:00
parent dcba6686dc
commit 1e88fa1cb6
4 changed files with 13 additions and 38 deletions

View File

@@ -1,36 +1,36 @@
<template> <template>
<div class="editor"> <div class="editor">
<menu-bar class="menubar" :editor="editor"> <menu-bar class="menubar" :editor="editor">
<template slot-scope="{ nodes, marks, newCommands }"> <template slot-scope="{ nodes, marks, commands }">
<button <button
class="menubar__button" class="menubar__button"
@click="newCommands.history" @click="commands.history"
v-if="newCommands.history" v-if="commands.history"
> >
</button> </button>
<button <button
class="menubar__button" class="menubar__button"
@click="newCommands.undo" @click="commands.undo"
v-if="newCommands.undo" v-if="commands.undo"
> >
</button> </button>
<button <button
class="menubar__button" class="menubar__button"
@click="newCommands.redo" @click="commands.redo"
v-if="newCommands.redo" v-if="commands.redo"
> >
</button> </button>
<button <button
class="menubar__button" class="menubar__button"
@click="newCommands.undoRedo" @click="commands.undoRedo"
v-if="newCommands.undoRedo" v-if="commands.undoRedo"
> >
undoredo undoredo
</button> </button>

View File

@@ -12,7 +12,7 @@ export default {
marks: this.editor.menuActions.marks, marks: this.editor.menuActions.marks,
focused: this.editor.view.focused, focused: this.editor.view.focused,
focus: this.editor.focus, focus: this.editor.focus,
newCommands: this.editor.newCommands, commands: this.editor.commands,
})) }))
} }
}, },

View File

@@ -53,13 +53,6 @@ export default class Editor {
this.view = this.createView() this.view = this.createView()
this.commands = this.createCommands() this.commands = this.createCommands()
this.newCommands = this.extensions.newCommands({
schema: this.schema,
view: this.view,
})
console.log(this.newCommands)
this.updateMenuActions() this.updateMenuActions()
this.emit('init') this.emit('init')

View File

@@ -87,31 +87,13 @@ export default class ExtensionManager {
} }
commands({ schema, view }) { commands({ schema, view }) {
return this.extensions
.filter(extension => ['node', 'mark'].includes(extension.type))
.filter(extension => extension.command)
.reduce((commands, { name, type, command }) => ({
...commands,
[name]: attrs => {
view.focus()
const provider = command({
type: schema[`${type}s`][name],
attrs,
schema,
})
const callbacks = Array.isArray(provider) ? provider : [provider]
callbacks.forEach(callback => callback(view.state, view.dispatch, view))
},
}), {})
}
newCommands({ schema, view }) {
return this.extensions return this.extensions
.filter(extension => extension.commands) .filter(extension => extension.commands)
.reduce((allCommands, { name, type, commands: provider }) => { .reduce((allCommands, { name, type, commands: provider }) => {
// TODO
// view.focus()
const commands = {} const commands = {}
const value = provider({ const value = provider({
schema, schema,