selection.registerOnChange

API reference for the selection.registerOnChange method.

Registers a callback that runs when the specified type of content is selected.

This callback fires immediately if content is already selected when the callback is registered.

#optsobject
Required

Options for configuring the content selection callback.

Properties of opts
#onChangefunction
Required

The callback to run when the selected content changes.

Parameters

#eventSelectionEvent<Scope>
Required

Information about the selection change event.

Properties of event
#countnumber
Required

The number of selected elements.

#readfunction
Required

Returns a snapshot of the content in the user's selection.

The snapshot is known as the draft.

Returns

A snapshot of content from a user's design. This is a Promise that resolves with the following object:

#contentsT[]

The individual content items that exist within the snapshot.

Any changes made to this array won't be reflected in the user's design until the save method is called.

#savefunction

Saves changes made to the content items in the contents array.

Once this method is called:

  • Any changes the app has made to to the content will be reflected in the user's design.
  • Any changes the user has made to the content since the snapshot was created may be overwritten.
  • Only properties that are different from the original state will be written to the design.

Returns

Promise<void>

#scopeScope
Required

The type of content that's selected.

The available options include:

  • "plaintext"
  • "image"
  • "video"
  • "richtext"

Returns

void

#scopeScope
Required

The type of content that triggers a selection change event.

The available options include:

  • "plaintext"
  • "image"
  • "video"
  • "richtext"

() => void