BlockAPI
BlockAPI provides methods and properties to work with Block instance. You can access BlockAPI object inside Tool or using `getBlockByIndex` method.
class MyTool {
constructor({ block }) {
this.block = block;
}
getBlockHolder() {
return this.block.holder;
}
}
...
const editor = new EditorJS();
const block = editor.getBlockByIndex(0);
const holder = block.holder;
name: string
|
Tool's name |
config: ToolConfig
|
Tool's config passed on Editor's initialisation |
holder: HTMLElement
|
Block's content holder HTMLDivElement |
isEmpty: boolean
|
Indicates if Block's content is empty |
selected: boolean
|
Indicates if Block is selected |
stretched: boolean
|
Indicates if Block is stretched |
stretched(isStretched: boolean)
|
Changes Block stretched state |
call(methodName: string, param?: object): void
|
Method to call Tool's instance methods (eg. save , validate , render , etc.)
|
save(): Promise<void|SavedData>
|
Returns Promise which resolves to saved Block data with meta |
validate(data: BlockToolData): Promise<boolean>
|
Calls Tool's validate method and returns Promise which resolves to boolean value. Equivalent to call('validate', data)
|
dispatchChange()
|
Allows to say Editor that Block has been changed. Used to manually trigger the Editor's onChange callback.
|
Allows to say Editor that Block was changed. Used to manually trigger the Editor's 'onChange' callback
Can be useful for Block changes invisible to the Editor's core.
class MyBlockTool {
constructor({ data, block }){
this.data
this.blockAPI = block
}
changeSomeDataProperty() {
this.data['some-property'] = 'some-value'
// Tell Editor to know that block was changed
this.blockAPI.dispatchChange()
}
}