@mtg-rio/mui-mentions
Version:
@mention people in a MUI TextField
111 lines (110 loc) • 6.99 kB
TypeScript
import { BaseSuggestionData, MentionData, SuggestionData, SuggestionDataSource, SuggestionsMap } from '../types';
/**
* Checks whether the given value is a number.
* @param val The value to check
* @returns True if val is a number;
*/
export declare function isNumber(val: any): val is number;
/**
* Searches the provided value for the mentions markup in the provided config and passes each found mention
* to the provided processor functions.
* @param value The value to search for the mentions markup.
* @param dataSources An array of all DataSources used in the markup.
* @param markupProcessor A callback function that processes each mention markup instance.
* @param plainTextProcessor A callback function that processes each plain text instance.
*/
export declare function iterateMentionsMarkup<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[], markupProcessor: (match: string, matchIndex: number, plainTextIndex: number, id: string, display: string, mentionIndex: number, start: number) => void, plainTextProcessor?: (value: string, start: number, currentIndex: number) => void, multiline?: boolean): void;
/**
* Converts the given value to plain text.
* @param value The value which possibly contains mention markup.
* @param dataSources An array of all DataSources used in the markup.
* @param multiline Whether the value is being converted in a multiline textfield.
* @returns value with mention markup converted to plain text.
*/
export declare function getPlainText<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[], multiline?: boolean): string;
/**
* Applies changes from the given plain text value to the given markup value, guided
* by the selected text ranges before and after the change.
* @param value The current markup string.
* @param plainTextValue The new plain text string.
* @param selectionStartBefore The start of the selected text range before the change.
* @param selectionEndBefore The end of the selected text range before the change.
* @param selectionEndAfter The end of the selected text range after the change.
* @param dataSources An array of DataSources used in the markup string.
* @param multiline Whether the value is for a multiline text field.
*/
export declare function applyChangeToValue<T extends BaseSuggestionData>(value: string, plainTextValue: string, selectionStartBefore: number | null, selectionEndBefore: number | null, selectionEndAfter: number, dataSources: SuggestionDataSource<T>[], multiline?: boolean): string;
/**
* Converts a plain text character index to the corresponding index in the markup value string.
* @param value The markup value string.
* @param dataSources An array of all DataSources used in the markup string.
* @param indexInPlainText The index in the plain text string.
* @param inMarkupCorrection The behavior if the corresponding index is inside a mention.
* START returns the index of the mention markup's first character (default).
* END returns the index after the mention markup's last character.
* NULL returns null.
* @returns The index in the markup string.
*/
export declare function mapPlainTextIndex<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[], indexInPlainText: number, inMarkupCorrection?: 'START' | 'END' | 'NULL'): number | null | undefined;
/**
* Replaces the characters in str from start to end with insert.
* @param str The string to edit.
* @param start The starting position to splice (inclusive).
* @param end The ending position to splice (exclusive).
* @param insert The string to insert at the start position.
* @returns The edited string.
*/
export declare function spliceString(str: string, start: number, end: number, insert: string): string;
/**
* Converts the index of a mention in plain text to the index of the first character
* of the mention in the plain text. If the given index is not inside a mention, undefined is
* returned.
* @param value The markup value string.
* @param dataSources An array of DataSources used in the markup string.
* @param indexInPlainText The index of the mention in plain text.
* @returns The start of the index in the plain text.
*/
export declare function findStartOfMentionInPlainText<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[], indexInPlainText: number): number | undefined;
/**
* Parses a list of mentions from the given markup string.
* @param value The markup string value to parse.
* @param dataSources An array of SuggestionDataSources used in the markup string.
* @returns An array of MentionDatas parsed from the given markup string.
*/
export declare function getMentions<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[]): MentionData[];
/**
* Returns the number of individual SuggestionData objects in the provided suggestions map.
* @param suggestions The suggestions map to count.
* @returns The number of SuggestionData objects in suggestions.
*/
export declare function countSuggestions<T extends BaseSuggestionData>(suggestions: SuggestionsMap<T>): any;
/**
* Returns the index of the end of the last mention in the given markup string.
* @param value The markup string to search for mentions.
* @param dataSources An array of SuggestionDataSources used in the markup string.
* @returns The index of the end of the last mention, or 0 if there are no mentions.
*/
export declare function getEndOfLastMention<T extends BaseSuggestionData>(value: string, dataSources: SuggestionDataSource<T>[]): number;
/**
* Converts the given trigger to regex.
* @param trigger The trigger to use for mentions.
* @param allowSpaceInQuery Whether to allow a space in the query.
* @returns A regex version of trigger.
*/
export declare function makeTriggerRegex(trigger: string | RegExp, allowSpaceInQuery?: boolean): RegExp;
/**
* Returns a data provider for the given data.
* @param data An array of SuggestionData objects, or an asychronous function that returns an array of SuggestionData objects.
* @param ignoreAccents Whether to ignore accents while comparing the data with the query.
* @param customFilter Optional custom filter function to use instead of the default substring search.
* @returns A function which returns an array of SuggestionData objects based on a query string.
*/
export declare function getDataProvider<T extends BaseSuggestionData>(data: SuggestionData<T>[] | ((query: string) => Promise<SuggestionData<T>[]>), ignoreAccents?: boolean, customFilter?: (suggestion: SuggestionData<T>, query: string) => boolean): (query: string) => Promise<SuggestionData<T>[]>;
/**
*
* @param markup The markup format to use.
* @param id The id of the mention.
* @param display The display string of the mention.
* @returns The markup string for the mention.
*/
export declare const makeMentionsMarkup: (markup: string, id: string, display?: string) => string;