Drops

An interface for retrieving and managing drops.

Hooks provide access to drops 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 drop by ID or null if no drop was found.

useDrop<T = Drop>(dropId: string): T | null
ArgumentTypeDescription
dropId*stringThe ID of the drop to retrieve.

Returns a { [id]: Drop } map of drops matching the provided IDs.

useDrops(dropIds: string[], filters?: DropFilters): Record<string, Drop>
ArgumentTypeDescription
dropIds*string[]The IDs of the drops to retrieve.
filtersDropFilters Allows filtering of returned drops. See the DropFilters section for more details.

Returns the DataInsert from which a drop was created, or null if the drop was not created from a data insert or the data insert is no longer in memory.

This hook is mainly intended to provide access the to the files from which a drop was created within the drop component, immediately after its creation.

useDataInsert(dropId: string): DataInsert | null
ArgumentTypeDescription
dropId*stringThe ID of the drop for which to retrieve the data insert.

Retrieves drops by ID. If provided a single ID string, returns the drop or null if not found. If provided an array of IDs, returns a { [id]: Drop } of the corresponding drops.

Drops.get<T = Drop>(dropId: string | string[], filters?: DropFilters): T | DropMap<T> | null
ArgumentTypeDescription
dropId*string | string[]The ID(s) of the drop(s) to retrieve.
filtersDropFilters Allows filtering of returned drops. See the DropFilters section for more details.

Retrieves all drops, returning a DropMap. Returned drops can be filtered by passing in DropFilters.

Drops.getAll(filters?: DropFilters): DropMap
ArgumentTypeDescription
filtersDropFilters Allows filtering of returned drops. See the DropFilters section for more details.

Returns the DropConfig for a given drop type.

Drops.getConfig(type: string): DropConfig
ArgumentTypeDescription
type*stringThe drop type for which to retrieve the config.

Returns the DataInsert from which a drop was created, or null if the drop was not created from a data insert or the data insert is no longer in memory.

This method is mainly intended to provide access the to files from which a drop was created within the drop component, immediately after its creation.

Drops.getDataInsert(dropId: string): DataInsert | null
ArgumentTypeDescription
dropId*stringThe ID of the drop for which to retrieve the data insert.

Filters drops according to provided filters.

Drops.filter(drops: DropMap, filters: DropFilters): DropMap
ArgumentTypeDescription
dropsDropMapThe drops to filter.
filtersDropFilters Filtering options. See the DropFilters section for more details.

Registers a new drop type and dispatches a drops:register event.

Drops.register(core: Core, config: DropConfig): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
config*DropConfigThe configuration of the new drop type to register.

Unregisters a drop type and dispatches a drops:unregister event.

Drops.unregister(core: Core, type: string): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
type*stringThe type of drop to unregister.

Creates a new drop and dispatches a drops:create event. Returns the new drop.

Drops.create(core: Core, data: CreateDropData): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dataCreateDropData The drop data, of which type is the only required value. See below for details.

Creates a drop of the specified type. Data can be provided by supplying a DataInsert object. Returns a promise which resolves to the new drop. Dispatches a drops:create event.

Throws a InvalidDropDataError if the drop could not be created due to invalid or missing data.

Drops.createOfType(core: Core, type: string, data?: DataInsert): Promise<Drop>
ArgumentTypeDescription
core*CoreA MindDrop core instance.
type*stringThe type of drop to create.
dataDataInsertThe data from which to create the drop.

Creates drops of the appropriate type given a DataInsert object and an array of DropConfig objects. Returns a promise resolving to a { [id]: Drop } map of the created drops. Dispatches a drops:create event for each created drop.

Drops.createFromDataInsert(core: Core, data: DataInsert, configs: DropConfig[]): Promise<DropMap>
ArgumentTypeDescription
core*CoreA MindDrop core instance.
data*DataInsertThe data from which to create the drop(s).
configs*DropConfig[]The drop configurations with which to create the drops.

To create the appropriate drop types, the data is matched against the drop configs' dataTypes property. When a match is found, a drop of that type is created.

If multiple drop configs support the provided data, only a single drop of the first type to match will be created. The priority of the matching is based on the order of the configs in the array (the first item having the highest priority).

If the data contains files, the files are matched against the drop config's fileTypes property. When a match is found, a drop of that type is created.

If the data contains multiple files, a drop will be created for each file unless the first matching drop type supports multiple files. In that case, a single drop will be created from all supported files which have not already been matched. Any left over unsupported files will continue on to be matched against other drop types.

Duplicates the given drops, creating new ones containing the same data. Dispatches a drops:create event for each created drop and returns the new drops.

