add handlePlugins option to registerPlugin
This commit is contained in:
@@ -109,23 +109,17 @@ export class Editor extends EventEmitter {
|
|||||||
return this.proxy
|
return this.proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerPlugin(plugin: Plugin) {
|
public registerPlugin(plugin: Plugin, handlePlugins?: (plugin: Plugin, plugins: Plugin[]) => Plugin[]) {
|
||||||
if (!plugin) {
|
const plugins = typeof handlePlugins === 'function'
|
||||||
return
|
? handlePlugins(plugin, this.state.plugins)
|
||||||
}
|
: [plugin, ...this.state.plugins]
|
||||||
|
|
||||||
const state = this.state.reconfigure({
|
const state = this.state.reconfigure({ plugins })
|
||||||
plugins: [plugin, ...this.state.plugins],
|
|
||||||
})
|
|
||||||
|
|
||||||
this.view.updateState(state)
|
this.view.updateState(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregisterPlugin(name: string) {
|
public unregisterPlugin(name: string) {
|
||||||
if (!name) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = this.state.reconfigure({
|
const state = this.state.reconfigure({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(`${name}$`)),
|
plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(`${name}$`)),
|
||||||
|
|||||||
Reference in New Issue
Block a user