Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/nodes/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,33 @@ const Image = TiptapImage.extend({
}
},
handlePaste: (view, event, slice) => {
const data = event.clipboardData
if (!data) {
return false
}

// Check if the pasted content contains a table, either in HTML or TSV-like format. If so, let the regular paste pipeline handle it.
const html = data.getData('text/html') || ''
const text = data.getData('text/plain') || ''
const hasHtmlTable = /<table[\s>]/i.test(html)
const hasTsvLikeTable =
text.includes('\t') && text.includes('\n')
if (hasHtmlTable || hasTsvLikeTable) {
// Let regular paste pipeline parse table content
return false
}

// only catch the paste if it contains files
if (
event.clipboardData.files
&& event.clipboardData.files.length > 0
) {
// let the editor wrapper catch this custom event
if (event.target && data.files && data.files.length > 0) {
const customEvent = new CustomEvent('image-paste', {
bubbles: true,
detail: {
files: event.clipboardData.files,
},
detail: { files: data.files },
})
event.target.dispatchEvent(customEvent)
return true
}

return false
},
},
}),
Expand Down
Loading