11import { BlockAPI as BlockAPIInterface , Blocks } from '../../../../types/api' ;
2- import { InsertedBlock } from '../../../../types/api' ;
32import { BlockToolData , OutputData , ToolConfig } from '../../../../types' ;
43import * as _ from './../../utils' ;
54import BlockAPI from '../../block/api' ;
@@ -31,7 +30,7 @@ export default class BlocksAPI extends Module {
3130 getBlocksCount : ( ) : number => this . getBlocksCount ( ) ,
3231 stretchBlock : ( index : number , status = true ) : void => this . stretchBlock ( index , status ) ,
3332 insertNewBlock : ( ) : void => this . insertNewBlock ( ) ,
34- insert :( ) : BlockAPIInterface => this . insert ( { } ) ,
33+ insert : this . insert ,
3534 update : this . update ,
3635 composeBlockData : this . composeBlockData ,
3736 } ;
@@ -223,10 +222,30 @@ export default class BlocksAPI extends Module {
223222
224223 /**
225224 * Insert new Block and returns it's API
226- * @param {InsertedBlock } block - The block being inserted
225+ *
226+ * @param {string } type — Tool name
227+ * @param {BlockToolData } data — Tool data to insert
228+ * @param {ToolConfig } config — Tool config
229+ * @param {number? } index — index where to insert new Block
230+ * @param {boolean? } needToFocus - flag to focus inserted Block
231+ * @param replace - pass true to replace the Block existed under passed index
227232 */
228- public insert ( block : InsertedBlock ) : BlockAPIInterface {
229- const insertedBlock = this . Editor . BlockManager . insert ( block ) ;
233+ public insert = (
234+ type : string = this . config . defaultBlock ,
235+ data : BlockToolData = { } ,
236+ config : ToolConfig = { } ,
237+ index ?: number ,
238+ needToFocus ?: boolean ,
239+ replace ?: boolean
240+ ) : BlockAPIInterface => {
241+ const insertedBlock = this . Editor . BlockManager . insert ( {
242+ tool : type ,
243+ data,
244+ index,
245+ needToFocus,
246+ replace,
247+ } ) ;
248+
230249 return new BlockAPI ( insertedBlock ) ;
231250 }
232251
@@ -244,6 +263,7 @@ export default class BlocksAPI extends Module {
244263 data : { } ,
245264 tunesData : { } ,
246265 } ) ;
266+
247267 return block . data ;
248268 }
249269
@@ -258,7 +278,7 @@ export default class BlocksAPI extends Module {
258278 public insertNewBlock ( ) : void {
259279 _ . log ( 'Method blocks.insertNewBlock() is deprecated and it will be removed in the next major release. ' +
260280 'Use blocks.insert() instead.' , 'warn' ) ;
261- this . insert ( { } ) ;
281+ this . insert ( ) ;
262282 }
263283
264284 /**
0 commit comments