Skip to content

Commit

Permalink
Improve typings (codex-team#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
gohabereg authored Jan 25, 2019
1 parent 8ca49fa commit b89f756
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 27 deletions.
6 changes: 3 additions & 3 deletions dist/codex-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 8 additions & 10 deletions types/tools/block-tool.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
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';
/**
* 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
Expand Down Expand Up @@ -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
*/
Expand Down
7 changes: 7 additions & 0 deletions types/tools/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
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';
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;
10 changes: 7 additions & 3 deletions types/tools/inline-tool.d.ts
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -30,4 +34,4 @@ export interface InlineTool extends Tool {
clear?(): void;
}

export interface InlineToolConstructable extends ToolConstructable {}
export interface InlineToolConstructable extends BaseToolConstructable {}
2 changes: 1 addition & 1 deletion types/tools/tool-settings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ToolConfig} from './tool-config';
import {ToolConstructable} from './tool';
import {ToolConstructable} from './index';

/**
* Tool's Toolbox settings
Expand Down
10 changes: 3 additions & 7 deletions types/tools/tool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,11 +14,7 @@ export interface Tool {
render(): HTMLElement;
}

export interface ToolConstructable {
/**
* Tool name
*/
name: string;
export interface BaseToolConstructable {

/**
* Define Tool type as Inline
Expand All @@ -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
Expand Down

0 comments on commit b89f756

Please sign in to comment.