I see that there is a way to programmatically insert a file/attachment, but is there a way to programmatically remove attachments? Being able to remove attachments by id would be awesome.
If you still have a reference to an attachment from an event, you can call its remove() method:
addEventListener("trix-attachment-add", event => {
const { attachment } = event
setTimeout(() => {
attachment.remove()
}, 1000)
})
Otherwise, you can use the editor.setSelectedRange() and editor.deleteInDirection() APIs.
If you want to venture into not-technically-public APIs, this will work too:
const attachment = editor.getDocument().getAttachmentById(id)
editor.composition.removeAttachment(attachment)
This works great, thank you so much for the response.
Most helpful comment
If you want to venture into not-technically-public APIs, this will work too: