Skip to content

Commit

Permalink
[RTE]: fixed bug when files added from attachment button inserted in …
Browse files Browse the repository at this point in the history
…preview mode instead of attachment block
  • Loading branch information
AlekseyManetov committed Dec 2, 2024
1 parent 0be8b6c commit ccc9033
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [Modals]: prevent scrolling to the modal toggler because of focus return after modal close
* [RTE]: fixed scroll to the top of the editor after editor modal windows(Add image/link/video etc.) were close
* [RTE]: fixed error while merging cells without content
* [RTE]: fixed bug when files added from attachment button inserted in preview mode instead of attachment block

# 5.11.0 - 15.11.2024

Expand Down
18 changes: 11 additions & 7 deletions uui-editor/src/plugins/uploadFilePlugin/file_uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,25 @@ const isValidFileType = (fileType?: string) => {

const buildFragments = (
files: FileUploadResponse[],
blockType?: UploadType,
) => {
return files.map((file: FileUploadResponse) => {
const fileType = file.type;
const uploadType = (
isValidFileType(fileType) ? fileType : ATTACHMENT_TYPE
) as UploadType;
if (blockType) {
return UPLOAD_BLOCKS[blockType](file);
} else {
const blockTypeByFile = (isValidFileType(fileType) ? fileType : ATTACHMENT_TYPE) as UploadType;

return UPLOAD_BLOCKS[uploadType](file);
return UPLOAD_BLOCKS[blockTypeByFile](file);
}
});
};

export const createFileUploader = (options?: UploadFileOptions) =>
async (
editor: PlateEditor,
files: File[],
blockType: UploadType,
) => {
const uploadFile = options?.uploadFile;
if (!uploadFile) return;
Expand Down Expand Up @@ -127,7 +131,7 @@ export const createFileUploader = (options?: UploadFileOptions) =>
}

// build fragments
const fileFragments = buildFragments(res);
const fileFragments = buildFragments(res, blockType);

// remove loader
removeLoader();
Expand All @@ -138,14 +142,14 @@ export const createFileUploader = (options?: UploadFileOptions) =>

export const useFilesUploader = (editor: PlateEditor) => {
return useCallback(
(files: File[], overriddenAction?: UploadType): Promise<void> => {
(files: File[], blockType?: UploadType): Promise<void> => {
const callback = getPlugin<FileUploaderOptions>(editor, UPLOAD_PLUGIN_KEY)?.options.uploadFiles;

if (callback) {
return callback(
editor,
files,
overriddenAction,
blockType,
);
}

Expand Down

0 comments on commit ccc9033

Please sign in to comment.