RichTextDocuments

An interface for retrieving and managing rich text documents.

Hooks provide access to rich text documents and related data from inside React components. Unlike data accessed using static methods, hooks will cause the component to rerender when the data changes.

Returns a rich text document by ID or null if it does not exist.

useRichTextDocument(documentId: string): RTDocument | null;
ArgumentTypeDescription
documentId*stringThe ID of the rich text document to retrieve.

Retrieves rich text documents by ID. If provided a single ID string, returns the matching rich text document. If provided an array of IDs, returns a { [id]: RTDocument } map of the corresponding rich text documents.

  • Throws a RichTextDocumentNotFoundError if a document does not exist.

// Get a single rich text document
RichTextDocuments.get(documentId: string): RTDocument
// Get multiple rich text documents
RichTextDocuments.get(documentId: string[]): RTDocumentMap
ArgumentTypeDescription
documentId*string | string[]The ID(s) of the rich text document(s) to retrieve.

Retrieves all rich text documents as a { [id]: RTDocument } map.

RichTextDocuments.getAll(): RTDocumentMap

Creates a new rich text document and dispaches a rich-text-document:create event. Returns the new rich text document.

Adds the document as a parent on all rich text block elements listen in children.

  • Throws a RichTextElementNotFoundError if any of the rich text elements listed in children do not exist.

  • Throws a RichTextElementTypeNotRegistered if any of the rich text elements listed in children are of an unregistered type.

  • Throws a RichTextDocumentValidationError if any of the elements listen in children are not block level elements.

RichTextDocuments.create(core: Core, data?: CreateRTDocumentData): RTDocument;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dataCreateRTDocumentDataThe rich text document data. See the table below for details.

CreateRTDocumentData

Data used to create a rich text document.

PropertyTypeDescription
childrenstring[]The IDs of the rich text block elements making up the root level content of the document (nested elements should not be listed here).
revisionstringAn UUID used to distinguish between different revisions of a rich text document. If not set, a new one will be automatically generated.

Deletes a rich text document and dispaches a rich-text-document:delete event. Returns the deleted document.

Deleted rich text documents can be restored using the RichTextDocuments.restore method.

  • Throws a RichTextDocumentNotFoundError if the document does not exist.

RichTextDocuments.delete(core: Core, documentId: string): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document to delete.

Restores a deleted rich text document and dispatches a rich-text-document:restore event. Returns the restored document.

  • Throws a RichTextDocumentNotFoundError if the document does not exist.

RichTextDocuments.restore(core: Core, documentId: string): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document to restore.

Permanently deletes a rich text document and dispatches a rich-text-document:delete-permanently event. Returns the deleted document.

Permanently deleted rich text documents cannot be restored.

  • Throws a RichTextDocumentNotFoundError if the document does not exist.

RichTextDocuments.deletePermanently(core: Core, documentId: string): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document to delete permanently.

Sets the child elements of a rich text document and dispatches a rich-text-document:set-children event. Returns the updated document.

Adds the document as a parent on any added child elements and removes the document as a parent from any removed child elements. Optionally, a new revision ID can be passed to update the document's revision.

  • Throws a RichTextDocumentNotFoundError if the rich text document does not exist.

  • Throws a RichTextElementNotFoundError if any of the rich text block elements do not exist.

  • Throws a RichTextDocumentValidationError if any of the added elements are not block level elements.

RichTextDocuments.setChildren(
core: Core,
documentId: string,
children: string[],
revision?: string
): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document for which to set the children.
children*string[]The IDs of the rich text block elements which make up the root level elements of the document.
revisionstringThe document revision ID.

Sets a new reivsion on the document and dispaches a rich-text-document:update event. Returns the updated document.

  • Throws a RichTextDocumentNotFoundError if the rich text document does not exist.

RichTextDocuments.setRevision(
core: Core,
documentId: string,
revision: string
): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document for which to set the revision.
revision*stringThe document revision ID.

