From 692b16f99e4101e23c769ec61a0f93e4daa10d0d Mon Sep 17 00:00:00 2001 From: Loren Riesenfeld Date: Mon, 8 Jan 2024 14:40:42 -0500 Subject: [PATCH] fix: MenuButtonImageUpload should call insertImages prop --- src/controls/MenuButtonImageUpload.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/controls/MenuButtonImageUpload.tsx b/src/controls/MenuButtonImageUpload.tsx index 4f4d345..951891e 100644 --- a/src/controls/MenuButtonImageUpload.tsx +++ b/src/controls/MenuButtonImageUpload.tsx @@ -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"; @@ -52,6 +55,7 @@ export interface MenuButtonImageUploadProps export default function MenuButtonImageUpload({ onUploadFiles, inputProps, + insertImages, ...props }: MenuButtonImageUploadProps) { const editor = useRichTextEditorContext(); @@ -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 (