Address Greptile review on UI polish PR

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
dotta 2026-03-23 17:16:10 -05:00
parent c3f4e18a5e
commit 6960ab1106
3 changed files with 51 additions and 19 deletions

View file

@ -26,22 +26,52 @@ import {
thematicBreakPlugin,
type RealmPlugin,
} from "@mdxeditor/editor";
import { LinkNode } from "@lexical/link";
import { LinkNode, type LinkAttributes } from "@lexical/link";
import { buildAgentMentionHref, buildProjectMentionHref } from "@paperclipai/shared";
import { AgentIcon } from "./AgentIconPicker";
import { applyMentionChipDecoration, clearMentionChipDecoration, parseMentionChipHref } from "../lib/mention-chips";
import { mentionDeletionPlugin } from "../lib/mention-deletion";
import { cn } from "../lib/utils";
/* ---- Allow custom mention URL schemes in Lexical's LinkNode ---- */
// Lexical only allows http(s)/mailto/sms/tel by default, converting
// everything else to about:blank. We need agent:// and project://
// to survive the markdown→Lexical import so mention chips render.
const _origSanitizeUrl = LinkNode.prototype.sanitizeUrl;
LinkNode.prototype.sanitizeUrl = function sanitizeUrl(url: string): string {
if (/^(agent|project):\/\//.test(url)) return url;
return _origSanitizeUrl.call(this, url);
};
const CUSTOM_MENTION_URL_RE = /^(agent|project):\/\//;
class MentionAwareLinkNode extends LinkNode {
static clone(node: MentionAwareLinkNode): MentionAwareLinkNode {
return new MentionAwareLinkNode(
node.getURL(),
{
rel: node.getRel(),
target: node.getTarget(),
title: node.getTitle(),
},
node.getKey(),
);
}
constructor(url?: string, attributes?: LinkAttributes, key?: string) {
super(url, attributes, key);
}
sanitizeUrl(url: string): string {
if (CUSTOM_MENTION_URL_RE.test(url)) return url;
return super.sanitizeUrl(url);
}
}
const mentionAwareLinkNodeReplacement = {
replace: LinkNode,
with: (node: LinkNode) =>
new MentionAwareLinkNode(
node.getURL(),
{
rel: node.getRel(),
target: node.getTarget(),
title: node.getTitle(),
},
node.getKey(),
),
withKlass: MentionAwareLinkNode,
} as const;
/* ---- Mention types ---- */
@ -560,6 +590,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
"paperclip-mdxeditor-content focus:outline-none [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:list-item",
contentClassName,
)}
additionalLexicalNodes={[mentionAwareLinkNodeReplacement]}
plugins={plugins}
/>