/** * Mentions in a draft: finding the one being typed, putting a chosen one in, and * turning the names back into tokens when the draft is sent. * * The draft is plain text, so a mention is carried as `@Full Name` while it is being * written and only becomes a `${mention|type:id}` token on the way out. The names the * reader picked are remembered so that the same text typed by hand, or a name that * two members share, does not turn into a mention of someone they never chose. */ import type { CommentAuthorType, SiteMembers } from '@pantheon-systems/css-client'; export interface MentionCandidate { type: CommentAuthorType; id: string; name: string; role: string; avatar: string | null; } /** Where in the draft the mention being typed sits, and what has been typed so far. */ export interface MentionQuery { /** Index of the `@`. */ start: number; /** Just past the last character of the query. */ end: number; query: string; } /** Agents first, then people; someone with no name to show is left out. */ export declare function mentionCandidates(roster: SiteMembers): MentionCandidate[]; export declare function filterMentionCandidates(candidates: readonly MentionCandidate[], query: string): MentionCandidate[]; /** * The mention being typed at the caret, if there is one: an `@` that starts a word, * with no whitespace between it and the caret. `@` followed by a space is a plain * at-sign, and so is one in the middle of an email address. */ export declare function mentionQueryAt(text: string, caret: number): MentionQuery | null; /** Puts the chosen name where the query was, followed by a space so typing carries on. */ export declare function insertMention(text: string, at: MentionQuery, candidate: MentionCandidate): { text: string; caret: number; }; /** * Replaces each chosen name still present in the draft with its token. Longer names go * first so "@Marco Reyes" is never read as "@Marco" plus " Reyes". */ export declare function serializeMentions(text: string, chosen: readonly MentionCandidate[]): string;