mirror of
https://github.com/codex-team/editor.js
synced 2024-06-09 01:12:28 +02:00
23858e0025
* fix caret loosing after caret * Refactor convert method to return Promise in Blocks API * changelog upd * Fix missing semicolon in blocks.cy.ts and BlockTunes.cy.ts * add test for inline toolbar conversion * Fix missing semicolon in InlineToolbar.cy.ts * add test for toolbox shortcut * api caret.setToBlock now can accept block api or index or id * eslint fix * Refactor test descriptions in caret.cy.ts * rm tsconfig change * lint * lint * Update CHANGELOG.md
22 lines
711 B
TypeScript
22 lines
711 B
TypeScript
import type { BlockAPI } from '../../../types/api/block';
|
|
import { EditorModules } from '../../types-internal/editor-modules';
|
|
import Block from '../block';
|
|
|
|
/**
|
|
* Returns Block instance by passed Block index or Block id
|
|
*
|
|
* @param attribute - either BlockAPI or Block id or Block index
|
|
* @param editor - Editor instance
|
|
*/
|
|
export function resolveBlock(attribute: BlockAPI | BlockAPI['id'] | number, editor: EditorModules): Block | undefined {
|
|
if (typeof attribute === 'number') {
|
|
return editor.BlockManager.getBlockByIndex(attribute);
|
|
}
|
|
|
|
if (typeof attribute === 'string') {
|
|
return editor.BlockManager.getBlockById(attribute);
|
|
}
|
|
|
|
return editor.BlockManager.getBlockById(attribute.id);
|
|
}
|