communication-react-19
Version:
React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)
41 lines • 1.28 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { PluginEventType } from '../../utils/RichTextEditorUtils';
/**
* KeyboardInputPlugin is a plugin for handling keyboard events in the editor.
*/
export class KeyboardInputPlugin {
constructor() {
this.editor = null;
this.disposer = null;
// don't set callback in constructor to be able to update callback without plugin recreation
this.onKeyDown = null;
this.onCompositionUpdate = null;
}
getName() {
return 'KeyboardInputPlugin';
}
/**
* Initialize this plugin
* @param editor The editor instance
*/
initialize(editor) {
this.editor = editor;
this.disposer = this.editor.attachDomEvent({
compositionupdate: { beforeDispatch: this.onCompositionUpdate }
});
}
dispose() {
this.editor = null;
if (this.disposer) {
this.disposer();
this.disposer = null;
}
}
onPluginEvent(event) {
if (this.onKeyDown && event.eventType === PluginEventType.KeyDown && event.rawEvent instanceof KeyboardEvent) {
this.onKeyDown(event.rawEvent);
}
}
}
//# sourceMappingURL=KeyboardInputPlugin.js.map