Behavior API Overview
Reference docs for the behavior API.
defineBehavior
Options Object
- on (string): Internal editor event
- guard (function or boolean): function accepts
context
andevent
, returns boolean - actions (array): function accepts
context
andevent
, returns array of actions
Example
Behavior Event types
Native event types
- copy
- deserialize
- key.down
- key.up
- paste
- serialize
Synthetic event types
- annotation.add
- annotation.remove
- annotation.toggle
- block.set
- block.unset
- blur
- data transfer.set
- decorator.add
- decorator.remove
- decorator.toggle
- delete.backward
- delete.block
- delete.forward
- delete.text
- deserialization.failure
- deserialization.success
- focus
- insert.block
- insert.blocks
- insert.block object
- insert.inline object
- insert.break
- insert.sort break
- insert.span
- insert.text
- insert.text block
- list item.add
- list item.remove
- list item.toggle
- move.block
- move.block down
- move.block up
- select
- select.next block
- select.previous block
- serialization.failure
- serialization.success
- style.add
- style.remove
- style.toggle
- text block.set
- text block.unset
Custom event types
- custom.* (e.g. custom.add link)
Behavior Actions
Actions as part of synthetic events
- annotation.add
- annotation.remove
- annotation.toggle
- block.set
- block.unset
- blur
- data transfer.set
- decorator.add
- decorator.remove
- decorator.toggle
- delete.backward
- delete.block
- delete.forward
- delete.text
- deserialization.failure
- deserialization.success
- focus
- insert.block
- insert.blocks
- insert.block object
- insert.inline object
- insert.break
- insert.sort break
- insert.span
- insert.text
- insert.text block
- list item.add
- list item.remove
- list item.toggle
- move.block
- move.block down
- move.block up
- select
- select.next block
- select.previous block
- serialization.failure
- serialization.success
- style.add
- style.remove
- style.toggle
- text block.set
- text block.unset
Additional actions
- noop
- effect
- raise
raise
The raise
action type is used to trigger synthetic events.
Properties:
- type:
raise
- event: Behavior event object
The raise
action also has a handy shorthand function. It accepts a behavior event object.