get #

Returns instance of selected block.

var instance = this.app.block.get();

See more about Block.Instance API.

set #

Arguments
element Node, Element, DomElement of the block
caret (optional)StringPlace 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');

unset #

Unsets the selected block.

this.app.block.unset();

remove #

  • params Object

Removes the selected block.

this.app.block.remove();

Turn off the selection of the parent or next/prev element of the removed block.

this.app.block.remove({ traverse: false });

duplicate #

Duplicates the selected block.

this.app.block.duplicate();

create #

Creates a block instance depend on the editor.markup setting. By default, creates an empty paragraph block.

var instance = this.app.block.create();

Alternative, create a block by type with app.create, for example:

var type = 'layer';
var instance = this.app.create('block.' + type);

change #

Arguments
instance ObjectInstance of the block.

Removes the selected block and adds a new one to its place.

var type = 'layer';
var instance = this.app.create('block.' + type);

this.app.block.change(instance);

add #

Arguments
params Object

This method adds a block depending on the caret or the specified position.

// create block
var instance = this.app.create('block.paragraph');

// add
this.app.block.add({ 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
var $source = this.dom('<p>').html('Hello world!');
var instance = this.app.create('block.paragraph', $source);

// add and set caret at start
this.app.block.add({ 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
var instance = this.app.create('block.paragraph');

// add before selected block
this.app.block.add({ instance: instance, position: 'before' });

Three options are available for specifying the position:

  • before — before the current block
  • after — after the current block
  • append — append to the current block

format #

Formats the selected block to a specific tag.

this.app.block.format({ tag: 'h2' });

moveUp #

Moves the selected block up.

this.app.block.moveUp();

moveDown #

Moves the selected block down.

this.app.block.moveDown();

getData #

Returns properties of the selected block.

var data = this.app.block.getData();

setData #

Sets the properties in the selected block.

this.app.block.setData({
    id: 'myid'
});