Editor Events

Equivalent Trix Events: https://github.com/basecamp/trix/blob/main/README.md#observing-editor-changes

Events marked with checkmarks have been implemented. Events without checkmarks have not been implemented yet.

Direct Upload Events

(Thank you Matheus Rich for the inspiration!)

https://github.com/rails/rails/pull/52680

Direct Uploads now have the following events you can listen to in the editor. All of the events have the event.attachmentUpload property which should have all the information you need to react appropriately.

All of the above have a event.attachmentUpload which will contain various properties you need. Such as .progress, .attachment, etc.

For example, here’s how you would grab the progress of a direct upload:

JavaScript
document.querySelector("rhino-editor").addEventListener("rhino-direct-upload:progress", (event) => {
  console.log(event.attachmentUpload.progress)
})

Waiting to submit a form until direct uploads finish

Also of note, the direct-upload attachments will also add a .pendingAttachments to Rhino Editor.

This can be useful for stopping form submissions until all uploads have finished.

Here’s an example of how you could stop form submissions:

JavaScript
form.addEventListener("submit", (e) => {
  if (rhinoEditor.pendingAttachments.length > 0) {
    // There are still pending uploads, so preventDefault() to stop the submission
    e.preventDefault()
  }
})