Skip to content

Commit

Permalink
fix(lexical-editor): relax file to node conversion checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jul 17, 2024
1 parent 238b222 commit 8347c16
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions packages/lexical-editor/src/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 8347c16

Please sign in to comment.