@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
100 lines (99 loc) • 3.54 kB
TypeScript
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
/**
* @module ai/aicore/aiediting
*/
import { type ModelRange, type ModelDocumentFragment } from '@ckeditor/ckeditor5-engine';
import { ContextPlugin, type Context, Editor } from '@ckeditor/ckeditor5-core';
export declare const AI_VISUAL_SELECTION_MARKER_NAME = "ai-selection";
export declare class AIEditing extends ContextPlugin {
/**
* @inheritDoc
*/
constructor(context: Context | Editor);
/**
* @inheritDoc
*/
static get pluginName(): "AIEditing";
/**
* @inheritDoc
*/
static get isOfficialPlugin(): true;
/**
* @inheritDoc
*/
static get isPremiumPlugin(): true;
/**
* Gets the current session ID. If RTC plugin is available, uses its sessionId.
* Otherwise, generates a random ID for the current (non-RTC) session.
*/
get sessionId(): string;
/**
* Returns the data and version of each document (one entry per editor root, excluding `$graveyard`).
*
* `rootName` and `channelId` identify the source of each entry so callers can remap AI modifications back to the editor and root
* they came from.
*/
getDocumentData(): Promise<Array<AIEditingDocumentData>>;
afterInit(): Promise<void>;
/**
* Displays a fake visual selection on given ranges.
*
* Since multiple features may want to show and hide the selection, while at the same time, only one fake selection should be shown,
* it is necessary to provide an `id` when showing fake selection. Then, when the fake selection should be hidden, `id` must be
* passed as well. This mechanism prevents a feature from mistakenly hiding a fake selection set by another feature.
*/
showFakeVisualSelection(fakeSelectionData: FakeSelectionData): void;
/**
* Removes a fake visual selection from the document.
*
* @param id ID of the fake visual selection to remove.
*/
hideFakeVisualSelection(id: string): void;
modelToDataWithIds(modelFragment: ModelDocumentFragment): Promise<string>;
}
/**
* A single document entry returned by {@link module:ai/aicore/aiediting~AIEditing#getDocumentData `AIEditing#getDocumentData()`}. One
* entry per editor model root (excluding `$graveyard`); `editor` + `rootName` identify the source root so callers can route AI
* modifications back to the correct place.
*/
export type AIEditingDocumentData = {
editor: Editor;
rootName: string;
content: string;
version: number;
sessionId: string;
channelId: string;
selections: Array<{
markerName: string;
start: number;
end: number;
htmlFragment: string;
}>;
name?: string;
description?: string;
};
type FakeSelectionData = {
/**
* Ranges on which fake selection should be shown.
*/
ranges: Array<ModelRange>;
/**
* Fake selection ID.
*
* Used when removing fake selection.
*
* Used as a part of CSS class set on fake selection DOM elements (`ck-fake-ai-selection-${ id }`).
*/
id: string;
/**
* Fake selection priority.
*
* There can be only one fake selection displayed at once. Priority is used to inform which fake selection should be displayed when
* multiple features asked to show fake selection on different ranges.
*/
priority: number;
};
export {};