import { IconFile, IconFolder } from "@tabler/icons-react"; import { mergeAttributes, Node } from "@tiptap/core"; import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"; const FileReferenceComponent = ({ node }: { node: any }) => { const isFolder = node.attrs.path?.endsWith("/"); const cleanPath = isFolder ? node.attrs.path.slice(0, -1) : node.attrs.path; const displayName = cleanPath.split("/").pop() || cleanPath; return ( {isFolder ? ( ) : ( )} {displayName} ); }; export const FileReference = Node.create({ name: "fileReference", group: "inline", inline: true, selectable: true, atom: true, addAttributes() { return { path: { default: null }, source: { default: "codebase" }, }; }, parseHTML() { return [{ tag: 'span[data-type="file-reference"]' }]; }, renderHTML({ HTMLAttributes }) { return [ "span", mergeAttributes({ "data-type": "file-reference" }, HTMLAttributes), ]; }, addNodeView() { return ReactNodeViewRenderer(FileReferenceComponent); }, });