Improve typings (#602)

This commit is contained in:
George Berezhnoy 2019-01-25 06:21:34 +03:00 committed by GitHub
parent 8ca49fa6f5
commit b89f756a03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 27 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "2.7.31",
"version": "2.7.32",
"description": "CodeX Editor. Native JS, based on API and Open Source",
"main": "dist/codex-editor.js",
"types": "./types/index.d.ts",

6
types/index.d.ts vendored
View file

@ -11,13 +11,15 @@ import {Blocks, Caret, Events, Listeners, Notifier, Sanitizer, Saver, Selection,
* Interfaces used for development
*/
export {
Tool,
ToolConstructable,
BaseTool,
BaseToolConstructable,
InlineTool,
InlineToolConstructable,
BlockToolConstructable,
BlockTool,
BlockToolData,
Tool,
ToolConstructable,
ToolboxConfig,
ToolSettings,
ToolConfig,

View file

@ -1,6 +1,6 @@
import {PasteConfig, SanitizerConfig} from '../configs';
import {BlockToolData} from './block-tool-data';
import {Tool, ToolConstructable} from './tool';
import {BaseTool, BaseToolConstructable} from './tool';
import {ToolConfig} from './tool-config';
import {API} from '../index';
import {PasteEvent} from './paste-events';
@ -8,18 +8,12 @@ import {PasteEvent} from './paste-events';
* Describe Block Tool object
* @see {@link docs/tools.md}
*/
export interface BlockTool extends Tool {
export interface BlockTool extends BaseTool {
/**
* Sanitizer rules description
*/
sanitize?: SanitizerConfig;
/**
* Return Tool's main block-wrapper
* @return {HTMLElement}
*/
render(): HTMLElement;
/**
* Process Tool's element in DOM and return raw data
* @param {HTMLElement} block - element created by {@link BlockTool#render} function
@ -47,10 +41,14 @@ export interface BlockTool extends Tool {
*/
merge?(blockData: BlockToolData): void;
onPaste?(event: PasteEvent);
/**
* On paste callback. Fired when pasted content can be substituted by a Tool
* @param {PasteEvent} event
*/
onPaste?(event: PasteEvent): void;
}
export interface BlockToolConstructable extends ToolConstructable {
export interface BlockToolConstructable extends BaseToolConstructable {
/**
* Tool's Toolbox settings
*/

View file

@ -1,3 +1,7 @@
import {BlockTool, BlockToolConstructable} from './block-tool';
import {InlineTool, InlineToolConstructable} from './inline-tool';
import {BaseTool, BaseToolConstructable} from './tool';
export * from './block-tool';
export * from './block-tool-data';
export * from './inline-tool';
@ -5,3 +9,6 @@ export * from './tool';
export * from './tool-config';
export * from './tool-settings';
export * from './paste-events';
export type Tool = BaseTool | BlockTool | InlineTool;
export type ToolConstructable = BaseToolConstructable | BlockToolConstructable | InlineToolConstructable;

View file

@ -1,8 +1,12 @@
import {Tool, ToolConstructable} from './tool';
import {BaseTool, BaseToolConstructable} from './tool';
/**
* Base structure for the Inline Toolbar Tool
*/
export interface InlineTool extends Tool {
export interface InlineTool extends BaseTool {
/**
* Shortcut for Tool
* @type {string}
*/
shortcut?: string;
/**
@ -30,4 +34,4 @@ export interface InlineTool extends Tool {
clear?(): void;
}
export interface InlineToolConstructable extends ToolConstructable {}
export interface InlineToolConstructable extends BaseToolConstructable {}

View file

@ -1,5 +1,5 @@
import {ToolConfig} from './tool-config';
import {ToolConstructable} from './tool';
import {ToolConstructable} from './index';
/**
* Tool's Toolbox settings

10
types/tools/tool.d.ts vendored
View file

@ -5,7 +5,7 @@ import {SanitizerConfig} from '../configs';
/**
* Abstract interface of all Tools
*/
export interface Tool {
export interface BaseTool {
/**
* Tool`s render method
* For inline Tools returns inline toolbar button
@ -14,11 +14,7 @@ export interface Tool {
render(): HTMLElement;
}
export interface ToolConstructable {
/**
* Tool name
*/
name: string;
export interface BaseToolConstructable {
/**
* Define Tool type as Inline
@ -33,7 +29,7 @@ export interface ToolConstructable {
/**
* Describe constructor parameters
*/
new (config: {api: API}): Tool;
new (config: {api: API}): BaseTool;
/**
* Tool`s prepare method. Can be async