Skip to content

Commit

Permalink
feat: add plugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Jun 25, 2023
1 parent ca28454 commit ad0bb32
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/editor/core/plugin/Plugin.ts
Original file line number Diff line number Diff line change
@@ -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)
}

}
8 changes: 7 additions & 1 deletion src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHeader> = {
Expand Down Expand Up @@ -185,6 +188,9 @@ export default class Editor {
shortcut.removeEvent()
contextMenu.removeEvent()
}
// 插件
const plugin = new Plugin(this)
this.use = plugin.use.bind(plugin)
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/editor/interface/Plugin.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ad0bb32

Please sign in to comment.