@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
109 lines (108 loc) • 4.35 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/aichat/ui/controls/resources/aichatresourcesballoonview
*/
import { type Locale } from '@ckeditor/ckeditor5-utils';
import { type BodyCollection } from '@ckeditor/ckeditor5-ui';
import { type AIContextProvider, type AIContextResourceState } from '../../../../aichat/model/aichatcontext.js';
/**
* Configuration interface for the AI chat resources balloon view.
*/
export interface AIChatResourcesBalloonViewConfig {
/**
* Callback fired when user requests to go back to the main context view.
*/
onBackToContext: () => void;
/**
* Callback fired when a resource is selected to be added to context.
*/
onResourceSelected: (source: AIContextProvider, resource: AIContextResourceState) => void;
/**
* Callback fired when source resources need to be loaded.
*/
onLoadSourceResources: (data: {
sourceId: string;
query: string;
uid: string;
}) => void;
/**
* Callback fired when the balloon is closed via click outside.
*/
onBalloonClosed: () => void;
/**
* Returns the element that limits balloon positioning.
*/
getLimiterElement: () => HTMLElement;
/**
* Returns the target element for balloon positioning.
*/
getTargetElement: () => HTMLElement;
/**
* The minimum number of resources to show the search input.
*/
searchInputVisibleFrom?: number;
}
/**
* Manages resource balloon panels for AI chat context sources.
*
* This class handles the creation, positioning, and lifecycle of balloon panels
* that display resources from various AI context providers. Each source can have
* its own balloon panel with search functionality and resource listing.
*/
export declare class AIChatResourcesBalloonView {
/**
* Creates a new AI chat resources balloon view manager.
*
* @param locale The locale instance for internationalization
* @param bodyCollection The body collection for managing balloon DOM lifecycle
* @param config Configuration object for balloon behavior and event handling
*/
constructor(locale: Locale, bodyCollection: BodyCollection, config: AIChatResourcesBalloonViewConfig);
/**
* Shows a source resources balloon for the given source provider.
* Creates a new balloon if one doesn't exist for this source, otherwise reuses the existing one.
*/
showSourceResourcesBalloon({ source, withBackButton }: {
source: AIContextProvider;
withBackButton: boolean;
}): void;
/**
* Populates a source resource balloon with loaded resources.
* Only updates the balloon if it exists and is currently active.
*
* @param sourceId The unique identifier of the source
* @param resources Array of resource states to display
* @param uid Unique identifier for the resource loading request
*/
populateSourceResourceBalloon(sourceId: string, resources: Array<AIContextResourceState>, uid: string): void;
/**
* Closes the source resource balloon and cleans up its state.
* Uses requestAnimationFrame to ensure proper cleanup timing.
*
* @param sourceId The unique identifier of the source balloon to close
*/
closeSourceResourceBalloon(sourceId: string): void;
/**
* Checks if any resource balloon is currently visible.
*
* @returns True if at least one resource balloon is visible, false otherwise
*/
isAnyResourceBalloonVisible(): boolean;
/**
* Updates the state of a specific resource in the balloon and repositions it.
* This method also handles balloon repositioning to ensure proper display.
*
* @param sourceId The unique identifier of the source
* @param resourceId The unique identifier of the resource to update
* @param isInContext Whether the resource is currently in the context
*/
updateResourceState(sourceId: string, resourceId: string, isInContext: boolean): void;
/**
* Destroys all resource balloons and cleans up resources.
* Should be called when the view is no longer needed to prevent memory leaks.
*/
destroy(): void;
}