import RibbonComponent from '../schema/RibbonComponent' ; import { Editor , EditorPlugin } from 'roosterjs-editor-core' ; import { PluginEvent , PluginEventType } from 'roosterjs-editor-types' ; export default class RibbonPlugin implements EditorPlugin { private editor : Editor ; private ribbons : RibbonComponent [ ] = [ ] ; constructor ( private onButtonClick ? ) { } public getName ( ) { return 'Ribbon' ; } public initialize ( editor ) { this . editor = editor ; } public dispose ( ) { this . editor = null ; } public onPluginEvent ( event ) { if ( event . eventType == PluginEventType . KeyUp || event . eventType == PluginEventType . MouseUp || event . eventType == PluginEventType . ContentChanged ) { this . ribbons . forEach ( ribbon => ribbon . onFormatChange ( ) ) ; } } public getEditor ( ) { return this . editor ; } public buttonClick ( buttonName ) { if ( this . onButtonClick ) { this . onButtonClick ( buttonName ) ; } } public registerRibbonComponent ( ribbon ) { if ( this . ribbons . indexOf ( ribbon ) < 0 ) { this . ribbons . push ( ribbon ) ; } } public unregisterRibbonComponent ( ribbon ) { let index = this . ribbons . indexOf ( ribbon ) ; if ( index >= 0 ) { this . ribbons . splice ( index , 1 ) ; } } public resize ( ) { this . ribbons . forEach ( ribbon => ribbon . onResize ( ) ) ; } }