@atlaskit/editor-plugin-type-ahead
Version:
Type-ahead plugin for @atlaskit/editor-core
100 lines (99 loc) • 3.82 kB
TypeScript
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import type { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
import type { TypeAheadHandler, TypeAheadItem, TypeAheadStats, UiComponentFactoryParams } from '@atlaskit/editor-common/types';
import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
export type { TypeAheadHandler } from '@atlaskit/editor-common/types';
import type { CloseSelectionOptions } from '../pm-plugins/constants';
export type TypeAheadError = 'FETCH_ERROR';
export type TypeAheadErrorInfo = {
error: TypeAheadError;
} | null;
export type OnSelectItem = (props: {
index: number;
item: TypeAheadItem;
}) => void;
export interface TypeAheadStatsSerializable extends TypeAheadStats {
serialize: () => TypeAheadStats;
}
export interface TypeAheadStatsModifier extends TypeAheadStatsSerializable {
increaseArrowDown: () => void;
increaseArrowUp: () => void;
}
export interface TypeAheadStatsMobileModifier extends TypeAheadStatsSerializable {
closeTime: () => void;
resetTime: () => void;
}
export type TypeAheadPluginState = {
decorationElement: HTMLElement | null;
decorationSet: DecorationSet;
errorInfo: TypeAheadErrorInfo;
inputMethod: TypeAheadInputMethod | null;
items: Array<TypeAheadItem>;
query: string;
/**
* If true, removes the trigger character from query when typeahead is closed
*/
removePrefixTriggerOnCancel?: boolean;
selectedIndex: number;
stats: TypeAheadStatsSerializable | null;
triggerHandler?: TypeAheadHandler;
typeAheadHandlers: Array<TypeAheadHandler>;
};
export type OnInsertSelectedItemProps = {
index: number;
mode: SelectItemMode;
query: string;
};
export type OnItemMatchProps = {
mode: SelectItemMode;
query: string;
};
export type OnInsertSelectedItem = (props: OnInsertSelectedItemProps) => void;
export type OnItemMatch = (props: OnItemMatchProps) => boolean;
export type OnTextInsertProps = {
forceFocusOnEditor: boolean;
setSelectionAt: CloseSelectionOptions;
text: string;
};
export type OnTextInsert = (props: OnTextInsertProps) => void;
export type InsertionTransactionMeta = (editorState: EditorState) => Transaction | false;
type PopupMountPoints = Pick<UiComponentFactoryParams, 'popupsMountPoint' | 'popupsBoundariesElement' | 'popupsScrollableElement'>;
export type PopupMountPointReference = Record<'current', PopupMountPoints | null>;
export type CreateTypeAheadDecorations = (tr: ReadonlyTransaction, options: {
inputMethod: TypeAheadInputMethod;
reopenQuery?: string;
triggerHandler: TypeAheadHandler;
}) => {
decorationElement: HTMLElement | null;
decorationSet: DecorationSet;
stats: TypeAheadStatsSerializable | null;
};
export type RemoveTypeAheadDecorations = (decorationSet?: DecorationSet) => boolean;
export type TypeAheadInputMethod = INPUT_METHOD.INSERT_MENU | INPUT_METHOD.KEYBOARD | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR
/**
* For Typeahead - Empty line prompt experiment
* Clean up ticket ED-24824
*/
| 'blockControl';
export type TypeAheadPluginOptions = {
isMobile?: boolean;
};
export interface TypeAheadPluginSharedState {
currentHandler?: TypeAheadHandler;
decorationElement: HTMLElement | null;
decorationSet: DecorationSet;
errorInfo: TypeAheadErrorInfo;
isAllowed: boolean;
isOpen: boolean;
items: Array<TypeAheadItem>;
query: string;
selectedIndex: number;
triggerHandler?: TypeAheadHandler;
}
export type OpenTypeAheadProps = {
inputMethod: TypeAheadInputMethod;
query?: string;
removePrefixTriggerOnCancel?: boolean;
triggerHandler: TypeAheadHandler;
};