UNPKG

@znuny/ckeditor5-autocomplete-plugin

Version:

A plugin for CKEditor 5 that provides an extendable autocomplete functionality with predefined mention and HTML replacement logic.

87 lines (86 loc) 3.94 kB
/** * @copyright Copyright (c) 2024, Znuny GmbH. * @copyright Copyright (c) 2003-2024, CKSource Holding sp. z o.o. * * @license GNU GPL version 3 * * This software comes with ABSOLUTELY NO WARRANTY. For details, see * the enclosed file COPYING for license information (GPL). If you * did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. */ import { type Editor } from 'ckeditor5/src/core.js'; import type { CompletionElementAttribute } from './Interfaces/CompletionElement'; import type { CompletionModelAttribute } from './Interfaces/CompletionModelAttribute'; export declare class EditorPreparation { static readonly identifyingMentionAttributeName = "data-mention"; static mentionCompletionElementTagName: string; /** * Prepare the editors model conversion manager to be able to process our custom data- html attributes. * See https://ckeditor.com/docs/ckeditor5/latest/framework/deep-dive/conversion/upcast.html * @param editor */ static makeItMentionable: (editor: Editor, mentionCompletionElementTagName: string | undefined) => void; /** * Checks whether a given html element tag name is valid. * @param tagName */ private static isValidHtmlElementTagName; /** * Merges the baseMentionData with data (if set) and adds a unique mention element id, required by CKEditor. * @param baseMentionData * @param data * @returns */ static mergeMentionObjects(baseMentionData: { name: string; content: string; attributes?: Array<CompletionElementAttribute>; }, data?: Record<string, unknown>): CompletionModelAttribute; /** * Creates mention model data from a mention view element. */ private static toMentionAttribute; /** * Creates a mention view element from mention model data. */ private static createViewMentionElement; /** * A converter that blocks partial mention from being converted. * * This converter is registered with 'highest' priority in order to consume mention attribute before it is converted by any other converters. * This converter only consumes partial mention - those whose `content` attribute is not equal to content with mention attribute. * This may happen when copying part of mention text. */ private static preventPartialMentionDowncast; /** * This post-fixer will extend the attribute applied on the part of the mention so the whole text node of the mention will have the added attribute. */ private static extendAttributeOnMentionPostFixer; /** * Checks if a node has a correct mention attribute if present. * Returns `true` if the node is text and has a mention attribute whose text does not match the expected mention text. */ private static isBrokenMentionNode; /** * Model post-fixer that removes the mention attribute from the modified text node. */ private static removePartialMentionPostFixer; /** * Fixes a mention on a text node if it needs a fix, while fix means here removing the mention html representation from the (possibly incomplete) view text. */ private static checkAndFix; /** * Model post-fixer that disallows typing with selection when the selection is placed after the text node with the mention attribute or * before a text node with mention attribute. */ private static selectionMentionAttributePostFixer; /** * Helper function to detect if mention attribute should be removed from selection. * This check makes only sense if the selection has mention attribute. * * The mention attribute should be removed from a selection when selection focus is placed: * a) after a text node * b) the position is at parents start - the selection will set attributes from node after. */ private static shouldNotTypeWithMentionAt; }