Skip to content

Commit

Permalink
fix: MenuButtonImageUpload should call insertImages prop
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenries committed Jan 8, 2024
1 parent 0ad9992 commit 692b16f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/controls/MenuButtonImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Editor } from "@tiptap/core";
import { useRef, type ComponentPropsWithoutRef } from "react";
import type { SetOptional } from "type-fest";
import { useRichTextEditorContext } from "../context";
import { insertImages, type ImageNodeAttributes } from "../utils";
import {
insertImages as fallbackInsertImages,
type ImageNodeAttributes,
} from "../utils";
import MenuButtonAddImage, {
type MenuButtonAddImageProps,
} from "./MenuButtonAddImage";
Expand Down Expand Up @@ -52,6 +55,7 @@ export interface MenuButtonImageUploadProps
export default function MenuButtonImageUpload({
onUploadFiles,
inputProps,
insertImages,
...props
}: MenuButtonImageUploadProps) {
const editor = useRichTextEditorContext();
Expand All @@ -63,10 +67,14 @@ export default function MenuButtonImageUpload({
return;
}
const attributesForImages = await onUploadFiles(Array.from(files));
insertImages({
editor,
images: attributesForImages,
});
if (typeof insertImages === "function") {
insertImages({ editor, images: attributesForImages });
} else {
fallbackInsertImages({
editor,
images: attributesForImages,
});
}
};

return (
Expand Down

0 comments on commit 692b16f

Please sign in to comment.