UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

40 lines (39 loc) 2.47 kB
import type { MentionDefinition } from '@atlaskit/adf-schema/mention'; import type { MentionNodeDataCallback, MentionNodeDataIdentifier, MentionNodeDataProvider as MentionNodeDataProviderContract } from '@atlaskit/editor-common/mention'; import type { JSONNode } from '@atlaskit/editor-json-transformer/types'; import type { MentionNodeData } from '@atlaskit/mention/types'; import { NodeDataProvider } from '@atlaskit/node-data-provider/node-data-provider'; export type FetchMentionNodeData = (accountIds: string[]) => Promise<Record<string, MentionNodeData>>; export type ResolveMentionNodeData = (mention: MentionNodeDataIdentifier) => MentionNodeData | undefined; /** * Page-scoped data provider for mention avatars. * * Products inject their resolution strategy so this package remains independent * of Jira and Confluence APIs. Reuse the instance for the lifetime of a renderer * or editor rather than creating one for every mention. * * Deterministic products can supply `resolveMentionNodeData` to return an * SSR-safe avatar URL synchronously. It must return the same value on the server * and the client's first render to preserve hydration parity. * * Network-backed products supply `fetchMentionNodeData`. Calls made in the same * microtask are combined and account IDs are deduplicated before the fetcher is * invoked. A Relay adapter can query `users(accountIds:)`, then map each user's * `picture` and app type to a `MentionNodeData` record keyed by account ID. The * resolved result is cached by the underlying `NodeDataProvider`. */ export declare class MentionNodeDataProvider extends NodeDataProvider<MentionDefinition, MentionNodeData> implements MentionNodeDataProviderContract { private readonly fetchMentionNodeData; private readonly resolveMentionNodeData; readonly name = "mentionNodeDataProvider"; private queuedFetches; private isFlushScheduled; constructor(fetchMentionNodeData: FetchMentionNodeData, resolveMentionNodeData?: ResolveMentionNodeData | undefined); isNodeSupported(node: JSONNode): node is MentionDefinition; nodeDataKey(node: MentionDefinition): string; fetchNodesData(nodes: MentionDefinition[]): Promise<MentionNodeData[]>; getMentionData(mention: MentionNodeDataIdentifier, callback: MentionNodeDataCallback): void; getMentionDataFromCache(mention: MentionNodeDataIdentifier): MentionNodeData | undefined; private enqueueFetch; private flushFetches; }