attaches icon indicating copy to clipboard operation
attaches copied to clipboard

Option to handle the deletion of files

Open lhps opened this issue 3 years ago • 7 comments

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

lhps avatar Sep 21 '22 20:09 lhps

Did anything like this ever get added? its pretty important or is there a work around?

Intrflex avatar Jul 09 '25 07:07 Intrflex

This is fairly important. Hope some workaround is there.

feavel1 avatar Oct 21 '25 09:10 feavel1

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.

neSpecc avatar Oct 21 '25 11:10 neSpecc

Or, optionally, we could consider introducing a method in the Tools API for that.

neSpecc avatar Oct 21 '25 11:10 neSpecc

Probably removed Lifecycle Hook could be used

neSpecc avatar Oct 21 '25 12:10 neSpecc

So we can add removingEndpoint to the config

neSpecc avatar Oct 21 '25 12:10 neSpecc

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

rajmondx avatar Nov 03 '25 14:11 rajmondx