From a9ea4dce3d030dc70fb29c42e7702af3ea3457c2 Mon Sep 17 00:00:00 2001 From: wangry Date: Tue, 3 Dec 2024 10:53:32 +0800 Subject: [PATCH] fix(table): replace deprecated document.execCommand() with Clipboard API for copy functionality --- .../src/table/modules/table-operation-menu.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/fluent-editor/src/table/modules/table-operation-menu.ts b/packages/fluent-editor/src/table/modules/table-operation-menu.ts index f33c955..3bac2b3 100644 --- a/packages/fluent-editor/src/table/modules/table-operation-menu.ts +++ b/packages/fluent-editor/src/table/modules/table-operation-menu.ts @@ -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 }) @@ -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