@atlaskit/mention
Version:
A React component used to display user profiles in a list for 'Mention' functionality
106 lines (105 loc) • 5.36 kB
TypeScript
import { type AnalyticsCallback, type ErrorCallback, type InfoCallback, type InviteFlow, type MentionContextIdentifier, type MentionDescription, type MentionNameDetails, type MentionProvider, type MentionResourceConfig, type MentionsResult, type MentionStats, type ResourceProvider, type ResultCallback, type UserRole } from '../types';
export type { MentionStats, ResultCallback, ErrorCallback, InfoCallback, MentionResourceConfig, ResourceProvider, MentionContextIdentifier, MentionProvider, } from '../types';
/**
* Configuration for the TeamMentionResource, which extends {@link MentionResourceConfig}
* to support fetching team mentions from a separate team search service endpoint.
*
* Used as the second argument when constructing a {@link TeamMentionResource}, alongside
* a standard `MentionResourceConfig` for user mentions.
*/
export interface TeamMentionResourceConfig extends MentionResourceConfig {
/**
* A custom resolver function to generate the URL for a team's profile page.
* If not provided, a default link of `{window.location.origin}/people/team/{teamId}` is used.
*
* @param teamId - The ID of the team (with any ARI prefix already trimmed).
* @returns The full URL to the team's profile page.
*/
teamLinkResolver?: (teamId: string) => string;
}
/**
* Support
*/
export interface ResolvingMentionProvider extends MentionProvider {
cacheMentionName(id: string, mentionName: string): void;
resolveMentionName(id: string): Promise<MentionNameDetails> | MentionNameDetails;
supportsMentionNameResolving(): boolean;
}
declare class AbstractResource<Result> implements ResourceProvider<Result> {
protected changeListeners: Map<string, ResultCallback<Result>>;
protected errListeners: Map<string, ErrorCallback>;
protected infoListeners: Map<string, InfoCallback>;
protected allResultsListeners: Map<string, ResultCallback<Result>>;
protected analyticsListeners: Map<string, AnalyticsCallback>;
constructor();
subscribe(key: string, callback?: ResultCallback<Result>, errCallback?: ErrorCallback, infoCallback?: InfoCallback, allResultsCallback?: ResultCallback<Result>, analyticsListeners?: AnalyticsCallback): void;
unsubscribe(key: string): void;
}
declare class AbstractMentionResource extends AbstractResource<MentionDescription[]> implements MentionProvider {
shouldHighlightMention(_mention: MentionDescription): boolean;
filter(query?: string): void;
recordMentionSelection(_mention: MentionDescription): void;
isFiltering(_query: string): boolean;
protected _notifyListeners(mentionsResult: MentionsResult, stats?: MentionStats): void;
protected _notifyAllResultsListeners(mentionsResult: MentionsResult): void;
protected _notifyErrorListeners(error: Error, query?: string): void;
protected _notifyInfoListeners(info: string): void;
protected _notifyAnalyticsListeners(event: string, actionSubject: string, action: string, attributes?: {
[key: string]: any;
}): void;
}
/**
* Provides a Javascript API
*/
export declare class MentionResource extends AbstractMentionResource implements ResolvingMentionProvider {
private config;
private lastReturnedSearch;
private activeSearches;
productName?: string;
shouldEnableInvite: boolean;
userRole: UserRole;
onInviteItemClick?: (flow: InviteFlow) => void;
inviteXProductUser?: (userId: string, mentionName: string) => Promise<void>;
constructor(config: MentionResourceConfig);
shouldHighlightMention(mention: MentionDescription): boolean;
notify(searchTime: number, mentionResult: MentionsResult, query?: string): void;
notifyError(error: Error, query?: string): void;
filter(query?: string, contextIdentifier?: MentionContextIdentifier): Promise<void>;
isFiltering(query: string): boolean;
resolveMentionName(id: string): Promise<MentionNameDetails> | MentionNameDetails;
cacheMentionName(id: string, mentionName: string): void;
supportsMentionNameResolving(): boolean;
protected updateActiveSearches(query: string): void;
protected verifyMentionConfig(config: MentionResourceConfig): void;
private initialState;
/**
* Clear a context object to generate query params by removing empty
* strings, `undefined` and empty values.
*
* @param contextIdentifier the current context identifier
* @returns a safe context for query encoding
*/
private clearContext;
private getQueryParams;
/**
* Returns the initial mention display list before a search is performed for the specified
* container.
*
* @param contextIdentifier
* @returns Promise
*/
protected remoteInitialState(contextIdentifier?: MentionContextIdentifier): Promise<MentionsResult>;
private search;
protected remoteSearch(query: string, contextIdentifier?: MentionContextIdentifier): Promise<MentionsResult>;
private transformServiceResponse;
}
export declare class HttpError implements Error {
name: string;
message: string;
statusCode: number;
stack?: string;
constructor(statusCode: number, statusMessage: string);
}
export declare const isResolvingMentionProvider: (p: any) => p is ResolvingMentionProvider;
export { AbstractResource, AbstractMentionResource };
export default MentionResource;