@kangc/v-md-editor
Version:
A markdown editor built on Vue
30 lines (25 loc) • 681 B
JavaScript
import registerCommand from '@/utils/command';
export default function (Component) {
return {
created() {
const { commands } = Component;
this.commands = {};
Object.keys(commands).forEach((name) => {
this.registerCommand(name, commands[name]);
});
},
methods: {
registerCommand(name, callback) {
registerCommand(this.commands, name, callback);
},
execCommand(name, ...arg) {
const commandCallBack = this.commands[name];
if (commandCallBack) {
commandCallBack(this, ...arg);
} else {
console.error(`Command not found: ${name}`);
}
},
},
};
}