mirror of https://github.com/nocodb/nocodb
Ramesh Mane
11 months ago
4 changed files with 49 additions and 2 deletions
@ -0,0 +1,28 @@
|
||||
export const usePaste = () => { |
||||
const paste = async (): Promise<boolean> => { |
||||
try { |
||||
// Check if the Clipboard API is supported
|
||||
if (!navigator.clipboard) return false |
||||
|
||||
// Read text from the clipboard
|
||||
const clipboardText = await navigator.clipboard.readText() |
||||
|
||||
// Create a new paste event
|
||||
const pasteEvent = new Event('paste') |
||||
|
||||
// Attach clipboard data to the event
|
||||
const clipboardData = { |
||||
getData: () => clipboardText || '', |
||||
} |
||||
Object.defineProperty(pasteEvent, 'clipboardData', { value: clipboardData }) |
||||
|
||||
// Dispatch the event on the document or any other target element
|
||||
document.dispatchEvent(pasteEvent) |
||||
return true |
||||
} catch (e) { |
||||
return false |
||||
} |
||||
} |
||||
|
||||
return { paste } |
||||
} |
Loading…
Reference in new issue