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
Argument | Type | Description |
---|---|---|
dropId* | string | The 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>
Argument | Type | Description |
---|---|---|
dropIds* | string[] | The IDs of the drops to retrieve. |
filters | DropFilters | 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
Argument | Type | Description |
---|---|---|
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
dropId* | string | string[] | The ID(s) of the drop(s) to retrieve. |
filters | DropFilters | 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
Argument | Type | Description |
---|---|---|
filters | DropFilters | 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
Argument | Type | Description |
---|---|---|
type* | string | The 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
Argument | Type | Description |
---|---|---|
dropId* | string | The ID of the drop for which to retrieve the data insert. |
Filters drops according to provided filters.
Drops.filter(drops: DropMap, filters: DropFilters): DropMap
Argument | Type | Description |
---|---|---|
drops | DropMap | The drops to filter. |
filters | DropFilters | 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
config* | DropConfig | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
type* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data | CreateDropData | 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>
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
type* | string | The type of drop to create. |
data | DataInsert | The 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>
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data* | DataInsert | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The ID of the drop to update. |
data* | UpdateDropData | The changes to apply to the drop. See below for details. |
UpdateDropData
Property | Type | Description |
---|---|---|
type | string | The drop type. |
parents | | string | |
markdown | string | Delete | The drop's markdown text content. |
files | string[] | Delete | The IDs of the drop's files. All files attached to the drop must be listed here. |
color | ContentColor | Delete | The 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>;
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The ID of the drop into which to insert the data. |
data* | DataInsert | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
dropId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Clears registered drop types from the store and dispaches a drops:clear-register
event.
Drops.clearRegisteredDropTypes(core: Core): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Returns the DropConfig
s of registered drop types.
Drops.getRegisteredDropTypes(types?: string[]): DropConfig[]
Argument | Type | Description |
---|---|---|
types | string[] | 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | DropEvent | The event type to listen for. See the drop events section below for available events. |
callback* | EventListenerCallback | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | DropEvent | The event type for which to remove the event listener. |
callback* | EventListenerCallback | The callback of the event listener to remove. |
See below the table for more details on the data passed by drop related events.
Name | Data | Description |
---|---|---|
drops:register | DropConfig | Dispatched when a new drop type is registered. |
drops:unregister | DropConfig | Dispatched when a drop type is unregistered. |
drops:create | Drop | Dispatched when a drop is created. |
drops:update | ChangeDropEventData | Dispatched when a drop is updated. |
drops:delete | Drop | Dispatched when a drop is deleted. |
drops:restore | Drop | Dispatched when a deleted drop is restored. |
drops:delete-permanently | Drop | Dispatched when a drop is permanently deleted. |
drops:add-parents | AddParentsEventData | Dispatched when parents are added to a drop. |
drops:remove-parents | RemoveParentsEventData | Dispatched when parents are removed from a drop. |
drops:add-tags | AddTagsEventData | Dispatched when tags are added to a drop. |
drops:remove-tags | RemoveTagsEventData | Dispatched when tags are removed from a drop. |
drops:add-files | AddFilesEventData | Dispatched when files are added to a drop. |
drops:remove-files | RemoveFilesEventData | Dispatched when files are removed from a drop. |
drops:replaced-files | ReplaceFilesEventData | Dispatched when a drop's files are replaced with new ones. |
drops:load | Drop[] | Dispatched when drops are loaded into the store. |
drops:clear-drops | Dispatched when drops are cleared from the store. | |
drops:clear-register | Dispatched when registered drop types are cleared from the store. |
Drop events are dispatched with one of the following types of data.
See the DropConfig interface page.
See the Drop interface page.
See the DropParentReference interface.
Property | Type | Description |
---|---|---|
before* | Drop | Drop data before it was changed. |
after* | Drop | Updated drop data. |
changes* | DropChanges | The changes made to the drop. See below for details. |
DropChanges
Property | Type | Description |
---|---|---|
updatedAt* | Date | Timestamp at which the drop was updated. |
type | string | The drop type. Determines which component will be used to render it. |
parents | | DropParentReference[] | The references of the drops's parents. |
tags | | string[] | The IDs of the tags applied to the drop. |
markdown | string | Delete | The drop's markdown text content. |
files | | string[] | The IDs of the drop's files. |
color | ContentColor | Delete | The drop's highlight color. See the Color page for available content colors. |
deleted | boolean | If true , the drop is deleted. |
deletedAt | Date | Timestamp at which the drop was deleted. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop to which the parents were added. |
parents* | DropParentReference[] | The references of the parents which were added to the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop from which the parents were removed. |
parents* | DropParentReference[] | The references of the parents which were removed from the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop to which the tags were added. |
tags* | TagMap | The tags which were added to the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop from which the tags were removed. |
tags* | TagMap | The tags which were removed from the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop to which the files were added. |
files* | FileReferenceMap | The file references of the files which were added to the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop from which the files were removed. |
files* | FileReferenceMap | The files references of the files which were removed from the drop. |
Property | Type | Description |
---|---|---|
drop* | Drop | The drop in which the files were replaced. |
files* | FileReferenceMap | The 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.
Prop | Type | Default |
---|---|---|
type | string[] | |
active | boolean | true |
deleted | boolean | false |