Drops.duplicate(core: Core, dropIds: string[]): DropMap
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropIds*string[]The IDs of the drops to duplicate.

Updates a drop and dispatches a drops:update event. Returns the updated drop.

Drops.update(core: Core, dropId: string, data: UpdateDropData): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to update.
data*UpdateDropDataThe changes to apply to the drop. See below for details.

UpdateDropData

PropertyTypeDescription
typestringThe drop type.
parents| string
| ArrayUnion
| ArrayRemove
markdownstring | DeleteThe drop's markdown text content.
filesstring[] | DeleteThe IDs of the drop's files. All files attached to the drop must be listed here.
colorContentColor | DeleteThe drop's highlight color.

Inserts data into a drop. Does nothing if the drop type is not configured to accept data inserts. Returns a promise which resolves to the updated drop (or original drop if it was not updated). Inserts resulting in a drop update dispatch a drops:update event.

Drops.insertData(core: Core, dropId: string, data: DataInsert): Promise<Drop>;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop into which to insert the data.
data*DataInsertThe data to insert into the drop.

Deletes a drop and dispatches a drops:delete event and an drops:update event. Returns the deleted drop.

Deleted drops can be restored using the Drops.restore method.

Drops.delete(core: Core, dropId: string): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to delete.

Restores a deleted drop and dispatches a drops:restore event and an drops:update event. Returns the restored drop.

Drops.restore(core: Core, dropId: string): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to restore.

Permanently deletes a drop and dispatches a drops:delete-permanently event. Returns the deleted drop.

Permanently deleted drops cannot be restored.

Drops.deletePermanently(core: Core, dropId: string): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to delete.

Adds parent references to a drop and dispatches a drops:add-parents event and a drops:update event. Returns the updated drop.

