"use client"; import { mergeAttributes, Node } from "@tiptap/core"; import { NodeViewWrapper, ReactNodeViewRenderer, type ReactNodeViewProps } from "@tiptap/react"; import { IconHash } from "@tabler/icons-react"; import { t } from "@/lib/i18n"; export const EntityReferenceNode = Node.create({ name: "entityReference", group: "inline", inline: true, selectable: false, atom: true, addAttributes() { return { version: { default: 1 }, ref: { default: null }, provider: { default: null }, kind: { default: null }, id: { default: null }, key: { default: null }, title: { default: null }, url: { default: null }, scope: { default: null }, }; }, parseHTML() { return [{ tag: "span[data-entity-reference]" }]; }, renderHTML({ HTMLAttributes }) { return [ "span", mergeAttributes({ "data-entity-reference": "" }, HTMLAttributes), HTMLAttributes.key || HTMLAttributes.title || HTMLAttributes.id || "", ]; }, renderText({ node }) { return `#${node.attrs.key ?? node.attrs.title ?? node.attrs.id ?? ""}`; }, addNodeView() { return ReactNodeViewRenderer(EntityReferenceChipView); }, }); function EntityReferenceChipView({ node }: ReactNodeViewProps) { const { key, title, provider, kind, id } = node.attrs as { key?: string | null; title?: string | null; provider?: string | null; kind?: string | null; id?: string | null; }; const label = key || title || id || t("common:reference"); const source = [provider, kind].filter(Boolean).join(" "); const description = source ? `${source}: ${title || label}` : title || label; return ( ); }