import { MentionsTargetElement } from "@cometchat/uikit-resources"; import { CometChatTextFormatter } from "../CometChatTextFormatter"; import { MentionsVisibility } from "@cometchat/uikit-resources"; import { UserMentionStyle } from "./UserMentionStyle"; export { UserMentionStyle }; /** * Class that handles the text formatting for mentions in CometChat. * CometChatMentionsFormatter is a child class of CometChatTextFormatter. * It extends the functionality of text formatting to specifically handle user mentions * in the text, it keeps track of the mentions in the text, format them for display and * other functionalities. * * @extends {CometChatTextFormatter} */ export declare class CometChatMentionsFormatter extends CometChatTextFormatter { /** * List of users for mentions. */ private cometChatUserGroupMembers; /** * Mapping of CSS classes for mentions. */ private mentionsCssClassMapping?; /** * Specifies the visibility of mentions. */ private visibleIn; /** * Regular expression for validating search input. * * The search input is considered valid if it meets all of the following conditions: * - It starts with an "@" symbol. * - After the "@" symbol, it can optionally contain alphanumeric characters or periods. * - If there are spaces, they should not be immediately after the "@" symbol. * - After a space, it can optionally contain alphanumeric characters or periods. * * If the search input does not meet these conditions, the regular expression match will fail, indicating invalid input. * * @type {RegExp} * @private */ private invalidCharactersRegexForSearch; /** * Count of mentions in the text. */ private mentionsCount; /** * Map of mentions, linking user ids with their names. */ private mentionsMap?; /** * Stores the formatting style for mentions. */ private mentionsStyle; private composerMentionStyle; private conversationMentionStyle; private leftBubbleMentionStyle; private rightBubbleMentionStyle; /** * Observer for observing changes to the text. */ observer: MutationObserver; /** * Callback function for when a match is found by the regex used for search. */ keyUpCallBack: any; private warningDisplayed; private allowMultipleSpaces; private mouseOverEventDispatched; constructor(); /** * Observes changes in targetNode. * * @param {HTMLElement} targetNode - The HTML element to observe for changes. */ observeChange(targetNode: any): void; /** * Retrieves the count of mentions. * * @returns {number} - The count of mentions. */ getMentionsCount(): number; /** * Sets the count of mentions. * * @param {number} mentionsCount - The count of mentions to be set. */ setMentionsCount(mentionsCount: number): void; /** * Set Regex for Checking Invalid Characters in Search Term * @param pattern */ setInvalidCharactersRegexForSearch(pattern: RegExp): void; /** * Sets the current caret position and selection range. * * @param {Selection} currentCaretPosition - The current caret position. * @param {Range} currentRange - The current selection range. */ setCaretPositionAndRange(currentCaretPosition: Selection, currentRange: Range): void; /** * Sets the reference to the input element. * * @param {HTMLElement} inputElementReference - The reference to the input element. */ setInputElementReference(inputElementReference: HTMLElement): void; /** * Sets the regex pattern for matching text. * * @param {Array} regexPatterns - The array of regex patterns. */ setRegexPattern(regexPatterns: Array): void; /** * Retrieves the CometChatUserGroupMembers. * * @returns {Array} - The current CometChatUserGroupMembers. */ getCometChatUserGroupMembers(): (import("@cometchat/chat-sdk-javascript").User | import("@cometchat/chat-sdk-javascript").GroupMember)[]; /** * Sets the CometChatUserGroupMembers. * * @param {Array} CometChatUserGroupMembers - The CometChatUserGroupMembers to be set. */ setCometChatUserGroupMembers(CometChatUserGroupMembers: Array): void; resetCometChatUserGroupMembers(): void; /** * Sets the callback function for handling key down events. * * @param {Function} keyUpCallBack - The callback function for handling key up events. */ setKeyUpCallBack(keyUpCallBack: Function): void; /** * Sets the keydown callback function. * @param {Function} keyDownCallBack - The keydown callback function. */ setKeyDownCallBack(keyDownCallBack: Function): void; /** * Retrieves the mentions style. * * @returns {UserMentionStyle} - The current mentions style. */ getTextStyle(): UserMentionStyle; /** * * @param {UserMentionStyle} mentionsStyle - The mentions style to be set. */ setMentionsTextStyle(mentionsStyle: UserMentionStyle): void; /** * Sets the mentions style for conversation. * * @param {UserMentionStyle} mentionsStyle - The mentions style to be set. */ setConversationMentionStyle(mentionsStyle: UserMentionStyle): void; /** * Sets the mentions style for composer. * * @param {UserMentionStyle} mentionsStyle - The mentions style to be set. */ setComposerMentionStyle(mentionsStyle: UserMentionStyle): void; /** * Sets the mentions style for left bubble. * * @param {UserMentionStyle} mentionsStyle - The mentions style to be set. */ setLeftBubbleMentionStyle(mentionsStyle: UserMentionStyle): void; /** * Sets the mentions style for right bubble. * * @param {UserMentionStyle} mentionsStyle - The mentions style to be set. */ setRightBubbleMentionStyle(mentionsStyle: UserMentionStyle): void; getAllowMultipleSpaces(): boolean; setAllowMultipleSpaces(allowMultipleSpaces: boolean): void; cleanup(): void; /** * This will be called by composer before sending the message. This can be used to set metadata, tags on message * @param {CometChat.BaseMessage} message * @return {CometChat.BaseMessage} - message with metadata added */ formatMessageForSending(message: CometChat.BaseMessage): CometChat.BaseMessage; reset(): void; stopTracking(): void; /** * Formats the input text if provided, otherwise edits the text at the cursor position. * @param {string|null} inputText - The input text to be formatted. * @returns {string|void} - The formatted input text, or void if inputText is not provided. */ getFormattedText(inputText: string | null, params?: { mentionsTargetElement: MentionsTargetElement; }): string | void; /** * This function adds the mention span to the input text. * @param {string} inputText - The input text where the span needs to be added. * @returns {string} - The modified input text. */ protected addMentionsSpan(inputText: string): string; /** * Registers event listeners for click, mouseover, mouseout on the element * @param {HTMLElement} element - The element on which the events need to be registered * @param {DOMTokenList} domTokenList - The classes to be added * @return {HTMLElement} - The element with the registered event listeners */ registerEventListeners(element: HTMLElement, domTokenList: DOMTokenList): HTMLElement; /** * Replaces mentions which are span tags with corresponding user UIDs * * @param {string | null | undefined} inputText - The text in which the mentions need to be replaced * @return {string} - The text after replacing the mentions with uids */ protected replaceMentionsSpanWithUid(inputText: string | null | undefined): string; /** * Handles the keydown events, updating the mention state as necessary * * @param {KeyboardEvent} event - The keydown event */ onKeyDown(event: KeyboardEvent): void; /** * Validates the text input based on the invalidCharactersRegexForSearch regular expression. * * @param {string | null} text - The text to validate. If null, the function will return null. * @returns {string | null} - Returns the original text if valid, otherwise returns null. */ validateText(text: string | null): string | null; /** * Handles the keyup events, updating the mention state as necessary * * @param {KeyboardEvent} event - The keydown event */ onKeyUp(event: KeyboardEvent): null | undefined; /** * Adds the given HTML at the caret position. * * @param {string} newHtml - The HTML to be added. * @param {any} currentCaretPosition - The current caret position * @param {any} currentRange - The current range * @returns {any} */ protected addAtCaretPosition(newHtml: string, currentCaretPosition: Selection, currentRange: Range): any; /** * Matches the regex with the given inputText and replaces the matched text with respective spans * * @param {string | null} inputText - The text in which the regex patterns needs to be matched * @return {string} - The text after replacing the matched text with spans */ onRegexMatch(inputText?: string | null): string; /** * Retrieves the original text after replacing mentions span with UIDs * * @param {string | null | undefined} inputText - The input text to be formatted. * @returns {string} The original text after replacing mentions span with UIDs */ getOriginalText(inputText: string | null | undefined): string; setVisibleIn(visibleIn: MentionsVisibility): void; getVisibleIn(): MentionsVisibility; } //# sourceMappingURL=CometChatMentionsFormatter.d.ts.map