Pass configuration to inline tools (#660)

This commit is contained in:
George Berezhnoy 2019-03-27 15:46:42 +03:00 committed by GitHub
parent 42714fe2f5
commit dd42adbb39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 43 deletions

8
dist/editor.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,9 @@
# Changelog
### 2.12.2
- New *Inline Tools* — pass tool settings from configuration to Tool constructor
### 2.12.1
- `Fix` — Fix processing `color-mod` function in styles

View file

@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.12.1",
"version": "2.12.2",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",

View file

@ -17,34 +17,6 @@ import {InlineTool, InlineToolConstructable, ToolConstructable, ToolSettings} fr
*/
export default class InlineToolbar extends Module {
/**
* Returns internal inline tools
* Includes Bold, Italic, Link
*/
private get internalTools(): { [name: string]: InlineTool } {
return {
bold: this.Editor.Tools.constructInline(BoldInlineTool),
italic: this.Editor.Tools.constructInline(ItalicInlineTool),
link: this.Editor.Tools.constructInline(LinkInlineTool),
};
}
/**
* Get external tools
* Tools that has isInline is true
*/
private get externalTools(): { [name: string]: InlineTool } {
const result = {};
for (const tool in this.Editor.Tools.inline) {
if (this.Editor.Tools.inline.hasOwnProperty(tool)) {
result[tool] = this.Editor.Tools.constructInline(this.Editor.Tools.inline[tool]);
}
}
return result;
}
/**
* CSS styles
*/
@ -450,7 +422,9 @@ export default class InlineToolbar extends Module {
for (const tool in this.Editor.Tools.inline) {
if (this.Editor.Tools.inline.hasOwnProperty(tool)) {
result[tool] = this.Editor.Tools.constructInline(this.Editor.Tools.inline[tool]);
const toolSettings = this.Editor.Tools.getToolSettings(tool);
result[tool] = this.Editor.Tools.constructInline(this.Editor.Tools.inline[tool], toolSettings);
}
}

View file

@ -1,7 +1,14 @@
import Paragraph from '../tools/paragraph/dist/bundle';
import Module from '../__module';
import _ from '../utils';
import {BlockToolConstructable, ToolConfig, ToolConstructable, ToolSettings} from '../../../types';
import {
BlockToolConstructable,
InlineTool,
InlineToolConstructable, Tool,
ToolConfig,
ToolConstructable,
ToolSettings,
} from '../../../types';
import BoldInlineTool from '../inline-tools/inline-tool-bold';
import ItalicInlineTool from '../inline-tools/inline-tool-italic';
import LinkInlineTool from '../inline-tools/inline-tool-link';
@ -313,17 +320,19 @@ export default class Tools extends Module {
* Return Inline Tool's instance
*
* @param {InlineTool} tool
* @param {ToolSettings} toolSettings
* @return {InlineTool} instance
*/
public constructInline(tool) {
public constructInline(tool: InlineToolConstructable, toolSettings: ToolSettings = {} as ToolSettings): InlineTool {
/**
* @type {{api: API}}
*/
const constructorOptions = {
api: this.Editor.API.methods,
config: toolSettings[this.apiSettings.CONFIG] || {},
};
return new tool(constructorOptions);
return new tool(constructorOptions) as InlineTool;
}
/**
@ -411,14 +420,14 @@ export default class Tools extends Module {
*/
get internalTools() {
return {
bold: BoldInlineTool,
italic: ItalicInlineTool,
link: LinkInlineTool,
bold: {class: BoldInlineTool},
italic: {class: ItalicInlineTool},
link: {class: LinkInlineTool},
paragraph: {
class: Paragraph,
inlineToolbar: true,
},
stub: Stub,
stub: {class: Stub},
};
}
}

View file

@ -1,4 +1,4 @@
import {API} from '../index';
import {API, ToolSettings} from '../index';
import {ToolConfig} from './tool-config';
import {SanitizerConfig} from '../configs';
@ -29,7 +29,7 @@ export interface BaseToolConstructable {
/**
* Describe constructor parameters
*/
new (config: {api: API}): BaseTool;
new (config: {api: API, config?: ToolSettings}): BaseTool;
/**
* Tool`s prepare method. Can be async