UNPKG

@znuny/ckeditor5-autocomplete-plugin

Version:

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

77 lines (76 loc) 3.33 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 { Plugin, type Editor } from 'ckeditor5/src/core.js'; import { ContextualBalloon } from 'ckeditor5/src/ui.js'; import './Theme/Mention.css'; export declare class Autocomplete extends Plugin { private readonly config; private readonly selectionUi; /** * @inheritDoc */ static get requires(): readonly [typeof ContextualBalloon]; /** * @inheritDoc */ static get pluginName(): "Autocomplete"; static get pluginMarkerName(): string; static get pluginConfigurationName(): string; /** * @inheritDoc */ constructor(editor: Editor); /** * @inheritDoc */ init(): void; /** * Returns an array with all positions (index) of a given marker within the inputText. * @param inputText contains the content of the current cursor selection (in front of the cursor) * @param marker completion group marker */ private getAllMarkerPositions; /** * Checks whether the given selection (under to current cursor position) is part of an already fully inserted completion (mention) element. * @param data */ private isSelectionAboveFulfilledCompletionReplacement; private applyMatchingCompletionsToSelectionUi; /** * Adds the given completion elements to the selection ui (dropdown). * To show elements out of different groups, just call this multiple times with different (group specific) parameters. * @param completionGroup completion group from which the provided completions originate * @param completions array of completion elements to show in the selection ui (dropdown) */ private addGroupCompletionsToSelectionUi; /** * Creates a callback to test for all groups, if a matching marker is in the current editor line. * @param completionGroups * @returns Whether at least one valid completion marker was found in the current line / or word for any configured completion group */ private createTextWatcherCallback; /** * Tests whether the word at the current cursor position contains a valid autocomplete configured marker (completionGroup.matchingMarker). * Instead of the internal matching logic the external configured completionGroup.markerMatchingCallback(inputText, completionGroup.matchingMarker) will be called if available. * @param inputText contains the content of the current editor line in front of the current cursor position * @param completionGroup * @returns Whether a valid completion marker was found in the current line / or word for the given completion group */ private testMarkerMatchingForCompletionGroup; /** * Returns a predefined completion matching hander callback to check whether a inputText matches for a specific completion element or not. * @param strategy * @param isCaseSensitive * @returns */ private getMatchingHandlerByStrategy; private processCSSOverwrite; }