mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 15:45:47 +01:00
* fix types export * lint * changelog * tests fixed * fix tests imports * lint tests * upd submodule * Update yarn.lock * rename wrapper to factory * Update package.json * rename to adapters * Update tools.d.ts * BlockTool -> BlockToolAdapter etc * Update nested-list * Update collection.ts
21 lines
721 B
TypeScript
21 lines
721 B
TypeScript
import type { BlockAPI } from '../../../types/api/block';
|
|
import type { EditorModules } from '../../types-internal/editor-modules';
|
|
import type 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);
|
|
}
|