Mounts, unmounts, and looks up block instances.
Access:
app.getService('blockManager')
App code:
const blockManager = app.getService('blockManager');
Plugin:
const blockManager = this.app.getService('blockManager');
register#
Registers a block class for a type string, replacing any previous registration and tracking focusable types from Block.meta.
Parameters:
- type (
string) — block or entity type name - Block (
Block | HTMLElement) — block class (constructor)
blockManager.register('quote', QuoteBlock);
parse#
Finds the first registered block class that matches the element and instantiates a block wrapper around it.
Parameters:
- el (
HTMLElement | string) — DOM element
Returns: Block|null
blockManager.parse(element);
mount#
Parses an element into a block instance and adds it to the blocks collection when a match is found.
Parameters:
- el (
HTMLElement | string) — DOM element
Returns: Block|null
blockManager.mount(newEl);
resolve#
Returns the block class constructor that matches the element without creating an instance.
Parameters:
- el (
HTMLElement | string) — DOM element
Returns: class|null
blockManager.resolve(element);
create#
Instantiates a new block of the given type and optionally appends child blocks parsed from a children JSON array.
Parameters:
- type (
string) — block or entity type name - data (
object) — payload data
Returns: Block
blockManager.create('paragraph', { text: 'Hello' });
getType#
Returns the registered block type name for an element, or unknown when no block class matches.
Parameters:
- el (
HTMLElement | string) — DOM element
Returns: string
blockManager.getType(element);
getBlockClass#
Returns the registered block class constructor for a type name.
Parameters:
- type (
string) — block or entity type name
Returns: class|null
blockManager.getBlockClass('list');
is#
Returns whether the element matches the block class registered for the given type.
Parameters:
- el (
HTMLElement | string) — DOM element - type (
string) — block or entity type name
Returns: boolean
blockManager.is(element, 'image');