fix: fixed multi time file opener

This commit is contained in:
Palanikannan M
2024-09-13 21:09:08 +05:30
parent 2e1745e905
commit fa5cfd5fc3
3 changed files with 8 additions and 15 deletions

View File

@@ -72,8 +72,12 @@ export const CustomImageNode = (props: CustomImageNodeViewProps) => {
if (uploadEntity.event === "drop" && "file" in uploadEntity) {
uploadFile(uploadEntity.file);
} else if (uploadEntity.event === "insert" && fileInputRef.current && !hasTriggeredFilePickerRef.current) {
const entity = editorStorage?.fileMap.get(id);
if (entity && entity.hasOpenedFileInputOnce) return;
fileInputRef.current.click();
hasTriggeredFilePickerRef.current = true;
if (!entity) return;
editorStorage?.fileMap.set(id, { ...entity, hasOpenedFileInputOnce: true });
}
}
}, [getUploadEntity, uploadFile]);

View File

@@ -22,7 +22,7 @@ export interface UploadImageExtensionStorage {
fileMap: Map<string, UploadEntity>;
}
export type UploadEntity = { event: "insert" } | { event: "drop"; file: File };
export type UploadEntity = ({ event: "insert" } | { event: "drop"; file: File }) & { hasOpenedFileInputOnce: boolean };
export const CustomImageExtension = (props: TFileHandler) => {
const { upload } = props;
@@ -46,12 +46,6 @@ export const CustomImageExtension = (props: TFileHandler) => {
height: {
default: "auto",
},
["data-type"]: {
default: this.name,
},
["data-file"]: {
default: null,
},
["id"]: {
default: null,
},
@@ -63,6 +57,9 @@ export const CustomImageExtension = (props: TFileHandler) => {
{
tag: "image-component",
},
{
tag: "img",
},
];
},
@@ -101,9 +98,7 @@ export const CustomImageExtension = (props: TFileHandler) => {
}
const attributes = {
"data-type": this.name,
id: fileId,
"data-file": props.file ? `data-file="${props.file}"` : "",
};
if (props.pos) {

View File

@@ -24,12 +24,6 @@ export const CustomReadOnlyImageExtension = () =>
height: {
default: "auto",
},
["data-type"]: {
default: this.name,
},
["data-file"]: {
default: null,
},
["id"]: {
default: null,
},