From 8347c16fdfe4bd8bcc1f36c7d3bf2eeedfdd04df Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Wed, 17 Jul 2024 11:58:20 +0200 Subject: [PATCH] fix(lexical-editor): relax file to node conversion checks --- packages/lexical-editor/src/utils/files.ts | 41 ++++++---------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/packages/lexical-editor/src/utils/files.ts b/packages/lexical-editor/src/utils/files.ts index 90b5d4a56b6..ae43c477186 100644 --- a/packages/lexical-editor/src/utils/files.ts +++ b/packages/lexical-editor/src/utils/files.ts @@ -11,43 +11,24 @@ export interface FileManagerFileItemMetaItem { value: any; } -export const isImageType = (file: FileManagerFileItem): boolean => { - if (!file?.meta) { - return false; - } - - for (const metaItem of file.meta) { - if (metaItem.key === "type") { - return metaItem.value.includes("image/"); - } - } - - return false; -}; - -export const fileToImagePayload = (file: FileManagerFileItem): ImagePayload | null => { - if (!file?.meta) { - return null; - } - - if (!isImageType(file)) { - return null; - } - + export const fileToImagePayload = (file: FileManagerFileItem): ImagePayload | null => { const imagePayload = {} as ImagePayload; imagePayload["id"] = file.id; imagePayload["src"] = file.src; imagePayload["showCaption"] = true; imagePayload["captionsEnabled"] = true; - for (const metaValue of file.meta) { - if (metaValue.key === "name") { - imagePayload["altText"] = metaValue.value; - } else if (metaValue.key === "width") { - imagePayload["width"] = metaValue.value; - } else if (metaValue.key === "height") { - imagePayload["height"] = metaValue.value; + if (file?.meta) { + for (const metaValue of file.meta) { + if (metaValue.key === "name") { + imagePayload["altText"] = metaValue.value; + } else if (metaValue.key === "width") { + imagePayload["width"] = metaValue.value; + } else if (metaValue.key === "height") { + imagePayload["height"] = metaValue.value; + } } } + return imagePayload; };