mirror of
https://github.com/codex-team/editor.js
synced 2024-05-06 08:33:20 +02:00
63eeec0f3b
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com> Co-authored-by: tasuku-s <tasuku@freemind.co.jp> Co-authored-by: Athul Anil Kumar <athul7744@outlook.com> Co-authored-by: Taly <vitalik7tv@yandex.ru> Co-authored-by: flaming-cl <51183663+flaming-cl@users.noreply.github.com> Co-authored-by: Nguyen Ngoc Son <sonnn.se@gmail.com> Co-authored-by: Sisir Das K <37764463+sis-dk@users.noreply.github.com> Co-authored-by: Sisir <sisir@hellosivi.com>
122 lines
2.7 KiB
TypeScript
122 lines
2.7 KiB
TypeScript
import { ConversionConfig, PasteConfig, SanitizerConfig } from '../configs';
|
|
import { BlockToolData } from './block-tool-data';
|
|
import {BaseTool, BaseToolConstructable} from './tool';
|
|
import { ToolConfig } from './tool-config';
|
|
import {API, BlockAPI} from '../index';
|
|
import { PasteEvent } from './paste-events';
|
|
import { MoveEvent } from './hook-events';
|
|
|
|
/**
|
|
* Describe Block Tool object
|
|
* @see {@link docs/tools.md}
|
|
*/
|
|
export interface BlockTool extends BaseTool {
|
|
/**
|
|
* Sanitizer rules description
|
|
*/
|
|
sanitize?: SanitizerConfig;
|
|
|
|
/**
|
|
* Process Tool's element in DOM and return raw data
|
|
* @param {HTMLElement} block - element created by {@link BlockTool#render} function
|
|
* @return {BlockToolData}
|
|
*/
|
|
save(block: HTMLElement): BlockToolData;
|
|
|
|
/**
|
|
* Create Block's settings block
|
|
* @return {HTMLElement}
|
|
*/
|
|
renderSettings?(): HTMLElement;
|
|
|
|
/**
|
|
* Validate Block's data
|
|
* @param {BlockToolData} blockData
|
|
* @return {boolean}
|
|
*/
|
|
validate?(blockData: BlockToolData): boolean;
|
|
|
|
/**
|
|
* Method that specified how to merge two Blocks with same type.
|
|
* Called by backspace at the beginning of the Block
|
|
* @param {BlockToolData} blockData
|
|
*/
|
|
merge?(blockData: BlockToolData): void;
|
|
|
|
/**
|
|
* On paste callback. Fired when pasted content can be substituted by a Tool
|
|
* @param {PasteEvent} event
|
|
*/
|
|
onPaste?(event: PasteEvent): void;
|
|
|
|
/**
|
|
* Lifecycle hooks
|
|
*/
|
|
|
|
/**
|
|
* Called after block content added to the page
|
|
*/
|
|
rendered?(): void;
|
|
|
|
/**
|
|
* Called each time block content is updated
|
|
*/
|
|
updated?(): void;
|
|
|
|
/**
|
|
* Called after block removed from the page but before instance is deleted
|
|
*/
|
|
removed?(): void;
|
|
|
|
/**
|
|
* Called after block was moved
|
|
*/
|
|
moved?(event: MoveEvent): void;
|
|
}
|
|
|
|
/**
|
|
* Describe constructor parameters
|
|
*/
|
|
export interface BlockToolConstructorOptions<D extends object = any, C extends object = any> {
|
|
api: API;
|
|
data: BlockToolData<D>;
|
|
config?: ToolConfig<C>;
|
|
block?: BlockAPI;
|
|
}
|
|
|
|
export interface BlockToolConstructable extends BaseToolConstructable {
|
|
/**
|
|
* Tool's Toolbox settings
|
|
*/
|
|
toolbox?: {
|
|
/**
|
|
* HTML string with an icon for Toolbox
|
|
*/
|
|
icon: string;
|
|
|
|
/**
|
|
* Tool title for Toolbox
|
|
*/
|
|
title?: string;
|
|
};
|
|
|
|
/**
|
|
* Paste substitutions configuration
|
|
*/
|
|
pasteConfig?: PasteConfig | false;
|
|
|
|
/**
|
|
* Rules that specified how this Tool can be converted into/from another Tool
|
|
*/
|
|
conversionConfig?: ConversionConfig;
|
|
|
|
/**
|
|
* @constructor
|
|
*
|
|
* @param {BlockToolConstructorOptions} config - constructor parameters
|
|
*
|
|
* @return {BlockTool}
|
|
*/
|
|
new(config: BlockToolConstructorOptions): BlockTool;
|
|
}
|