1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-02 03:25:53 +01:00

fix: make getEmbedLink independent of t function (#7643)

* fix: make getEmbedLink independent of t function

* rename warning to error and make it type safe
This commit is contained in:
Aakansha Doshi 2024-02-01 21:12:10 +05:30 committed by GitHub
parent 0e0f34edd8
commit 0c3dffb082
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 9 deletions

@ -6501,8 +6501,11 @@ class App extends React.Component<AppProps, AppState> {
return; return;
} }
if (embedLink.warning) { if (embedLink.error instanceof URIError) {
this.setToast({ message: embedLink.warning, closable: true }); this.setToast({
message: t("toast.unrecognizedLinkFormat"),
closable: true,
});
} }
const element = newEmbeddableElement({ const element = newEmbeddableElement({

@ -120,8 +120,11 @@ export const Hyperlink = ({
} else { } else {
const { width, height } = element; const { width, height } = element;
const embedLink = getEmbedLink(link); const embedLink = getEmbedLink(link);
if (embedLink?.warning) { if (embedLink?.error instanceof URIError) {
setToast({ message: embedLink.warning, closable: true }); setToast({
message: t("toast.unrecognizedLinkFormat"),
closable: true,
});
} }
const ar = embedLink const ar = embedLink
? embedLink.intrinsicSize.w / embedLink.intrinsicSize.h ? embedLink.intrinsicSize.w / embedLink.intrinsicSize.h

@ -1,6 +1,5 @@
import { register } from "../actions/register"; import { register } from "../actions/register";
import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants"; import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants";
import { t } from "../i18n";
import { ExcalidrawProps } from "../types"; import { ExcalidrawProps } from "../types";
import { getFontString, updateActiveTool } from "../utils"; import { getFontString, updateActiveTool } from "../utils";
import { setCursorForShape } from "../cursor"; import { setCursorForShape } from "../cursor";
@ -107,8 +106,8 @@ export const getEmbedLink = (
const vimeoLink = link.match(RE_VIMEO); const vimeoLink = link.match(RE_VIMEO);
if (vimeoLink?.[1]) { if (vimeoLink?.[1]) {
const target = vimeoLink?.[1]; const target = vimeoLink?.[1];
const warning = !/^\d+$/.test(target) const error = !/^\d+$/.test(target)
? t("toast.unrecognizedLinkFormat") ? new URIError("Invalid embed link format")
: undefined; : undefined;
type = "video"; type = "video";
link = `https://player.vimeo.com/video/${target}?api=1`; link = `https://player.vimeo.com/video/${target}?api=1`;
@ -120,7 +119,7 @@ export const getEmbedLink = (
intrinsicSize: aspectRatio, intrinsicSize: aspectRatio,
type, type,
}); });
return { link, intrinsicSize: aspectRatio, type, warning }; return { link, intrinsicSize: aspectRatio, type, error };
} }
const figmaLink = link.match(RE_FIGMA); const figmaLink = link.match(RE_FIGMA);

@ -104,7 +104,7 @@ export type ExcalidrawIframeLikeElement =
export type IframeData = export type IframeData =
| { | {
intrinsicSize: { w: number; h: number }; intrinsicSize: { w: number; h: number };
warning?: string; error?: Error;
} & ( } & (
| { type: "video" | "generic"; link: string } | { type: "video" | "generic"; link: string }
| { type: "document"; srcdoc: (theme: Theme) => string } | { type: "document"; srcdoc: (theme: Theme) => string }