Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update to use writeText

Terry Suttonb1332a4dbe64
diff --git a/package-lock.json b/package-lock.json
index 0881d78353b..9ed78cb140f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -68107,7 +68107,7 @@
"@types/react": "^17.0.37",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-dom": "^17.0.11",
- "@types/react-syntax-highlighter": "*",
+ "@types/react-syntax-highlighter": "^15.5.6",
"autoprefixer": "^10.4.2",
"clsx": "^1.2.1",
"cmdk-supabase": "^0.2.2",
diff --git a/studio/lib/helpers.ts b/studio/lib/helpers.ts
index 35d3398283d..272cae31306 100644
--- a/studio/lib/helpers.ts
+++ b/studio/lib/helpers.ts
@@ -158,28 +158,27 @@ export const snakeToCamel = (str: string) =>
* Safari doesn't support write text into clipboard async, so if you need to load
* text content async before coping, please use Promise<string> for the 1st arg.
*/
-export const copyToClipboard = (str: string | Promise<string>, callback = () => {}) => {
+export const copyToClipboard = async (
+ str: string,
+ callback: () => void = () => {}
+): Promise<void> => {
const focused = window.document.hasFocus()
if (focused) {
- if (window.ClipboardItem) {
- Promise.resolve(str)
- .then((text) => new Blob([text], { type: 'text/plain' }))
- .then((blob) => new ClipboardItem({ 'text/plain': blob }))
- .then((text) => window.navigator?.clipboard?.write([text]))
- .then(callback)
-
- return
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
+ try {
+ await navigator.clipboard.writeText(str)
+ callback()
+ } catch (error) {
+ console.warn('Unable to copy to clipboard')
+ }
+ } else {
+ console.warn('Clipboard writeText method not supported')
}
-
- Promise.resolve(str)
- .then((text) => window.navigator?.clipboard?.writeText(text))
- .then(callback)
} else {
console.warn('Unable to copy to clipboard')
}
}
-
export async function passwordStrength(value: string) {
let message = ''
let warning = ''