Option to handle the deletion of files
give a option to configure a route to send a request when deleting files, to remove the file from a cloud for example, when the file is deleted from the editor
Did anything like this ever get added? its pretty important or is there a work around?
This is fairly important. Hope some workaround is there.
You can listen for the Editor.js onChange event and handle the BlockRemovedEvent there. Since there are many ways to remove blocks in the editor, a specific tool can’t reliably detect it on its own.
Or, optionally, we could consider introducing a method in the Tools API for that.
Probably removed Lifecycle Hook could be used
So we can add removingEndpoint to the config
Did anything like this ever get added? its pretty important or is there a work around?
You can find a workaround here https://github.com/editor-js/image/issues/54#issuecomment-724661390
According to @neSpecc you shouldn't count "amountPreviousBlocks != amountCurrentBlocks" but use BlockRemovedEvent instead.
Edit:
new EditorJS({
onChange: async (inEditor, events) => {
await handleEvents(events)
},
});
async function handleEvents(inEvents: BlockMutationEvent | BlockMutationEvent[]) {
const events: BlockMutationEvent[] = Array.isArray(inEvents) ? inEvents : [inEvents]
for (const event of events) {
if (isAttachRemovedEvent(event)) {
const blockData = await event.detail.target.save()
if (blockData) {
console.log('attachment removed', blockData.data)
}
}
}
}
// fake event, basically BlockRemovedEvent having 'attaches' as a target
function isAttachRemovedEvent(event: BlockMutationEvent): event is BlockRemovedEvent {
return isBlockRemovedEvent(event) && event.detail.target.name === 'attaches'
}
function isBlockRemovedEvent(event: BlockMutationEvent): event is BlockRemovedEvent {
return event.type === 'block-removed'
}
I hoped that there was a possibility todo something like editor.on('BlockRemovedEvent', ...) or on('block-removed') or on('block-added') etc. pp.
So if anyone has a more elegant solution, please spit it out