Database diagrams editor that allows you to visualize and design your DB with a single query.
TypeScript databasedbdb-migrationeditorerdmariadbmssqlmysqlpostgresqlreactreact-flowschema-migrationssqlsqlitetypescriptvisualizationxyflow
fix(clipboard): defensive for navigator clipboard (#462)
Huy Bui5fc10a7e649f
diff --git a/src/components/code-snippet/code-snippet.tsx b/src/components/code-snippet/code-snippet.tsxindex 89bd3f19..51f6f044 100644--- a/src/components/code-snippet/code-snippet.tsx+++ b/src/components/code-snippet/code-snippet.tsx@@ -3,6 +3,7 @@ import React, { lazy, Suspense, useCallback, useEffect } from 'react';import { Spinner } from '../spinner/spinner';import { useTheme } from '@/hooks/use-theme';import { useMonaco } from '@monaco-editor/react';+import { useToast } from '@/components/toast/use-toast';import { Button } from '../button/button';import { Copy, CopyCheck } from 'lucide-react';import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip/tooltip';@@ -38,6 +39,7 @@ export const CodeSnippet: React.FC<CodeSnippetProps> = React.memo(const { t } = useTranslation();const monaco = useMonaco();const { effectiveTheme } = useTheme();+ const { toast } = useToast();const [isCopied, setIsCopied] = React.useState(false);const [tooltipOpen, setTooltipOpen] = React.useState(false);@@ -66,10 +68,32 @@ export const CodeSnippet: React.FC<CodeSnippetProps> = React.memo(}}, [code, monaco, autoScroll]);- const copyToClipboard = useCallback(() => {- navigator.clipboard.writeText(code);- setIsCopied(true);- }, [code]);+ const copyToClipboard = useCallback(async () => {+ if (!navigator?.clipboard) {+ toast({+ title: t('copy_to_clipboard_toast.unsupported.title'),+ variant: 'destructive',+ description: t(+ 'copy_to_clipboard_toast.unsupported.description'+ ),+ });+ return;+ }++ try {+ await navigator.clipboard.writeText(code);+ setIsCopied(true);+ } catch (error) {+ setIsCopied(false);+ toast({+ title: t('copy_to_clipboard_toast.failed.title'),+ variant: 'destructive',+ description: t(+ 'copy_to_clipboard_toast.failed.description'+ ),+ });+ }+ }, [code, t, toast]);return (<divdiff --git a/src/i18n/locales/bn.ts b/src/i18n/locales/bn.tsindex 1dfb39b9..85d12db4 100644--- a/src/i18n/locales/bn.ts+++ b/src/i18n/locales/bn.ts@@ -78,6 +78,17 @@ export const bn: LanguageTranslation = {none: 'কিছুই না',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'কপি ব্যর্থ হয়েছে',+ description: 'ক্লিপবোর্ড সমর্থিত নয়',+ },+ failed: {+ title: 'কপি ব্যর্থ হয়েছে',+ description: 'কিছু ভুল হয়েছে। অনুগ্রহ করে আবার চেষ্টা করুন।',+ },+ },+theme: {system: 'সিস্টেম',light: 'হালকা',diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.tsindex 2db2cf4c..a683e769 100644--- a/src/i18n/locales/de.ts+++ b/src/i18n/locales/de.ts@@ -78,6 +78,18 @@ export const de: LanguageTranslation = {none: 'Keine',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Kopieren fehlgeschlagen',+ description: 'Zwischenablage nicht unterstützt',+ },+ failed: {+ title: 'Kopieren fehlgeschlagen',+ description:+ 'Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.',+ },+ },+theme: {system: 'System',light: 'Hell',diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.tsindex 991b1b13..ea6950a0 100644--- a/src/i18n/locales/en.ts+++ b/src/i18n/locales/en.ts@@ -77,6 +77,17 @@ export const en = {none: 'none',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Copy failed',+ description: 'Clipboard not supported.',+ },+ failed: {+ title: 'Copy failed',+ description: 'Something went wrong. Please try again.',+ },+ },+theme: {system: 'System',light: 'Light',diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.tsindex 0f6da176..f37d866f 100644--- a/src/i18n/locales/es.ts+++ b/src/i18n/locales/es.ts@@ -69,6 +69,17 @@ export const es: LanguageTranslation = {cancel: 'Cancelar',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Copia fallida',+ description: 'Portapapeles no soportado',+ },+ failed: {+ title: 'Copia fallida',+ description: 'Algo salió mal. Por favor, inténtelo de nuevo.',+ },+ },+theme: {system: 'Sistema',light: 'Claro',diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.tsindex 0ca62103..db2c825b 100644--- a/src/i18n/locales/fr.ts+++ b/src/i18n/locales/fr.ts@@ -68,6 +68,17 @@ export const fr: LanguageTranslation = {cancel: 'Annuler',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Échec de la copie',+ description: 'Presse-papiers non pris en charge',+ },+ failed: {+ title: 'Échec de la copie',+ description: 'Quelque chose a mal tourné. Veuillez réessayer.',+ },+ },+theme: {system: 'Système',light: 'Clair',diff --git a/src/i18n/locales/gu.ts b/src/i18n/locales/gu.tsindex d790f3a1..bf02d765 100644--- a/src/i18n/locales/gu.ts+++ b/src/i18n/locales/gu.ts@@ -78,6 +78,17 @@ export const gu: LanguageTranslation = {none: 'કઈ નહીં',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'નકલ નિષ્ફળ',+ description: 'ક્લિપબોર્ડ આધારિત નથી',+ },+ failed: {+ title: 'નકલ નિષ્ફળ',+ description: 'કંઈક ખોટું થયું છે. કૃપા કરીને ફરી પ્રયાસ કરો.',+ },+ },+theme: {system: 'સિસ્ટમ',light: 'હલકો',diff --git a/src/i18n/locales/hi.ts b/src/i18n/locales/hi.tsindex 96742d09..ab550936 100644--- a/src/i18n/locales/hi.ts+++ b/src/i18n/locales/hi.ts@@ -78,6 +78,17 @@ export const hi: LanguageTranslation = {none: 'कोई नहीं',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'कॉपी असफल',+ description: 'क्लिपबोर्ड समर्थित नहीं है',+ },+ failed: {+ title: 'कॉपी असफल',+ description: 'कुछ गलत हो गया। कृपया पुनः प्रयास करें।',+ },+ },+theme: {system: 'सिस्टम',light: 'हल्का',diff --git a/src/i18n/locales/id_ID.ts b/src/i18n/locales/id_ID.tsindex af90be6b..c8b667f5 100644--- a/src/i18n/locales/id_ID.ts+++ b/src/i18n/locales/id_ID.ts@@ -78,6 +78,17 @@ export const id_ID: LanguageTranslation = {none: 'Tidak ada',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Gagal menyalin',+ description: 'Clipboard tidak didukung',+ },+ failed: {+ title: 'Gagal menyalin',+ description: 'Ada yang salah. Silakan coba lagi.',+ },+ },+theme: {system: 'Sistem',light: 'Terang',diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.tsindex 8072bf0d..8a204f47 100644--- a/src/i18n/locales/ja.ts+++ b/src/i18n/locales/ja.ts@@ -79,6 +79,18 @@ export const ja: LanguageTranslation = {none: 'なし',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'コピー失敗',+ description: 'クリップボードがサポートされていません',+ },+ failed: {+ title: 'コピー失敗',+ description:+ '何かがうまくいきませんでした。もう一度お試しください。',+ },+ },+theme: {system: 'システム',light: 'ライト',diff --git a/src/i18n/locales/ko_KR.ts b/src/i18n/locales/ko_KR.tsindex 4f594587..44f5d7a9 100644--- a/src/i18n/locales/ko_KR.ts+++ b/src/i18n/locales/ko_KR.ts@@ -77,6 +77,17 @@ export const ko_KR: LanguageTranslation = {none: '없음',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: '복사 실패',+ description: '클립보드가 지원되지 않습니다"',+ },+ failed: {+ title: '복사 실패',+ description: '문제가 발생했습니다. 다시 시도해주세요.',+ },+ },+theme: {system: '시스템 설정에 따름',light: '밝게',diff --git a/src/i18n/locales/mr.ts b/src/i18n/locales/mr.tsindex fd25320a..ff106f9a 100644--- a/src/i18n/locales/mr.ts+++ b/src/i18n/locales/mr.ts@@ -78,6 +78,17 @@ export const mr: LanguageTranslation = {none: 'काहीही नाही',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'कॉपी अयशस्वी',+ description: 'क्लिपबोर्ड समर्थित नाही',+ },+ failed: {+ title: 'कॉपी अयशस्वी',+ description: 'काहीतरी चूक झाली. कृपया पुन्हा प्रयत्न करा.',+ },+ },+theme: {system: 'सिस्टम',light: 'लाईट',diff --git a/src/i18n/locales/ne.ts b/src/i18n/locales/ne.tsindex ae51d497..4c2adc92 100644--- a/src/i18n/locales/ne.ts+++ b/src/i18n/locales/ne.ts@@ -77,6 +77,17 @@ export const ne: LanguageTranslation = {none: 'कुनै पनि छैन',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'प्रतिलिपि असफल',+ description: 'क्लिपबोर्ड समर्थित छैन',+ },+ failed: {+ title: 'प्रतिलिपि असफल',+ description: 'केही गडबड भयो। कृपया फेरि प्रयास गर्नुहोस्।',+ },+ },+theme: {system: 'सिस्टम',light: 'लाइट',diff --git a/src/i18n/locales/pt_BR.ts b/src/i18n/locales/pt_BR.tsindex 174563f0..20d163a2 100644--- a/src/i18n/locales/pt_BR.ts+++ b/src/i18n/locales/pt_BR.ts@@ -78,6 +78,17 @@ export const pt_BR: LanguageTranslation = {none: 'nenhum',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Falha na cópia',+ description: 'Área de transferência não suportada',+ },+ failed: {+ title: 'Falha na cópia',+ description: 'Algo deu errado. Por favor, tente novamente.',+ },+ },+theme: {system: 'Sistema',light: 'Claro',diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.tsindex 0b9bb985..451749a1 100644--- a/src/i18n/locales/ru.ts+++ b/src/i18n/locales/ru.ts@@ -77,6 +77,18 @@ export const ru: LanguageTranslation = {none: 'никто',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Ошибка копирования',+ description: 'Буфер обмена не поддерживается',+ },+ failed: {+ title: 'Ошибка копирования',+ description:+ 'Что-то пошло не так. Пожалуйста, попробуйте еще раз.',+ },+ },+theme: {system: 'Системная',light: 'Светлая',diff --git a/src/i18n/locales/te.ts b/src/i18n/locales/te.tsindex bb1189b7..e376510a 100644--- a/src/i18n/locales/te.ts+++ b/src/i18n/locales/te.ts@@ -78,6 +78,17 @@ export const te: LanguageTranslation = {none: 'ఎదరికాదు',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'కాపీ విఫలమైంది',+ description: 'క్లిప్బోర్డ్ మద్దతు ఇవ్వదు',+ },+ failed: {+ title: 'కాపీ విఫలమైంది',+ description: 'ఏదో తప్పు జరిగింది. దయచేసి మళ్లీ ప్రయత్నించండి.',+ },+ },+theme: {system: 'సిస్టమ్',light: 'హালకా',diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.tsindex d857a22c..4ef11254 100644--- a/src/i18n/locales/tr.ts+++ b/src/i18n/locales/tr.ts@@ -78,6 +78,17 @@ export const tr: LanguageTranslation = {none: 'yok',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Kopyalama başarısız',+ description: 'Panoya desteklenmiyor',+ },+ failed: {+ title: 'Kopyalama başarısız',+ description: 'Bir şeyler ters gitti. Lütfen tekrar deneyin.',+ },+ },+theme: {system: 'Sistem',light: 'Açık',diff --git a/src/i18n/locales/uk.ts b/src/i18n/locales/uk.tsindex b36d25d8..6ae3a34b 100644--- a/src/i18n/locales/uk.ts+++ b/src/i18n/locales/uk.ts@@ -78,6 +78,17 @@ export const uk: LanguageTranslation = {none: 'немає',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Помилка копіювання',+ description: 'Буфер обміну не підтримується',+ },+ failed: {+ title: 'Помилка копіювання',+ description: 'Щось пішло не так. Будь ласка, спробуйте ще раз.',+ },+ },+theme: {system: 'система',light: 'світлий',diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.tsindex 7beea238..4250b3d1 100644--- a/src/i18n/locales/vi.ts+++ b/src/i18n/locales/vi.ts@@ -77,6 +77,17 @@ export const vi: LanguageTranslation = {none: 'không có',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: 'Sao chép thất bại',+ description: 'Không hỗ trợ bảng tạm',+ },+ failed: {+ title: 'Sao chép thất bại',+ description: 'Đã xảy ra lỗi. Vui lòng thử lại.',+ },+ },+theme: {system: 'Hệ thống',light: 'Sáng',@@ -97,7 +108,7 @@ export const vi: LanguageTranslation = {clear: 'Xóa',show_more: 'Hiển thị thêm',show_less: 'Hiển thị ít hơn',- copy_to_clipboard: 'Sao chép vào Clipboard',+ copy_to_clipboard: 'Sao chép vào bảng tạm',copied: 'Đã sao chép!',side_panel: {diff --git a/src/i18n/locales/zh_CN.ts b/src/i18n/locales/zh_CN.tsindex 203e7352..34533ddf 100644--- a/src/i18n/locales/zh_CN.ts+++ b/src/i18n/locales/zh_CN.ts@@ -74,6 +74,17 @@ export const zh_CN: LanguageTranslation = {none: '无',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: '复制失败',+ description: '不支持剪贴板',+ },+ failed: {+ title: '复制失败',+ description: '出现问题。请再试一次。',+ },+ },+theme: {system: '系统',light: '浅色',diff --git a/src/i18n/locales/zh_TW.ts b/src/i18n/locales/zh_TW.tsindex 0536c72e..24b8c3ce 100644--- a/src/i18n/locales/zh_TW.ts+++ b/src/i18n/locales/zh_TW.ts@@ -74,6 +74,17 @@ export const zh_TW: LanguageTranslation = {none: '無',},+ copy_to_clipboard_toast: {+ unsupported: {+ title: '複製失敗',+ description: '不支援剪貼簿',+ },+ failed: {+ title: '複製失敗',+ description: '出現問題。請再試一次。',+ },+ },+theme: {system: '系統',light: '淺色',