mirror of
https://github.com/codex-team/editor.js
synced 2024-06-28 10:20:29 +02:00
4e7b33c2b8
* onChange improvements * Return modifications observer module * Fix lint * Fix tests
41 lines
808 B
TypeScript
41 lines
808 B
TypeScript
import Module from '../__module';
|
|
import { BlockAPI } from '../../../types';
|
|
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 block - changed Block
|
|
*/
|
|
public onChange(block: BlockAPI): void {
|
|
if (this.disabled || !_.isFunction(this.config.onChange)) {
|
|
return;
|
|
}
|
|
|
|
this.config.onChange(this.Editor.API.methods, block);
|
|
}
|
|
}
|