From 2a9170f7dd0f41072b9f6a52aa170f0ea31cc284 Mon Sep 17 00:00:00 2001 From: codex-bot Date: Fri, 24 Oct 2025 16:53:36 -0300 Subject: [PATCH] Make ticket mention extension override link parsing --- src/components/ui/rich-text-editor.tsx | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/ui/rich-text-editor.tsx b/src/components/ui/rich-text-editor.tsx index b276386..4145db1 100644 --- a/src/components/ui/rich-text-editor.tsx +++ b/src/components/ui/rich-text-editor.tsx @@ -14,6 +14,7 @@ import type { Editor } from "@tiptap/react" import StarterKit from "@tiptap/starter-kit" import Placeholder from "@tiptap/extension-placeholder" import Mention from "@tiptap/extension-mention" +import TiptapLink from "@tiptap/extension-link" import { ReactRenderer } from "@tiptap/react" import tippy, { type Instance, type Props as TippyProps } from "tippy.js" // Nota: o CSS do Tippy não é obrigatório, mas melhora muito a renderização @@ -455,8 +456,16 @@ const TicketMentionListComponent = (props: TicketMentionSuggestionProps) => ( ) +const SafeLinkExtension = TiptapLink.extend({ + priority: 90, + parseHTML() { + return [{ tag: 'a[href]:not([data-ticket-mention="true"])' }] + }, +}) + const TicketMentionExtension = Mention.extend({ name: "ticketMention", + priority: 1000, group: "inline", inline: true, draggable: false, @@ -515,6 +524,7 @@ const TicketMentionExtension = Mention.extend({ return [ { tag: `a[data-ticket-mention="true"]`, + priority: 1000, getAttrs: (dom: HTMLElement | string) => { if (dom instanceof HTMLElement) { return { @@ -531,6 +541,7 @@ const TicketMentionExtension = Mention.extend({ }, { tag: "a.ticket-mention", + priority: 1000, getAttrs: (dom: HTMLElement | string) => { if (dom instanceof HTMLElement) { const href = dom.getAttribute("href") ?? null @@ -765,21 +776,24 @@ export function RichTextEditor({ }, [ticketMention?.enabled, value]) const extensions = useMemo(() => { - const baseExtensions = [ + const mentionExtensions = ticketMention?.enabled ? [TicketMentionExtension] : [] + + const coreExtensions = [ StarterKit.configure({ bulletList: { keepMarks: true }, orderedList: { keepMarks: true }, - // Configure built-in link from StarterKit to avoid duplicate extension - link: { - openOnClick: true, - autolink: true, - protocols: ["http", "https", "mailto"], - HTMLAttributes: { rel: "noopener noreferrer", target: "_blank" }, - }, + link: false, + }), + SafeLinkExtension.configure({ + openOnClick: true, + autolink: true, + protocols: ["http", "https", "mailto"], + HTMLAttributes: { rel: "noopener noreferrer", target: "_blank" }, }), Placeholder.configure({ placeholder }), ] - return ticketMention?.enabled ? [...baseExtensions, TicketMentionExtension] : baseExtensions + + return [...mentionExtensions, ...coreExtensions] }, [placeholder, ticketMention?.enabled]) const editor = useEditor({