export class SimpleWysiwygEditorInterface {
protected context: EditorUiContext;
+ protected onChangeListeners: (() => void)[] = [];
+ protected editorListenerTeardown: (() => void)|null = null;
constructor(context: EditorUiContext) {
this.context = context;
return await getEditorContentAsHtml(this.context.editor);
}
+ onChange(listener: () => void) {
+ this.onChangeListeners.push(listener);
+ this.startListeningToChanges();
+ }
+
focus(): void {
focusEditor(this.context.editor);
}
remove() {
- this.context.editorDOM.remove();
this.context.manager.teardown();
+ this.context.containerDOM.remove();
+ if (this.editorListenerTeardown) {
+ this.editorListenerTeardown();
+ }
+ }
+
+ protected startListeningToChanges(): void {
+ if (this.editorListenerTeardown) {
+ return;
+ }
+
+ this.editorListenerTeardown = this.context.editor.registerUpdateListener(() => {
+ for (const listener of this.onChangeListeners) {
+ listener();
+ }
+ });
}
}
\ No newline at end of file