Skip to content

Commit

Permalink
fix(table): replace deprecated document.execCommand() with Clipboard …
Browse files Browse the repository at this point in the history
…API for copy functionality
  • Loading branch information
qwangry committed Dec 3, 2024
1 parent 6d8ab96 commit a9ea4dc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/fluent-editor/src/table/modules/table-operation-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ export default class TableOperationMenu {
const dom = this.table.cloneNode(true)
const trArr = dom.querySelectorAll('tr[data-row]')
trArr.forEach(tr => tr.removeAttribute('data-row'))
if (!navigator.clipboard || !navigator.clipboard.write) {
dom.style.position = 'fixed'
dom.style.top = 0
dom.style.left = 0
dom.style.clip = 'rect(0,0,0,0)'
document.body.appendChild(dom)
this.setCopyRange(dom)
document.execCommand('copy')
dom.remove()
return
}
this.setCopyRange(dom)
const blob = new Blob([dom.outerHTML], { type: 'text/html' })
const clipboardItem = new ClipboardItem({ 'text/html': blob })
Expand Down Expand Up @@ -461,6 +472,13 @@ export default class TableOperationMenu {
async onCopy(operation) {
const { selectedTds } = this.tableSelection
const virtualTable = this.createVirtualTable(selectedTds, operation)
if (!navigator.clipboard || !navigator.clipboard.write) {
document.body.appendChild(virtualTable)
this.setCopyRange(virtualTable)
document.execCommand('copy')
virtualTable.remove()
return
}
this.setCopyRange(virtualTable)
this.tableSelection.preSelectedTable = virtualTable
this.tableSelection.preSelectedTds = selectedTds
Expand Down

0 comments on commit a9ea4dc

Please sign in to comment.