Files
nocodb/packages/nc-gui/composables/usePaste.ts
Mert E 89f0895de3 fix: experimental frontend optimizations (#8427)
* fix: get rid of barrel files

* chore: get rid of explicit imports

* fix: use explicit import for classes and enums

* fix: use explicit import for enum & class & aliases

* fix: build issues
2024-05-08 15:55:09 +05:30

36 lines
942 B
TypeScript

export const usePaste = () => {
const { t } = useI18n()
const paste = async (): Promise<boolean> => {
try {
// Check if the Clipboard API is supported
if (!navigator.clipboard) throw new Error(t('msg.error.pasteFromClipboardError'))
// Read text from the clipboard
const clipboardText = await navigator.clipboard.readText()
// Create a new paste event
const pasteEvent = new Event('paste', {
bubbles: false,
cancelable: true,
})
// 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) {
message.error(t('msg.error.pasteFromClipboardError'))
return false
}
}
return { paste }
}