Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix: remove dependency of t from clipboard and image (#7712)

Aakansha Doshif5ab3e4e12e9
diff --git a/excalidraw-app/collab/RoomDialog.tsx b/excalidraw-app/collab/RoomDialog.tsx
index f2614674de..74266d3d91 100644
--- a/excalidraw-app/collab/RoomDialog.tsx
+++ b/excalidraw-app/collab/RoomDialog.tsx
@@ -65,20 +65,19 @@ export const RoomModal = ({
const copyRoomLink = async () => {
try {
await copyTextToSystemClipboard(activeRoomLink);
+ } catch (e) {
+ setErrorMessage(t("errors.copyToSystemClipboardFailed"));
+ }
+ setJustCopied(true);
- setJustCopied(true);
-
- if (timerRef.current) {
- window.clearTimeout(timerRef.current);
- }
-
- timerRef.current = window.setTimeout(() => {
- setJustCopied(false);
- }, 3000);
- } catch (error: any) {
- setErrorMessage(error.message);
+ if (timerRef.current) {
+ window.clearTimeout(timerRef.current);
}
+ timerRef.current = window.setTimeout(() => {
+ setJustCopied(false);
+ }, 3000);
+
ref.current?.select();
};
diff --git a/excalidraw-app/share/ShareDialog.tsx b/excalidraw-app/share/ShareDialog.tsx
index 2fa92dff86..85e500dae2 100644
--- a/excalidraw-app/share/ShareDialog.tsx
+++ b/excalidraw-app/share/ShareDialog.tsx
@@ -69,20 +69,20 @@ const ActiveRoomDialog = ({
const copyRoomLink = async () => {
try {
await copyTextToSystemClipboard(activeRoomLink);
+ } catch (e) {
+ collabAPI.setErrorMessage(t("errors.copyToSystemClipboardFailed"));
+ }
- setJustCopied(true);
-
- if (timerRef.current) {
- window.clearTimeout(timerRef.current);
- }
+ setJustCopied(true);
- timerRef.current = window.setTimeout(() => {
- setJustCopied(false);
- }, 3000);
- } catch (error: any) {
- collabAPI.setErrorMessage(error.message);
+ if (timerRef.current) {
+ window.clearTimeout(timerRef.current);
}
+ timerRef.current = window.setTimeout(() => {
+ setJustCopied(false);
+ }, 3000);
+
ref.current?.select();
};
diff --git a/packages/excalidraw/actions/actionClipboard.tsx b/packages/excalidraw/actions/actionClipboard.tsx
index b9634886b1..dbc3c87516 100644
--- a/packages/excalidraw/actions/actionClipboard.tsx
+++ b/packages/excalidraw/actions/actionClipboard.tsx
@@ -238,7 +238,11 @@ export const copyText = register({
return acc;
}, [])
.join("\n\n");
- copyTextToSystemClipboard(text);
+ try {
+ copyTextToSystemClipboard(text);
+ } catch (e) {
+ throw new Error(t("errors.copyToSystemClipboardFailed"));
+ }
return {
commitToHistory: false,
};
diff --git a/packages/excalidraw/clipboard.ts b/packages/excalidraw/clipboard.ts
index c6b6082ffa..e24961c647 100644
--- a/packages/excalidraw/clipboard.ts
+++ b/packages/excalidraw/clipboard.ts
@@ -17,7 +17,6 @@ import { deepCopyElement } from "./element/newElement";
import { mutateElement } from "./element/mutateElement";
import { getContainingFrame } from "./frame";
import { arrayToMap, isMemberOf, isPromiseLike } from "./utils";
-import { t } from "./i18n";
type ElementsClipboard = {
type: typeof EXPORT_DATA_TYPES.excalidrawClipboard;
@@ -435,7 +434,7 @@ export const copyTextToSystemClipboard = async (
// (3) if that fails, use document.execCommand
if (!copyTextViaExecCommand(text)) {
- throw new Error(t("errors.copyToSystemClipboardFailed"));
+ throw new Error("Error copying to clipboard.");
}
};
diff --git a/packages/excalidraw/components/ShareableLinkDialog.tsx b/packages/excalidraw/components/ShareableLinkDialog.tsx
index cb8ba4cefc..145cc21b58 100644
--- a/packages/excalidraw/components/ShareableLinkDialog.tsx
+++ b/packages/excalidraw/components/ShareableLinkDialog.tsx
@@ -31,20 +31,19 @@ export const ShareableLinkDialog = ({
const copyRoomLink = async () => {
try {
await copyTextToSystemClipboard(link);
+ } catch (e) {
+ setErrorMessage(t("errors.copyToSystemClipboardFailed"));
+ }
+ setJustCopied(true);
- setJustCopied(true);
-
- if (timerRef.current) {
- window.clearTimeout(timerRef.current);
- }
-
- timerRef.current = window.setTimeout(() => {
- setJustCopied(false);
- }, 3000);
- } catch (error: any) {
- setErrorMessage(error.message);
+ if (timerRef.current) {
+ window.clearTimeout(timerRef.current);
}
+ timerRef.current = window.setTimeout(() => {
+ setJustCopied(false);
+ }, 3000);
+
ref.current?.select();
};
diff --git a/packages/excalidraw/data/index.ts b/packages/excalidraw/data/index.ts
index 51446921f7..ac3975696e 100644
--- a/packages/excalidraw/data/index.ts
+++ b/packages/excalidraw/data/index.ts
@@ -133,9 +133,12 @@ export const exportCanvas = async (
},
);
} else if (type === "clipboard-svg") {
- await copyTextToSystemClipboard(
- await svgPromise.then((svg) => svg.outerHTML),
- );
+ const svg = await svgPromise.then((svg) => svg.outerHTML);
+ try {
+ await copyTextToSystemClipboard(svg);
+ } catch (e) {
+ throw new Error(t("errors.copyToSystemClipboardFailed"));
+ }
return;
}
}
diff --git a/packages/excalidraw/element/image.ts b/packages/excalidraw/element/image.ts
index bd9bcd6270..ad94c51e03 100644
--- a/packages/excalidraw/element/image.ts
+++ b/packages/excalidraw/element/image.ts
@@ -3,7 +3,6 @@
// -----------------------------------------------------------------------------
import { MIME_TYPES, SVG_NS } from "../constants";
-import { t } from "../i18n";
import { AppClassProperties, DataURL, BinaryFiles } from "../types";
import { isInitializedImageElement } from "./typeChecks";
import {
@@ -100,7 +99,7 @@ export const normalizeSVG = async (SVGString: string) => {
const svg = doc.querySelector("svg");
const errorNode = doc.querySelector("parsererror");
if (errorNode || !isHTMLSVGElement(svg)) {
- throw new Error(t("errors.invalidSVGString"));
+ throw new Error("Invalid SVG");
} else {
if (!svg.hasAttribute("xmlns")) {
svg.setAttribute("xmlns", SVG_NS);
diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.json
index b983586bbd..924d5c8aec 100644
--- a/packages/excalidraw/locales/en.json
+++ b/packages/excalidraw/locales/en.json
@@ -214,7 +214,6 @@
"fileTooBig": "File is too big. Maximum allowed size is {{maxSize}}.",
"svgImageInsertError": "Couldn't insert SVG image. The SVG markup looks invalid.",
"failedToFetchImage": "Failed to fetch image.",
- "invalidSVGString": "Invalid SVG.",
"cannotResolveCollabServer": "Couldn't connect to the collab server. Please reload the page and try again.",
"importLibraryError": "Couldn't load library",
"collabSaveFailed": "Couldn't save to the backend database. If problems persist, you should save your file locally to ensure you don't lose your work.",
@@ -248,7 +247,7 @@
"library": "Library",
"lock": "Keep selected tool active after drawing",
"penMode": "Pen mode - prevent touch",
- "link": "Add/ Update link for a selected shape",
+ "link": "Add / Update link for a selected shape",
"eraser": "Eraser",
"frame": "Frame tool",
"magicframe": "Wireframe to code",