feat: add plugin interface
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import Editor from '../..'
|
||||||
|
import { PluginFunction } from '../../interface/Plugin'
|
||||||
|
|
||||||
|
export class Plugin {
|
||||||
|
|
||||||
|
private editor: Editor
|
||||||
|
|
||||||
|
constructor(editor: Editor) {
|
||||||
|
this.editor = editor
|
||||||
|
}
|
||||||
|
|
||||||
|
public use<Options>(pluginFunction: PluginFunction<Options>, options?: Options) {
|
||||||
|
pluginFunction(this.editor, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+7
-1
@@ -45,13 +45,16 @@ import { ListStyle, ListType } from './dataset/enum/List'
|
|||||||
import { ICatalog, ICatalogItem } from './interface/Catalog'
|
import { ICatalog, ICatalogItem } from './interface/Catalog'
|
||||||
import { IPlaceholder } from './interface/Placeholder'
|
import { IPlaceholder } from './interface/Placeholder'
|
||||||
import { defaultPlaceholderOption } from './dataset/constant/Placeholder'
|
import { defaultPlaceholderOption } from './dataset/constant/Placeholder'
|
||||||
|
import { Plugin } from './core/plugin/Plugin'
|
||||||
|
import { UsePlugin } from './interface/Plugin'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
|
|
||||||
public command: Command
|
public command: Command
|
||||||
public listener: Listener
|
public listener: Listener
|
||||||
public register: Register
|
public register: Register
|
||||||
public destroy: Function
|
public destroy: () => void
|
||||||
|
public use: UsePlugin
|
||||||
|
|
||||||
constructor(container: HTMLDivElement, data: IEditorData | IElement[], options: IEditorOption = {}) {
|
constructor(container: HTMLDivElement, data: IEditorData | IElement[], options: IEditorOption = {}) {
|
||||||
const headerOptions: Required<IHeader> = {
|
const headerOptions: Required<IHeader> = {
|
||||||
@@ -185,6 +188,9 @@ export default class Editor {
|
|||||||
shortcut.removeEvent()
|
shortcut.removeEvent()
|
||||||
contextMenu.removeEvent()
|
contextMenu.removeEvent()
|
||||||
}
|
}
|
||||||
|
// 插件
|
||||||
|
const plugin = new Plugin(this)
|
||||||
|
this.use = plugin.use.bind(plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import Editor from '..'
|
||||||
|
|
||||||
|
export type PluginFunction<Options> = (editor: Editor, options?: Options) => any;
|
||||||
|
|
||||||
|
export type UsePlugin = <Options>(pluginFunction: PluginFunction<Options>, options?: Options) => void;
|
||||||
Reference in New Issue
Block a user