Returns instance of selected block.
let instance = this.app.block.get();
See more about Block.Instance API.
element | Node , Element , Dom | Element of the block |
caret (optional) | String | Place the caret at the beginning or end of the editable block |
Sets the selected block.
this.app.block.set(element);
this.app.block.set(element, 'start');
this.app.block.set(element, 'end');
Unsets the selected block.
this.app.block.unset();
Object
Removes the selected block.
this.app.block.remove();
Turn off the selection of the next/previous element of the removed block.
this.app.block.remove({ traverse: false });
Duplicates the selected block.
this.app.block.duplicate();
Creates an empty paragraph block.
let instance = this.app.block.create();
Alternative, create a block by the type with app.create
, for example:
let type = 'text';
let instance = this.app.create('block.' + type);
instance | Object | Instance of the block. |
Removes the selected block and adds a new one to its place.
let type = 'heading';
let instance = this.app.create('block.' + type);
this.app.block.change(instance);
params | Object |
This method adds a block depending on the caret or the specified position.
// create block
let instance = this.app.create('block.text');
// add
this.app.block.insert({ instance: instance });
By default, the caret will be placed at the end of the added block. To set the caret to the beginning, you can pass the parameter caret
with the value start
.
// create block
let $source = this.dom('<p>').html('Hello world!');
let instance = this.app.create('block.text', $source);
// add and set caret at start
this.app.block.insert({ instance: instance, caret: 'start' });
The method automatically detects the position of the block to be added, depending on what is currently selected in the content. You can manually specify a position, for example to add a new block before the current one.
// create block
let instance = this.app.create('block.text');
// add before selected block
this.app.block.insert({ instance: instance, position: 'before' });
These options are available for specifying the position:
Moves the selected block up.
this.app.block.moveUp();
Moves the selected block down.
this.app.block.moveDown();
Returns properties of the selected block.
let data = this.app.block.getData();
Sets the properties in the selected block.
this.app.block.setData({
id: 'myid'
});