多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
750 B

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
document.dispatchEvent(pasteEvent)
return true
} catch (e) {
return false
}
}
return { paste }
}