Files
PaperClipAI/ui/src/lib/mention-aware-link-node.ts
T
DottaandPaperclip 2c43b39167 refactor(ui): share task composer and project/worktree controls (#15091)
Use the shared composer for new tasks, including project and worktree selection, rich mentions and slash commands, and remembered task settings.

Save project preferences after successful task updates. Show known agent models by name and use Default for unknown runtime defaults.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-05 18:06:40 -05:00

68 lines
1.7 KiB
TypeScript

import {
LinkNode,
type LinkAttributes,
type SerializedLinkNode,
} from "@lexical/link";
const CUSTOM_MENTION_URL_RE = /^(agent|project|user|skill|routine):\/\//;
export class MentionAwareLinkNode extends LinkNode {
static getType(): string {
return "mention-aware-link";
}
static clone(node: MentionAwareLinkNode): MentionAwareLinkNode {
return new MentionAwareLinkNode(
node.getURL(),
{
rel: node.getRel(),
target: node.getTarget(),
title: node.getTitle(),
},
node.getKey(),
);
}
static importJSON(serializedNode: SerializedLinkNode): MentionAwareLinkNode {
return new MentionAwareLinkNode(
serializedNode.url ?? "",
{
rel: serializedNode.rel ?? null,
target: serializedNode.target ?? null,
title: serializedNode.title ?? null,
},
);
}
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);
}
}
type MentionAwareLinkSource = Pick<LinkNode, "getURL" | "getRel" | "getTarget" | "getTitle">;
export function getMentionAwareLinkNodeInit(node: MentionAwareLinkSource) {
return {
url: node.getURL(),
attributes: {
rel: node.getRel(),
target: node.getTarget(),
title: node.getTitle(),
},
};
}
export const mentionAwareLinkNodeReplacement = {
replace: LinkNode,
with: (node: LinkNode) => {
const { url, attributes } = getMentionAwareLinkNodeInit(node);
return new MentionAwareLinkNode(url, attributes);
},
withKlass: MentionAwareLinkNode,
} as const;