Adds parent references to a rich text document and dispatches a rich-text-document:add-parents event. Returns the updated rich text document.

  • Throws a RichTextDocumentNotFoundError if the document does not exist.

  • Throws a ParentReferenceValidationError if any of the parent references are invalid.

RichTextDocuments.addParents(
core: Core,
documentId: string,
parentReferences: ParentReference[],
): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document to which to add parents.
parentReferences*ParentReference[] The parent references to add to the rich text document. See the ParentReference interface for details.

Remove parents references from a rich text document and dispaches a rich-text-document:remove-parents event. Returns the updated rich text document.

  • Throws a RichTextDocumentNotFoundError if the document does not exist.

RichTextDocuments.removeParents(
core: Core,
documentId: string,
parentReferences: ParentReference[],
): RTDocument
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documentId*stringThe ID of the rich text document from which to remove parents.
parentReferences*ParentReference[] The parent references to remove from the rich text document. See the ParentReference interface for details.

Converts a rich text document to a plain text string. Void elements are converted using their toPlainText method. If they do not have such a method, they are omited.

  • Throws a RichTextElementNotFoundError if any of the document's rich text elements do no exist.

toPlainText(document: RTDocument): string
ArgumentTypeDescription
document*RTDocumentThe rich text document to convert into plain text.

Loads rich text documents into the store and dispatches a rich-text-document:load event.

RichTextDocuments.load(core: Core, documents: RTDocument[]): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
documents*RTDocumentThe rich text documents to load.

Clears all rich text documents from the store. This method is only intended for use in tests, do not use within your extension code.

RichTextDocuments.clear(): void

See below the table for more details on the data passed by rich text document related events.

NameDataDescription
rich-text-document:createRTDocumentDispatched when a rich text document is created.
rich-text-document:updateUpdateRTDocumentEventDataDispatched when a rich text document is updated.
rich-text-document:deleteRTDocumentDispatched when a rich text document is deleted.
rich-text-document:restoreRTDocumentDispatched when a deleted rich text document is restored.
rich-text-document:delete-permanentlyRTDocumentDispatched when a rich text document is permanently deleted.
rich-text-document:set-childrenSetRTDocumentChildrenEventDataDispatched when a rich text document's children are set.
rich-text-document:add-parentsAddParentsToRTDocumentEventDataDispatched when parents are added to a rich text document.
rich-text-document:remove-parentsRemoveParentsFromRTDocumentEventDataDispatched when parents are removed from a rich text document.
rich-text-document:loadRTDocument[]Dispatched when rich text documents are loaded into the store.

RichTextDocument events are dispatched with one of the following types of data.

RichTextDocument

See the RichTextDocument interface page.

ParentReference

See the ParentReference interface page.

UpdateRTDocumentEventData

PropertyTypeDescription
before*RTDocumentThe rich text document before it was updated.
after*RTDocumentThe updated rich text document.
changes*RTDocumentChangesThe changes applied to the rich text document. See below for details.

RTDocumentChanges

PropertyTypeDescription
updatedAt*DateTimestamp at which the rich text document was updated.
revision*stringAn UUID used to distinguish between different revisions of a rich text document.
children| string[]
| ArrayUnion
| ArrayRemove
The IDs of the RTBlockElements which make up the root level content of the document.
deletedtrue If true, the rich text document is deleted. Not present if the rich text document is not deleted.
deletedAtDate Timestamp at which the rich text document was deleted. Only set ifdeleted is true.

SetRTDocumentChildrenEventData

PropertyTypeDescription
document*RTDocumentThe rich text document in which the elements were set.
removedElements*RTBlockElementMapThe rich text block elements which were removed from the document.
addedElements*RTBlockElementMapThe rich text block elements which were added to the document.

AddParentsToRTDocumentEventData

PropertyTypeDescription
document*RTDocumentThe rich text document to which the parents were added.
parents*ParentReference[]The references of the parents which were added to the rich text document.

RemoveParentsFromRTDocumentEventData

PropertyTypeDescription
document*RTDocumentThe rich text document from which the parents were removed.
parents*ParentReference[]The references of the parents which were removed from the rich text document.