editor.js/src/components/modules/modificationsObserver.ts
Peter Savchenko 4f15bbc0cb
feat(onchange): callback now accepts custom event (#1791)
* feat(onchange): callback now accepts custom event

* Delete block-added.ts

* testd updated, changelog added

* Update example-dev.html

* indexes added to all events

* block-removed dispatching on block replacing

* Update example-dev.html
2021-10-05 20:40:44 +03:00

40 lines
787 B
TypeScript

import Module from '../__module';
import * as _ from '../utils';
/**
* Single entry point for Block mutation events
*/
export default class ModificationsObserver extends Module {
/**
* Flag shows onChange event is disabled
*/
private disabled = false;
/**
* Enables onChange event
*/
public enable(): void {
this.disabled = false;
}
/**
* Disables onChange event
*/
public disable(): void {
this.disabled = true;
}
/**
* Call onChange event passed to Editor.js configuration
*
* @param event - some of our custom change events
*/
public onChange(event: CustomEvent): void {
if (this.disabled || !_.isFunction(this.config.onChange)) {
return;
}
this.config.onChange(this.Editor.API.methods, event);
}
}