Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MenuButtonImageUpload should call insertImages prop #188

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with a similar use-case here:

colorToHex = colorToHexDefault,

how about:

Suggested change
insertImages,
insertImages = insertImagesDefault,

(importing with insertImages as insertImagesDefault instead of insertImages as fallbackInsertImages).

And then no need to update any of the code below (no conditional needed)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...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