mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
022320940e
* feat(conversion): allow to convert block using shortcut * display shortcuts in conversion toolbar * tests for the blocks.convert * tests for the toolbox shortcuts * Update CHANGELOG.md * Update toolbox.cy.ts * rm unused imports * firefox test fixed * test errors via to.throw
55 lines
1.1 KiB
TypeScript
55 lines
1.1 KiB
TypeScript
import { BlockTool, BlockToolConstructorOptions } from '../../../../types';
|
|
|
|
/**
|
|
* Simple structure for Tool data
|
|
*/
|
|
interface MockToolData {
|
|
text: string;
|
|
}
|
|
|
|
/**
|
|
* Common class for Tool mocking.
|
|
* Extend this class to create a mock for your Tool with specific properties.
|
|
*/
|
|
export default class ToolMock implements BlockTool {
|
|
/**
|
|
* Tool data
|
|
*/
|
|
private data: MockToolData;
|
|
|
|
/**
|
|
* Creates new Tool instance
|
|
*
|
|
* @param options - tool constructor options
|
|
*/
|
|
constructor(options: BlockToolConstructorOptions<MockToolData>) {
|
|
this.data = options.data;
|
|
}
|
|
|
|
/**
|
|
* Renders a single content editable element as tools element
|
|
*/
|
|
public render(): HTMLElement {
|
|
const contenteditable = document.createElement('div');
|
|
|
|
if (this.data && this.data.text) {
|
|
contenteditable.innerHTML = this.data.text;
|
|
}
|
|
|
|
contenteditable.contentEditable = 'true';
|
|
|
|
return contenteditable;
|
|
}
|
|
|
|
/**
|
|
* Save method mock, returns block innerHTML
|
|
*
|
|
* @param block - element rendered by the render method
|
|
*/
|
|
public save(block: HTMLElement): MockToolData {
|
|
return {
|
|
text: block.innerHTML,
|
|
};
|
|
}
|
|
}
|