MCPcopy Index your code
hub / github.com/codex-team/editor.js / BlocksAPI

Class BlocksAPI

src/components/modules/api/blocks.ts:14–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 * provides with methods working with Block
13 */
14export default class BlocksAPI extends Module {
15 /**
16 * Available methods
17 *
18 * @returns {Blocks}
19 */
20 public get methods(): Blocks {
21 return {
22 clear: (): Promise<void> => this.clear(),
23 render: (data: OutputData): Promise<void> => this.render(data),
24 renderFromHTML: (data: string): Promise<void> => this.renderFromHTML(data),
25 delete: (index?: number): void => this.delete(index),
26 swap: (fromIndex: number, toIndex: number): void => this.swap(fromIndex, toIndex),
27 move: (toIndex: number, fromIndex?: number): void => this.move(toIndex, fromIndex),
28 getBlockByIndex: (index: number): BlockAPIInterface | undefined => this.getBlockByIndex(index),
29 getById: (id: string): BlockAPIInterface | null => this.getById(id),
30 getCurrentBlockIndex: (): number => this.getCurrentBlockIndex(),
31 getBlockIndex: (id: string): number => this.getBlockIndex(id),
32 getBlocksCount: (): number => this.getBlocksCount(),
33 getBlockByElement: (element: HTMLElement) => this.getBlockByElement(element),
34 stretchBlock: (index: number, status = true): void => this.stretchBlock(index, status),
35 insertNewBlock: (): void => this.insertNewBlock(),
36 insert: this.insert,
37 insertMany: this.insertMany,
38 update: this.update,
39 composeBlockData: this.composeBlockData,
40 convert: this.convert,
41 };
42 }
43
44 /**
45 * Returns Blocks count
46 *
47 * @returns {number}
48 */
49 public getBlocksCount(): number {
50 return this.Editor.BlockManager.blocks.length;
51 }
52
53 /**
54 * Returns current block index
55 *
56 * @returns {number}
57 */
58 public getCurrentBlockIndex(): number {
59 return this.Editor.BlockManager.currentBlockIndex;
60 }
61
62 /**
63 * Returns the index of Block by id;
64 *
65 * @param id - block id
66 */
67 public getBlockIndex(id: string): number | undefined {
68 const block = this.Editor.BlockManager.getBlockById(id);
69
70 if (!block) {
71 _.logLabeled('There is no block with id `' + id + '`', 'warn');

Callers

nothing calls this directly

Calls 9

validateIndexMethod · 0.95
capitalizeFunction · 0.90
getBlockByIdMethod · 0.80
composeBlockMethod · 0.80
insertMethod · 0.65
getMethod · 0.65
updateMethod · 0.65
convertMethod · 0.65
insertManyMethod · 0.65

Tested by

no test coverage detected