mirror of
https://github.com/codex-team/editor.js
synced 2024-06-09 01:12:28 +02:00
6cd6bd5de3
* Fix readOnly.isEnabled getter * Add tests * Update CHANGELOG.md Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
42 lines
942 B
TypeScript
42 lines
942 B
TypeScript
import { ReadOnly } from '../../../../types/api';
|
|
import Module from '../../__module';
|
|
|
|
/**
|
|
* @class ReadOnlyAPI
|
|
* @classdesc ReadOnly API
|
|
*/
|
|
export default class ReadOnlyAPI extends Module {
|
|
/**
|
|
* Available methods
|
|
*/
|
|
public get methods(): ReadOnly {
|
|
const getIsEnabled = (): boolean => this.isEnabled;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
return {
|
|
toggle: (state): Promise<boolean> => this.toggle(state),
|
|
get isEnabled(): boolean {
|
|
return getIsEnabled();
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Set or toggle read-only state
|
|
*
|
|
* @param {boolean|undefined} state - set or toggle state
|
|
*
|
|
* @returns {boolean} current value
|
|
*/
|
|
public toggle(state?: boolean): Promise<boolean> {
|
|
return this.Editor.ReadOnly.toggle(state);
|
|
}
|
|
|
|
/**
|
|
* Returns current read-only state
|
|
*/
|
|
public get isEnabled(): boolean {
|
|
return this.Editor.ReadOnly.isEnabled;
|
|
}
|
|
}
|