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;
Argument | Type | Description |
---|---|---|
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
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;
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data | CreateRTDocumentData | The rich text document data. See the table below for details. |
Data used to create a rich text document.
Property | Type | Description |
---|---|---|
children | string[] | The IDs of the rich text block elements making up the root level content of the document (nested elements should not be listed here). |
revision | string | An 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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. |
revision | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The ID of the rich text document for which to set the revision. |
revision* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documentId* | string | The 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
Argument | Type | Description |
---|---|---|
document* | RTDocument | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
documents* | RTDocument | The 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.
Name | Data | Description |
---|---|---|
rich-text-document:create | RTDocument | Dispatched when a rich text document is created. |
rich-text-document:update | UpdateRTDocumentEventData | Dispatched when a rich text document is updated. |
rich-text-document:delete | RTDocument | Dispatched when a rich text document is deleted. |
rich-text-document:restore | RTDocument | Dispatched when a deleted rich text document is restored. |
rich-text-document:delete-permanently | RTDocument | Dispatched when a rich text document is permanently deleted. |
rich-text-document:set-children | SetRTDocumentChildrenEventData | Dispatched when a rich text document's children are set. |
rich-text-document:add-parents | AddParentsToRTDocumentEventData | Dispatched when parents are added to a rich text document. |
rich-text-document:remove-parents | RemoveParentsFromRTDocumentEventData | Dispatched when parents are removed from a rich text document. |
rich-text-document:load | RTDocument[] | Dispatched when rich text documents are loaded into the store. |
RichTextDocument events are dispatched with one of the following types of data.
See the RichTextDocument interface page.
See the ParentReference interface page.
Property | Type | Description |
---|---|---|
before* | RTDocument | The rich text document before it was updated. |
after* | RTDocument | The updated rich text document. |
changes* | RTDocumentChanges | The changes applied to the rich text document. See below for details. |
RTDocumentChanges
Property | Type | Description |
---|---|---|
updatedAt* | Date | Timestamp at which the rich text document was updated. |
revision* | string | An UUID used to distinguish between different revisions of a rich text document. |
children | | string[] | The IDs of the RTBlockElement s which make up the root level content of the document. |
deleted | true | If true , the rich text document is deleted. Not present if the rich text document is not deleted. |
deletedAt | Date | Timestamp at which the rich text document was deleted. Only set ifdeleted is true . |
Property | Type | Description |
---|---|---|
document* | RTDocument | The rich text document in which the elements were set. |
removedElements* | RTBlockElementMap | The rich text block elements which were removed from the document. |
addedElements* | RTBlockElementMap | The rich text block elements which were added to the document. |
Property | Type | Description |
---|---|---|
document* | RTDocument | The rich text document to which the parents were added. |
parents* | ParentReference[] | The references of the parents which were added to the rich text document. |
Property | Type | Description |
---|---|---|
document* | RTDocument | The rich text document from which the parents were removed. |
parents* | ParentReference[] | The references of the parents which were removed from the rich text document. |