diff --git a/example/tools/embed b/example/tools/embed index 35742f01a..27e578907 160000 --- a/example/tools/embed +++ b/example/tools/embed @@ -1 +1 @@ -Subproject commit 35742f01ae5875d442b145121d3c9b71b23aea56 +Subproject commit 27e5789079577c7dcaf9de8074d0979fc2e15203 diff --git a/src/components/modules/api/blocks.ts b/src/components/modules/api/blocks.ts index 8d742c850..1d9837f73 100644 --- a/src/components/modules/api/blocks.ts +++ b/src/components/modules/api/blocks.ts @@ -1,5 +1,6 @@ import { BlockAPI as BlockAPIInterface, Blocks } from '../../../../types/api'; import { BlockToolData, OutputData, ToolConfig } from '../../../../types'; +import {InsertedBlock} from '../../../../types/api'; import * as _ from './../../utils'; import BlockAPI from '../../block/api'; import Module from '../../__module'; @@ -222,30 +223,20 @@ export default class BlocksAPI extends Module { /** * Insert new Block and returns it's API - * - * @param {string} type — Tool name - * @param {BlockToolData} data — Tool data to insert - * @param {ToolConfig} config — Tool config - * @param {number?} index — index where to insert new Block - * @param {boolean?} needToFocus - flag to focus inserted Block - * @param replace - pass true to replace the Block existed under passed index + * @param {InsertedBlock} block - The block being inserted */ - public insert = ( - type: string = this.config.defaultBlock, - data: BlockToolData = {}, - config: ToolConfig = {}, - index?: number, - needToFocus?: boolean, - replace?: boolean - ): BlockAPIInterface => { + public insert = (block: InsertedBlock = { + type : this.config.defaultBlock, + data: {}, + config: {} + }): BlockAPIInterface => { const insertedBlock = this.Editor.BlockManager.insert({ - tool: type, - data, - index, - needToFocus, - replace, + tool: block.type, + data: block.data, + index: block.index, + needToFocus: block.needToFocus, + replace: block.replace, }); - return new BlockAPI(insertedBlock); } diff --git a/src/components/ui/toolbox.ts b/src/components/ui/toolbox.ts index 7ae48c58f..991db0c6e 100644 --- a/src/components/ui/toolbox.ts +++ b/src/components/ui/toolbox.ts @@ -9,6 +9,7 @@ import Popover, { PopoverEvent, PopoverItem } from '../utils/popover'; import I18n from '../i18n'; import { I18nInternalNS } from '../i18n/namespace-internal'; + /** * @todo the first Tab on the Block — focus Plus Button, the second — focus Block Tunes Toggler, the third — focus next Block */ @@ -404,14 +405,13 @@ export default class Toolbox extends EventsDispatcher { blockData = Object.assign(defaultBlockData, blockDataOverrides); } - const newBlock = this.api.blocks.insert( - toolName, - blockData, - undefined, + const newBlock = this.api.blocks.insert({ + type: toolName, + data: blockData, + config: undefined, index, - undefined, - currentBlock.isEmpty - ); + replace: currentBlock.isEmpty, + }); /** * Apply callback before inserting html diff --git a/types/api/block.d.ts b/types/api/block.d.ts index c20e46222..3b7e00585 100644 --- a/types/api/block.d.ts +++ b/types/api/block.d.ts @@ -74,3 +74,39 @@ export interface BlockAPI { */ dispatchChange(): void; } + +/** + * @interface InsertedBLock Describes methods and properties of inserted blocks + */ + + export interface InsertedBlock{ + /** + * Tool name + */ + type: string, + + /** + * Tool data to insert + */ + data: BlockToolData, + + /** + * Tool config + */ + config: ToolConfig, + + /** + * index where to insert new block + */ + index?: number, + + /** + * flag to focus inserted block + */ + needToFocus?: boolean, + + /** + * pass true to replace the Block existed under passed index + */ + replace?: boolean +} \ No newline at end of file diff --git a/types/api/blocks.d.ts b/types/api/blocks.d.ts index 21649db8a..dd1b70513 100644 --- a/types/api/blocks.d.ts +++ b/types/api/blocks.d.ts @@ -1,3 +1,4 @@ +import {InsertedBlock} from '.'; import {OutputData} from '../data-formats/output-data'; import {BlockToolData, ToolConfig} from '../tools'; import {BlockAPI} from './block'; @@ -96,21 +97,9 @@ export interface Blocks { /** * Insert new Block and return inserted Block API * - * @param {string} type — Tool name - * @param {BlockToolData} data — Tool data to insert - * @param {ToolConfig} config — Tool config - * @param {number?} index — index where to insert new Block - * @param {boolean?} needToFocus - flag to focus inserted Block - * @param {boolean?} replace - should the existed Block on that index be replaced or not - */ - insert( - type?: string, - data?: BlockToolData, - config?: ToolConfig, - index?: number, - needToFocus?: boolean, - replace?: boolean, - ): BlockAPI; + * @param {InsertedBlock} block - new block config + */ + insert(block: InsertedBlock): BlockAPI; /**