Current block operations: focus, remove, format, type checks.
Access:
app.block
app.getModule('block')
app.invoke('block.method', …)
create#
Creates a new block instance via blockManager without inserting it.
Parameters:
- type (
string) — block or entity type name - data (
object) — payload data
Returns: Block
app.block.create('heading', { level: 2 });
get#
Returns the current block at caret or data-selected.
Returns: Block|null
app.block.get();
getEl#
Returns the DOM element of the current block.
Returns: HTMLElement|null
app.block.getEl();
getType#
Returns the type string of the current block.
Returns: string|null
app.block.getType();
getData#
Returns the data object of the current block.
Returns: object|null
app.block.getData();
setData#
Updates current block data and emits blocks:change.
Parameters:
- data (
object) — payload data
Returns: Block|null
app.block.setData({ level: 3 });
focus#
Focuses a block instance or element via blockFocus service. options also accepts a boolean (shorthand for { alwaysSelect }) or a string (shorthand for { caret }) for backward compatibility.
Parameters:
- blockOrEl (
Block | HTMLElement) — block instance or its root element - options (
object) — object with the keys below- alwaysSelect (
boolean) — force reselecting the block even when it is already focused - caret (
any) — place the caret at'start'or'end'of the block after focusing - nestedCaret (
boolean) — allow the caret to land inside nested child blocks (list/table/layout containers)
- alwaysSelect (
Returns: Block|null
app.block.focus(block, { caret: 'end' });
clearFocus#
Clears block focus state.
app.block.clearFocus();
insert#
Inserts a block or HTML relative to the current block.
Parameters:
- type (
string) — block type to insert (e.g.'text'); omit to insert rawtemplateHTML instead - ...options (
object) — insert options:where('before'/'after'/'auto', default'auto'),data(initial block data),template(raw HTML used whentypeis omitted),focus(defaulttrue),caret('start'/'end', default'start')
Returns: insert result|null
app.block.insert({ type: 'text', where: 'after' });
insertBefore#
Inserts a block before the current block.
Parameters:
- type (
string) — block type to insert (e.g.'text') - options (
object) — object with the keys below- data (
object) — initial data for the new block - template (
any) — raw HTML template used whentypeis omitted - focus (
boolean) — whether to focus the new block after insert (defaulttrue) - caret (
any) — caret placement ('start'or'end') when focusing
- data (
Returns: insert result|null
app.block.insertBefore('text');
insertAfter#
Inserts a block after the current block.
Parameters:
- type (
string) — block type to insert (e.g.'text') - options (
object) — object with the keys below- data (
object) — initial data for the new block - template (
any) — raw HTML template used whentypeis omitted - focus (
boolean) — whether to focus the new block after insert (defaulttrue) - caret (
any) — caret placement ('start'or'end') when focusing
- data (
Returns: insert result|null
app.block.insertAfter('list');
isNonDeletable#
Returns whether the block is marked non-deletable.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.isNonDeletable();
isNonEditable#
Returns whether the block is marked non-editable.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.isNonEditable();
setNonDeletable#
Marks block as non-deletable (data-nondeletable="true"). Serialized in JSON as nondeletable: true.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.setNonDeletable();
clearNonDeletable#
Removes non-deletable flag from block.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.clearNonDeletable();
setNonEditable#
Marks block as non-editable (data-noneditable="true") and sets contenteditable="false". Serialized in JSON as noneditable: true.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.setNonEditable();
clearNonEditable#
Clears non-editable flag and restores contenteditable when appropriate.
Parameters:
- block (
Block | HTMLElement) — block instance
Returns: boolean
app.block.clearNonEditable();
remove#
Removes a block from DOM and registry with focus/caret handling.
Parameters:
- block (
Block | HTMLElement) — block instance - focus (
boolean) — whether to focus after operation
Returns: boolean
app.block.remove({ focus: true });
setParent#
Focuses nearest or topmost parent block in the parent chain.
Parameters:
- params (
object) — command or form parameters
Returns: Block|null
app.block.setParent({ to: 'top' });
duplicate#
Clones current block DOM and remounts nested block instances.
Parameters:
- focus (
boolean) — whether to focus after operation
Returns: Block|null
app.block.duplicate();
moveUp#
Moves current block up among siblings within sortable boundary.
Returns: Block|null
app.block.moveUp();
moveDown#
Moves current block down among siblings within sortable boundary.
Returns: Block|null
app.block.moveDown();
unwrap#
Unwraps layout/wrapper block, hoisting children to parent.
Parameters:
- focus (
boolean) — whether to focus after operation
Returns: boolean
app.block.unwrap();
replace#
Replaces current block with another block instance.
Parameters:
- block (
Block | HTMLElement) — block instance - focus (
boolean) — whether to focus after operation
Returns: Block|null
app.block.replace(newBlock);