import { createReactInlineContentSpec } from "@blocknote/react";
import { CheckIcon, XIcon } from "lucide-react";
import { Button } from "../../shadcnui";
import { cn } from "../../utils";
// Word-level diff with accept/reject functionality
export const diffWordInlineContentSpec = createReactInlineContentSpec(
{
type: "diffWord",
propSchema: {
text: {
default: "",
},
diffType: {
default: "unchanged",
},
diffId: {
default: "",
},
accepted: {
default: false,
},
rejected: {
default: false,
},
onAccept: {
default: "",
type: "string" as const,
},
onReject: {
default: "",
type: "string" as const,
},
},
content: "none",
},
{
render: (props) => {
const { text, diffType, diffId, accepted, rejected, onAccept, onReject } = props.inlineContent as any;
const handleAccept =
typeof onAccept === "function" ? onAccept : (window as any).blockNoteDiffHandlers?.handleAcceptChange;
const handleReject =
typeof onReject === "function" ? onReject : (window as any).blockNoteDiffHandlers?.handleRejectChange;
if (diffType === "unchanged") {
return {text};
}
// Handle button-only diffType for rendering accept/reject buttons
if (diffType === "buttons") {
const diffIdList = diffId.split(",");
return (
);
}
const isAddition = diffType === "added";
const isRemoval = diffType === "removed";
return (
{text}
{!accepted && !rejected && (diffType === "added" || diffType === "removed") && (
)}
);
},
},
);
export const diffInlineContentSpecs = {
diffWord: diffWordInlineContentSpec,
};