Virtual whiteboard for sketching hand-drawn like diagrams
fix: make getEmbedLink independent of t function (#7643)
Aakansha Doshi0c3dffb082c8
diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsxindex c357b4ca3c..f965a76795 100644--- a/packages/excalidraw/components/App.tsx+++ b/packages/excalidraw/components/App.tsx@@ -6501,8 +6501,11 @@ class App extends React.Component<AppProps, AppState> {return;}- if (embedLink.warning) {- this.setToast({ message: embedLink.warning, closable: true });+ if (embedLink.error instanceof URIError) {+ this.setToast({+ message: t("toast.unrecognizedLinkFormat"),+ closable: true,+ });}const element = newEmbeddableElement({diff --git a/packages/excalidraw/element/Hyperlink.tsx b/packages/excalidraw/element/Hyperlink.tsxindex a69fdeb836..930b877631 100644--- a/packages/excalidraw/element/Hyperlink.tsx+++ b/packages/excalidraw/element/Hyperlink.tsx@@ -120,8 +120,11 @@ export const Hyperlink = ({} else {const { width, height } = element;const embedLink = getEmbedLink(link);- if (embedLink?.warning) {- setToast({ message: embedLink.warning, closable: true });+ if (embedLink?.error instanceof URIError) {+ setToast({+ message: t("toast.unrecognizedLinkFormat"),+ closable: true,+ });}const ar = embedLink? embedLink.intrinsicSize.w / embedLink.intrinsicSize.hdiff --git a/packages/excalidraw/element/embeddable.ts b/packages/excalidraw/element/embeddable.tsindex f62b0f95f4..fb51c7283b 100644--- a/packages/excalidraw/element/embeddable.ts+++ b/packages/excalidraw/element/embeddable.ts@@ -1,6 +1,5 @@import { register } from "../actions/register";import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants";-import { t } from "../i18n";import { ExcalidrawProps } from "../types";import { getFontString, updateActiveTool } from "../utils";import { setCursorForShape } from "../cursor";@@ -107,8 +106,8 @@ export const getEmbedLink = (const vimeoLink = link.match(RE_VIMEO);if (vimeoLink?.[1]) {const target = vimeoLink?.[1];- const warning = !/^\d+$/.test(target)- ? t("toast.unrecognizedLinkFormat")+ const error = !/^\d+$/.test(target)+ ? new URIError("Invalid embed link format"): undefined;type = "video";link = `https://player.vimeo.com/video/${target}?api=1`;@@ -120,7 +119,7 @@ export const getEmbedLink = (intrinsicSize: aspectRatio,type,});- return { link, intrinsicSize: aspectRatio, type, warning };+ return { link, intrinsicSize: aspectRatio, type, error };}const figmaLink = link.match(RE_FIGMA);diff --git a/packages/excalidraw/element/types.ts b/packages/excalidraw/element/types.tsindex f89e8d5f23..aae0a8a30c 100644--- a/packages/excalidraw/element/types.ts+++ b/packages/excalidraw/element/types.ts@@ -104,7 +104,7 @@ export type ExcalidrawIframeLikeElement =export type IframeData =| {intrinsicSize: { w: number; h: number };- warning?: string;+ error?: Error;} & (| { type: "video" | "generic"; link: string }| { type: "document"; srcdoc: (theme: Theme) => string }