/** * @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/toolkit/proposedchangescontrollertype * @publicApi */ import { type Emitter } from "@ckeditor/ckeditor5-utils"; import { type ProposedChangesCollection } from "./proposedchangescollection.js"; import { type AISuggestionContainerView } from "../aicore/ui/suggestioncontainer/aisuggestioncontainerview.js"; /** * Binds together a {@link module:ai/toolkit/proposedchangescollection~ProposedChangesCollection set of proposed changes} with related * editor instances and (optionally) with the view component. * * When an `AISuggestionContainerView` is {@link #attachView attached}, the controller will provide all necessary data to render and * update the view according to the proposed changes set. It will also fully integrate with the editor instance to handle all user * interaction coming from the view. * * The controller also provides methods for handling the proposed document changes: {@link #applyChange}, * {@link #applyAllChanges}, {@link #rejectChange}, {@link #previewChange}, {@link #highlightChange}. * * One controller instance handles all changes from the proposed changes set, even when they are related to multiple editor instances. */ export interface ProposedChangesController extends Emitter { /** * The set of proposed changes under review. */ readonly collection: ProposedChangesCollection; /** * Binds the given view with the controller, so the view shows the changes and its actions decide on them. */ attachView(view: AISuggestionContainerView): void; /** * Unbinds the attached view, leaving the changes as they are. */ detachView(): void; /** * Whether the attached view shows each change as a diff, or as the proposed content alone. */ setShowDiff(showDiff: boolean): void; /** * Applies the change at `index` to the related document, directly or as track-changes suggestions. */ applyChange(index: number, asSuggestions: boolean): void; /** * Applies every change that can still be applied, one undo step per document. */ applyAllChanges(asSuggestions: boolean): void; /** * Rejects the change at `index`, leaving the document as it is. */ rejectChange(index: number): void; /** * Scrolls the content the change at `index` covers into view. */ scrollToChange(index: number): void; /** * Highlights the content the change at `index` covers. */ highlightChange(index: number): void; /** * Removes the highlight set by {@link #highlightChange}. */ hideHighlight(): void; /** * Opens the preview of the change at `index` in the document. */ previewChange(index: number): void; /** * Stops tracking the documents and releases everything the controller holds. */ destroy(): void; } /** * The options of {@link ~ProposedChangesController}. */ export interface ProposedChangesControllerOptions { /** * Whether proposed changes are previewed in the document, in the balloon of the editor the change belongs to. Applies both to * the previews opened from the attached view and to {@link ~ProposedChangesController#previewChange}. * * Requires the editor to load the `AIChatBalloon` plugin. * * @default false */ hasPreview?: boolean; /** * How long, in milliseconds, the preview waits after the user applies, suggests or rejects a change in the attached view or * in the preview balloon before it moves on to the next change. The decided change shows its new state in the meantime. * Set it to `0` to move on right away. * * Applies only when {@link #hasPreview `hasPreview`} is on. Calling the controller methods, for example * {@link ~ProposedChangesController#applyChange}, never waits. * * @default 600 */ autoAdvanceDelay?: number; }