diff --git a/src/editor/core/plugin/Plugin.ts b/src/editor/core/plugin/Plugin.ts new file mode 100644 index 0000000..4188f0a --- /dev/null +++ b/src/editor/core/plugin/Plugin.ts @@ -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(pluginFunction: PluginFunction, options?: Options) { + pluginFunction(this.editor, options) + } + +} \ No newline at end of file diff --git a/src/editor/index.ts b/src/editor/index.ts index 883a7ec..a92ce1f 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -45,13 +45,16 @@ import { ListStyle, ListType } from './dataset/enum/List' import { ICatalog, ICatalogItem } from './interface/Catalog' import { IPlaceholder } from './interface/Placeholder' import { defaultPlaceholderOption } from './dataset/constant/Placeholder' +import { Plugin } from './core/plugin/Plugin' +import { UsePlugin } from './interface/Plugin' export default class Editor { public command: Command public listener: Listener public register: Register - public destroy: Function + public destroy: () => void + public use: UsePlugin constructor(container: HTMLDivElement, data: IEditorData | IElement[], options: IEditorOption = {}) { const headerOptions: Required = { @@ -185,6 +188,9 @@ export default class Editor { shortcut.removeEvent() contextMenu.removeEvent() } + // 插件 + const plugin = new Plugin(this) + this.use = plugin.use.bind(plugin) } } diff --git a/src/editor/interface/Plugin.ts b/src/editor/interface/Plugin.ts new file mode 100644 index 0000000..26d458d --- /dev/null +++ b/src/editor/interface/Plugin.ts @@ -0,0 +1,5 @@ +import Editor from '..' + +export type PluginFunction = (editor: Editor, options?: Options) => any; + +export type UsePlugin = (pluginFunction: PluginFunction, options?: Options) => void; \ No newline at end of file