UNPKG

@chayns-components/emoji-input

Version:
40 lines (39 loc) 2.61 kB
import { type ReplaceTextOptions as IReplaceTextOptions } from './selection'; interface InsertTextAtCursorPositionOptions { editorElement: HTMLDivElement; text: string; shouldUseSavedSelection?: boolean; } /** * This function inserts the passed text at the correct position in the editor element. If the * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji * will be appended to the back of the input field content. * * In addition, this function also sets the cursor to the correct position when the input field * has the focus. For this purpose, the current position of the cursor or a selection is read to * calculate the cursor position after inserting the text. * * @param {Object} options - Object with element and text to insert * @param {HTMLDivElement} options.editorElement - Element to insert text into * @param {string} options.text - Text to insert into element */ export declare const insertTextAtCursorPosition: ({ editorElement, text, shouldUseSavedSelection, }: InsertTextAtCursorPositionOptions) => void; export interface ReplaceTextOptions { editorElement: HTMLDivElement; searchText: string; pasteText: string; options?: IReplaceTextOptions; } export declare const replaceText: ({ editorElement, searchText, pasteText, options, }: ReplaceTextOptions) => void; interface RevertAsciiSmileyConversionOptions { editorElement: HTMLDivElement; /** The original ASCII smiley to restore (e.g. ":-)"). */ original: string; /** The Unicode emoji that is currently in the DOM and should be replaced. */ emoji: string; /** * Whether to also remove the single character immediately following the * emoji (typically the trigger whitespace / punctuation that caused the * conversion). Defaults to `true` to mirror common autocorrect UX * (Word, IntelliJ, ...). */ shouldRemoveTriggerChar?: boolean; } /** * Reverts the most recent ASCII-smiley-to-emoji conversion at the cursor * position. * * The emoji (and optionally the trigger character following it) is removed * and replaced by a `<span class="no-emoji-convert">{original}</span>` block. * The cursor is moved to the end of the inserted span. The span is then * protected against re-conversion by the existing `regAscii` rule that skips * the contents of any `<span>` element. * * @returns `true` if a revert was performed, `false` otherwise. */ export declare const revertAsciiSmileyConversion: ({ editorElement, original, emoji, shouldRemoveTriggerChar, }: RevertAsciiSmileyConversionOptions) => boolean; export {};