On September 25th, 2024, we released v2 of the Apps SDK. To learn what’s new and how to upgrade, see Migration FAQ and Migration guide.

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.

Parameters

optsobject
REQUIRED

Options for configuring the content selection callback.

Properties of opts
scopeScope
REQUIRED

The type of content that triggers a selection change event.

The available options include:

  • "plaintext"
  • "image"
  • "video"
  • "richtext"
onChangefunction
REQUIRED

The callback to run when the selected content changes.

Parameters

eventSelectionEvent<Scope>
REQUIRED

Information about the selection change event.

Properties of event
scopeScope
REQUIRED

The type of content that's selected.

The available options include:

  • "plaintext"
  • "image"
  • "video"
  • "richtext"
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>

Returns

void

Returns

() => void