mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
cd29c52e51
* slash to open toolbox, tab for navigation * tab, focus improvements - remove "focused" block state - tab navigation respects inputs - allow to focus contentless blocks * fix tests * tests for Slash * tab tests * test for tabbing out of editor * tests fixed * review fixes
137 lines
2.8 KiB
TypeScript
137 lines
2.8 KiB
TypeScript
import Block from './index';
|
|
import { BlockToolData, ToolConfig } from '../../../types/tools';
|
|
import { SavedData } from '../../../types/data-formats';
|
|
import { BlockAPI as BlockAPIInterface } from '../../../types/api';
|
|
|
|
/**
|
|
* Constructs new BlockAPI object
|
|
*
|
|
* @class
|
|
* @param {Block} block - Block to expose
|
|
*/
|
|
function BlockAPI(
|
|
block: Block
|
|
): void {
|
|
const blockAPI: BlockAPIInterface = {
|
|
/**
|
|
* Block id
|
|
*
|
|
* @returns {string}
|
|
*/
|
|
get id(): string {
|
|
return block.id;
|
|
},
|
|
/**
|
|
* Tool name
|
|
*
|
|
* @returns {string}
|
|
*/
|
|
get name(): string {
|
|
return block.name;
|
|
},
|
|
|
|
/**
|
|
* Tool config passed on Editor's initialization
|
|
*
|
|
* @returns {ToolConfig}
|
|
*/
|
|
get config(): ToolConfig {
|
|
return block.config;
|
|
},
|
|
|
|
/**
|
|
* .ce-block element, that wraps plugin contents
|
|
*
|
|
* @returns {HTMLElement}
|
|
*/
|
|
get holder(): HTMLElement {
|
|
return block.holder;
|
|
},
|
|
|
|
/**
|
|
* True if Block content is empty
|
|
*
|
|
* @returns {boolean}
|
|
*/
|
|
get isEmpty(): boolean {
|
|
return block.isEmpty;
|
|
},
|
|
|
|
/**
|
|
* True if Block is selected with Cross-Block selection
|
|
*
|
|
* @returns {boolean}
|
|
*/
|
|
get selected(): boolean {
|
|
return block.selected;
|
|
},
|
|
|
|
/**
|
|
* Set Block's stretch state
|
|
*
|
|
* @param {boolean} state — state to set
|
|
*/
|
|
set stretched(state: boolean) {
|
|
block.stretched = state;
|
|
},
|
|
|
|
/**
|
|
* True if Block is stretched
|
|
*
|
|
* @returns {boolean}
|
|
*/
|
|
get stretched(): boolean {
|
|
return block.stretched;
|
|
},
|
|
|
|
/**
|
|
* True if Block has inputs to be focused
|
|
*/
|
|
get focusable(): boolean {
|
|
return block.focusable;
|
|
},
|
|
|
|
/**
|
|
* Call Tool method with errors handler under-the-hood
|
|
*
|
|
* @param {string} methodName - method to call
|
|
* @param {object} param - object with parameters
|
|
* @returns {unknown}
|
|
*/
|
|
call(methodName: string, param?: object): unknown {
|
|
return block.call(methodName, param);
|
|
},
|
|
|
|
/**
|
|
* Save Block content
|
|
*
|
|
* @returns {Promise<void|SavedData>}
|
|
*/
|
|
save(): Promise<void|SavedData> {
|
|
return block.save();
|
|
},
|
|
|
|
/**
|
|
* Validate Block data
|
|
*
|
|
* @param {BlockToolData} data - data to validate
|
|
* @returns {Promise<boolean>}
|
|
*/
|
|
validate(data: BlockToolData): Promise<boolean> {
|
|
return block.validate(data);
|
|
},
|
|
|
|
/**
|
|
* Allows to say Editor that Block was changed. Used to manually trigger Editor's 'onChange' callback
|
|
* Can be useful for block changes invisible for editor core.
|
|
*/
|
|
dispatchChange(): void {
|
|
block.dispatchChange();
|
|
},
|
|
};
|
|
|
|
Object.setPrototypeOf(this, blockAPI);
|
|
}
|
|
|
|
export default BlockAPI;
|