mirror of
https://github.com/codex-team/editor.js
synced 2024-05-15 21:06:52 +02:00
4f15bbc0cb
* 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
40 lines
787 B
TypeScript
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);
|
|
}
|
|
}
|