mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 18:10:39 +09:00
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:
parent
49ace2faf9
commit
0e8e162cd5
3 changed files with 19 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue