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", "name": "codex.editor",
"version": "2.7.31", "version": "2.7.32",
"description": "CodeX Editor. Native JS, based on API and Open Source", "description": "CodeX Editor. Native JS, based on API and Open Source",
"main": "dist/codex-editor.js", "main": "dist/codex-editor.js",
"types": "./types/index.d.ts", "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 * Interfaces used for development
*/ */
export { export {
Tool, BaseTool,
ToolConstructable, BaseToolConstructable,
InlineTool, InlineTool,
InlineToolConstructable, InlineToolConstructable,
BlockToolConstructable, BlockToolConstructable,
BlockTool, BlockTool,
BlockToolData, BlockToolData,
Tool,
ToolConstructable,
ToolboxConfig, ToolboxConfig,
ToolSettings, ToolSettings,
ToolConfig, ToolConfig,

View file

@ -1,6 +1,6 @@
import {PasteConfig, SanitizerConfig} from '../configs'; import {PasteConfig, SanitizerConfig} from '../configs';
import {BlockToolData} from './block-tool-data'; import {BlockToolData} from './block-tool-data';
import {Tool, ToolConstructable} from './tool'; import {BaseTool, BaseToolConstructable} from './tool';
import {ToolConfig} from './tool-config'; import {ToolConfig} from './tool-config';
import {API} from '../index'; import {API} from '../index';
import {PasteEvent} from './paste-events'; import {PasteEvent} from './paste-events';
@ -8,18 +8,12 @@ import {PasteEvent} from './paste-events';
* Describe Block Tool object * Describe Block Tool object
* @see {@link docs/tools.md} * @see {@link docs/tools.md}
*/ */
export interface BlockTool extends Tool { export interface BlockTool extends BaseTool {
/** /**
* Sanitizer rules description * Sanitizer rules description
*/ */
sanitize?: SanitizerConfig; sanitize?: SanitizerConfig;
/**
* Return Tool's main block-wrapper
* @return {HTMLElement}
*/
render(): HTMLElement;
/** /**
* Process Tool's element in DOM and return raw data * Process Tool's element in DOM and return raw data
* @param {HTMLElement} block - element created by {@link BlockTool#render} function * @param {HTMLElement} block - element created by {@link BlockTool#render} function
@ -47,10 +41,14 @@ export interface BlockTool extends Tool {
*/ */
merge?(blockData: BlockToolData): void; 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 * 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';
export * from './block-tool-data'; export * from './block-tool-data';
export * from './inline-tool'; export * from './inline-tool';
@ -5,3 +9,6 @@ export * from './tool';
export * from './tool-config'; export * from './tool-config';
export * from './tool-settings'; export * from './tool-settings';
export * from './paste-events'; 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 * Base structure for the Inline Toolbar Tool
*/ */
export interface InlineTool extends Tool { export interface InlineTool extends BaseTool {
/**
* Shortcut for Tool
* @type {string}
*/
shortcut?: string; shortcut?: string;
/** /**
@ -30,4 +34,4 @@ export interface InlineTool extends Tool {
clear?(): void; clear?(): void;
} }
export interface InlineToolConstructable extends ToolConstructable {} export interface InlineToolConstructable extends BaseToolConstructable {}

View file

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