Drops.addParents(core: Core, dropId: string, parentReferences: DropParentReference[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to which to add the parents.
parentReferences*DropParentReference[] The parent references to add to the drop. See the DropParentReference interface for details.

Remove parent references from a drop and dispatches a drops:remove-parents event and a drops:update event. Returns the updated drop.

Drops.removeParents(core: Core, dropId: string, parentReferences: DropParentReference[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop from which to remove the parents.
parentReferences*DropParentReference[] The parent references to remove from the drop. See the DropParentReference interface for details.

Adds tags to a drop, dispaches an drops:add-tags event and a drops:update event. Returns the updated drop.

Drops.addTags(core: Core, dropId: string, tagIds: string[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to which to add the tags.
tagIds*string[]The IDs of the tags to add.

Removes tags from a drop and dispatches a drops:remove-tags event as well as a drops:update event. Returns the updated drop.

Drops.removeTags(core: Core, dropId: string, tagIds: string[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop from which to remove the tags.
tagIds*string[]The IDs of the tags to remove.

Adds files to a drop, dispaches an drops:add-files event and a drops:update event. Returns the updated drop.

The file references of the added files will be automatically updated to include the drop ID in their attachedTo value.

Drops.addFiles(core: Core, dropId: string, fileIds: string[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop to which to add the files.
fileIds*string[]The IDs of the files to add.

Removes files from a drop and dispatches a drops:remove-files event as well as a drops:update event. Returns the updated drop.

The file references of the removed files will be automatically updated to remove the drop ID from their attachedTo value, and deleted if the drop was their only attachment.

Drops.removeFiles(core: Core, dropId: string, fileIds: string[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop from which to remove the files.
fileIds*string[]The IDs of the files to remove.

Replaces files in a drop (removing current files and adding given files) and dispatches a drops:replace-files event as well as a drops:update event. Returns the updated drop.

The file references of the added files will be automatically updated to include the drop ID in their attachedTo value.

The file references of the removed files will be automatically updated to remove the drop ID from their attachedTo value, and deleted if the drop was their only attachment.

Drops.replaceFiles(core: Core, dropId: string, fileIds: string[]): Drop
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dropId*stringThe ID of the drop for which to replace the files.
fileIds*string[]The IDs of the files to add.

Loads drops into the store and dispatches a drops:load event.

Drops.load(core: Core, drops: Drop[]): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
drops*Drop[]The drops to load into the store.

Clears drops from the store and dispaches a drops:clear-drops event.

Drops.clearDrops(core: Core): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.

Clears registered drop types from the store and dispaches a drops:clear-register event.

Drops.clearRegisteredDropTypes(core: Core): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.

Returns the DropConfigs of registered drop types.

Drops.getRegisteredDropTypes(types?: string[]): DropConfig[]
ArgumentTypeDescription
typesstring[]An array of drop types. If provided, only configs for the given types will be returned.

Adds drop specific event listeners. Equivalent to calling addEventListener directly on core, but provides more advanced type definitions.

Drops.addEventListener(core: Core, event: DropEvent, callback: EventListenerCallback): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*DropEventThe event type to listen for. See the drop events section below for available events.
callback*EventListenerCallbackThe callback fired when the event occurs. See the drop events section below for the data passed to the callback.

Removes drop specific event listeners. Equivalent to calling removeEventListener directly on core, but provides more advanced type definitions.

Drops.removeEventListener(core: Core, event: DropEvent, callback: EventListenerCallback): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*DropEventThe event type for which to remove the event listener.
callback*EventListenerCallbackThe callback of the event listener to remove.

See below the table for more details on the data passed by drop related events.

NameDataDescription
drops:registerDropConfigDispatched when a new drop type is registered.
drops:unregisterDropConfigDispatched when a drop type is unregistered.
drops:createDropDispatched when a drop is created.
drops:updateChangeDropEventDataDispatched when a drop is updated.
drops:deleteDropDispatched when a drop is deleted.
drops:restoreDropDispatched when a deleted drop is restored.
drops:delete-permanentlyDropDispatched when a drop is permanently deleted.
drops:add-parentsAddParentsEventDataDispatched when parents are added to a drop.
drops:remove-parentsRemoveParentsEventDataDispatched when parents are removed from a drop.
drops:add-tagsAddTagsEventDataDispatched when tags are added to a drop.
drops:remove-tagsRemoveTagsEventDataDispatched when tags are removed from a drop.
drops:add-filesAddFilesEventDataDispatched when files are added to a drop.
drops:remove-filesRemoveFilesEventDataDispatched when files are removed from a drop.
drops:replaced-filesReplaceFilesEventDataDispatched when a drop's files are replaced with new ones.
drops:loadDrop[]Dispatched when drops are loaded into the store.
drops:clear-dropsNo dataDispatched when drops are cleared from the store.
drops:clear-registerNo dataDispatched when registered drop types are cleared from the store.

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

DropConfig

See the DropConfig interface page.

Drop

See the Drop interface page.

DropParentReference

See the DropParentReference interface.

UpdateDropEventData

PropertyTypeDescription
before*DropDrop data before it was changed.
after*DropUpdated drop data.
changes*DropChangesThe changes made to the drop. See below for details.

DropChanges

PropertyTypeDescription
updatedAt*DateTimestamp at which the drop was updated.
typestringThe drop type. Determines which component will be used to render it.
parents| DropParentReference[]
| ArrayUnion
| ArrayFilter
The references of the drops's parents.
tags| string[]
| ArrayUnion
| ArrayRemove
The IDs of the tags applied to the drop.
markdownstring | DeleteThe drop's markdown text content.
files| string[]
| ArrayUnion
| ArrayRemove
| Delete
The IDs of the drop's files.
colorContentColor | Delete The drop's highlight color. See the Color page for available content colors.
deletedboolean If true, the drop is deleted.
deletedAtDateTimestamp at which the drop was deleted.

AddParentsEventData

PropertyTypeDescription
drop*DropThe drop to which the parents were added.
parents*DropParentReference[]The references of the parents which were added to the drop.

RemoveParentsEventData

PropertyTypeDescription
drop*DropThe drop from which the parents were removed.
parents*DropParentReference[]The references of the parents which were removed from the drop.

AddTagsEventData

PropertyTypeDescription
drop*DropThe drop to which the tags were added.
tags*TagMapThe tags which were added to the drop.

RemoveTagsEventData

PropertyTypeDescription
drop*DropThe drop from which the tags were removed.
tags*TagMapThe tags which were removed from the drop.

AddFilesEventData

PropertyTypeDescription
drop*DropThe drop to which the files were added.
files*FileReferenceMapThe file references of the files which were added to the drop.

RemoveFilesEventData

PropertyTypeDescription
drop*DropThe drop from which the files were removed.
files*FileReferenceMapThe files references of the files which were removed from the drop.

ReplaceFilesEventData

PropertyTypeDescription
drop*DropThe drop in which the files were replaced.
files*FileReferenceMapThe file references of the files which were added to the drop.

Drops can be filtered using one or more of the options below.

By default, deleted drops are filtered out. If deleted is set to true, active drops will be filtered out by default unless active is also set to true.

A drop is considered active if it is not deleted.

PropTypeDefault
typestring[]No default value
activebooleantrue
deletedbooleanfalse