forked from farhoodlabs/paperclip
Fix mention pills by allowing custom URL schemes in Lexical LinkNode
The previous fix (validateUrl on linkPlugin) only affected the link dialog, not the markdown-to-Lexical import path. Lexical's LinkNode.sanitizeUrl() converts agent:// and project:// URLs to about:blank because they aren't in its allowlist. Override the prototype method to preserve these schemes so mention chips render correctly. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -26,11 +26,22 @@ import {
|
||||
thematicBreakPlugin,
|
||||
type RealmPlugin,
|
||||
} from "@mdxeditor/editor";
|
||||
import { LinkNode } from "@lexical/link";
|
||||
import { buildAgentMentionHref, buildProjectMentionHref } from "@paperclipai/shared";
|
||||
import { AgentIcon } from "./AgentIconPicker";
|
||||
import { applyMentionChipDecoration, clearMentionChipDecoration, parseMentionChipHref } from "../lib/mention-chips";
|
||||
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);
|
||||
};
|
||||
|
||||
/* ---- Mention types ---- */
|
||||
|
||||
export interface MentionOption {
|
||||
|
||||
Reference in New Issue
Block a user