@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
62 lines (61 loc) • 2.17 kB
TypeScript
import { DropdownMenuItemType } from '@lobehub/ui';
import Fuse, { type IFuseOptions } from 'fuse.js';
import type { IEditor, IEditorKernel, IServiceID } from "../../../types";
import { getBasicTypeaheadTriggerMatch } from '../utils/utils';
export type ISlashDividerOption = {
type: 'divider';
};
export interface ISlashMenuOption extends DropdownMenuItemType {
metadata?: Record<string, any>;
onSelect?: (editor: IEditor, matchingString: string) => void;
}
export type ISlashOption = ISlashMenuOption | ISlashDividerOption;
export interface SlashOptions {
allowWhitespace?: boolean;
/**
* Complete Fuse.js configuration options
* @example
* {
* keys: ['key', 'label', 'description'],
* threshold: 0.3,
* includeScore: true,
* includeMatches: true
* }
*/
fuseOptions?: IFuseOptions<ISlashMenuOption>;
items: Array<ISlashOption> | ((search: {
leadOffset: number;
matchingString: string;
replaceableString: string;
} | null) => Promise<Array<ISlashOption>>);
maxLength?: number;
minLength?: number;
punctuation?: string;
/**
* Fuse.js search keys for fuzzy matching
* Default is ['key']
* @example ['key', 'label', 'description']
* @deprecated Use fuseOptions instead
*/
searchKeys?: string[];
trigger: string;
}
export interface ISlashService {
registerSlash(options: SlashOptions): void;
updateOptions(options: SlashOptions[]): void;
}
export declare const ISlashService: IServiceID<ISlashService>;
export declare class SlashService implements ISlashService {
private kernel;
private triggerMap;
private triggerFnMap;
private triggerFuseMap;
private logger;
constructor(kernel: IEditorKernel);
registerSlash(options: SlashOptions, update?: boolean): void;
removeAllOptions(): void;
updateOptions(options: SlashOptions[]): void;
getSlashOptions(trigger: string): SlashOptions | undefined;
getSlashTriggerFn(trigger: string): ReturnType<typeof getBasicTypeaheadTriggerMatch> | undefined;
getSlashFuse(trigger: string): Fuse<ISlashOption> | undefined;
}