Skip to content

Commit d82a937

Browse files
authored
Merge pull request #4 from aditink/revert-3-wanxin-issue1817
Revert "Wanxin issue1817, fixed insert method."
2 parents 10ba7e3 + 765b03f commit d82a937

3 files changed

Lines changed: 27 additions & 43 deletions

File tree

src/components/modules/api/blocks.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BlockAPI as BlockAPIInterface, Blocks } from '../../../../types/api';
2-
import {InsertedBlock} from '../../../../types/api';
32
import { BlockToolData, OutputData, ToolConfig } from '../../../../types';
43
import * as _ from './../../utils';
54
import 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
/**

types/api/block.d.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,3 @@ export interface BlockAPI {
7474
*/
7575
dispatchChange(): void;
7676
}
77-
78-
/**
79-
* @interface InsertedBLock Describes methods and properties of inserted blocks
80-
*/
81-
82-
export interface InsertedBlock{
83-
/**
84-
* Tool name
85-
*/
86-
type?: string,
87-
88-
/**
89-
* Tool data to insert
90-
*/
91-
data?: BlockToolData,
92-
93-
/**
94-
* Tool config
95-
*/
96-
config?: ToolConfig,
97-
98-
/**
99-
* index where to insert new block
100-
*/
101-
index?: number,
102-
103-
/**
104-
* falg to focus inserted block
105-
*/
106-
needToFocus?: boolean,
107-
108-
/**
109-
* pass true to replace the Block existed under passed index
110-
*/
111-
replace?: boolean
112-
}

0 commit comments

Comments
 (0)