import type { IActionDispatcher, IActionHandler, ICommand, ModelRendererFactory } from "sprotty"; import { AbstractUIExtension } from "sprotty"; import type { Action } from "sprotty-protocol"; import type { VNode } from "snabbdom"; import { CanvasElement, Root } from "@hylimo/diagram-common"; import type { ConfigManager } from "../config/configManager.js"; import MiniSearch from "minisearch"; import type { ConnectionEditProvider } from "./connectionEditProvider.js"; import { ToolboxToolType } from "./toolType.js"; import { ToolState } from "./toolState.js"; import type { SettingsProvider } from "../settings/settingsProvider.js"; import type { TransactionIdProvider } from "../transaction/transactionIdProvider.js"; import type { ErrorState } from "../diagram-state/diagramStateProvider.js"; /** * UI Extension which displays the graphical toolbox. * Supports * - creating elements by dragging them from the toolbox or clicking them * - searching for elements * - showing previews for elements * - selecting the connection operator used for creating connections */ export declare class Toolbox extends AbstractUIExtension implements IActionHandler, ConnectionEditProvider { readonly configManager: ConfigManager; /** * The unique identifier of the toolbox. */ static readonly ID = "toolbox"; /** * If available, the current snabbdom root. */ private currentVNode?; /** * The current root element. */ currentRoot?: Root; /** * If true, pointer events are disabled */ pointerEventsDisabled: boolean; /** * If true, the toolbox is open. */ isOpen: boolean; /** * The edit for which to show a preview. * If undefined, no preview is shown. */ showPreviewFor?: string; /** * The search string. * If set to a non-empty string, the search is active. */ searchString: string; /** * The search string for the connection select. */ connectionSearchString?: string; /** * The selected connection. */ selectedConnection?: string; /** * The error state if the diagram is not in a valid state. */ errorState?: ErrorState; /** * The search index. */ private searchIndex?; /** * The connection search index. */ private connectionSearchIndex?; /** * Cached toolbox edits */ private toolboxEdits?; /** * Cached connection edits */ private connectionEdits?; /** * Cached rendered element previews. */ elementPreviews: Map; /** * The model renderer. */ private readonly renderer; /** * The ids of the currently selected elements. */ private readonly selectedElements; /** * The index of elements, used to quickly access elements by id. */ private index; /** * The patcher provider. */ private readonly patcherProvider; /** * The action dispatcher. */ readonly actionDispatcher: IActionDispatcher; /** * The model factory, used to render previews. */ private readonly modelFactory; /** * The tool state. */ toolState: ToolState; /** * The settings provider */ readonly settingsProvider: SettingsProvider; /** * The transaction id provider */ transactionIdProvider: TransactionIdProvider; /** * Creates a new toolbox. * * @param configManager The config manager * @param modelRendererFactory The model renderer factory, used to obtain the model renderer */ constructor(configManager: ConfigManager, modelRendererFactory: ModelRendererFactory); handle(action: Action): ICommand | Action | void; /** * Updates the error state of the toolbox. * * @param errorState The new error state */ private updateErrorState; /** * Clears all cached data */ private resetCache; /** * Handles UpdateModelAction and SetModelAction to update the toolbox state when the model changes. * This method: * * @param action The UpdateModelAction or SetModelAction containing the new model root * @returns returns early if the new root is not of type Root.TYPE */ private handleUpdateModelAction; /** * Handles a transactional action * Activates pointer events again if action is committed, and resets the tool if necessary. * * @param action the transactional action */ private handleTransactionalAction; /** * Handles a Select(All)Action and resets the cache if necessary. * * @param action The Select(All)Action to handle */ private handleSelectAction; /** * Initializes the toolbox. */ private initializeToolbox; /** * Updates the toolbox by re-rendering it. */ update(): void; id(): string; containerClass(): string; protected initializeContents(containerElement: HTMLElement): void; /** * Toggles the toolbox. */ toggleToolbox(): void; /** * Sets the currently used tool * * @param tool the new tool * @param locked if the tool should be locked */ updateTool(tool: ToolboxToolType, locked: boolean): void; /** * The current connection edit or undefined if no connection edit is available */ get connectionEdit(): `connection/${string}` | undefined; /** * Gets the current connection operator * Uses {@link selectedConnection} if it is set and in the list of available connections * * @param connections the list of available connection operators * @returns the current connection operator or unefined if no connection operator is available */ getCurrentConnection(connections: ConnectionEditEntry[]): string | undefined; /** * Extracts the toolbox edits from the root element. * * @returns The toolbox edits */ getToolboxEdits(): ToolboxEditEntry[]; /** * Extracts template information from the given node recursively. * Updates the provided info object with the extracted information. * * @param node The node to extract information from * @param info The info object to update */ private extractTemplateInformationRecursive; /** * Extracts the connection edits from the root element. * * @param root The root element * @returns The connection edits */ getConnectionEdits(): ConnectionEditEntry[]; /** * Shows a preview for a toolbox edit. * If no preview is available, a prediction is requested. * * @param edit The toolbox edit to show a preview for * @param targetId The id of the element to edit */ showPreview(edit: ToolboxEditEntry | ConnectionEditEntry): void; /** * Creates a prediction edit for a toolbox/connection edit entry. * * @param edit The toolbox edit to generate a prediction for * @returns The prediction edit */ private generatePredictionEdit; /** * Requests a prediction for a toolbox edit. * * @param edit The toolbox edit to request a prediction for * @param key The key under which the prediction is stored */ private requestPrediction; /** * Returns the search index. * If the search index is not yet available, it is created. * * @returns The search index */ getSearchIndex(): MiniSearch; /** * Returns the connection search index. * If the connection search index is not yet available, it is created. * * @returns The connection search index */ getConnectionSearchIndex(): MiniSearch; /** * Gets the index of all elements in the current root. * The index is a map that allows quick lookup of elements by their ID. * If the index doesn't exist yet, it will be built by traversing the entire element tree. * * @returns A map containing all elements indexed by their ID, or an empty map if no root exists */ private getIndex; /** * Recursively builds the element index by traversing the element tree. * This method adds the current element to the index and then recursively * processes all of its children. * * @param element The element to add to the index and whose children to process recursively */ private buildIndexRecursive; /** * Checks if a toolbox tool is currently enabled. * * @param tool The toolbox tool * @returns True if the tool is enabled, false otherwise */ isToolEnabled(tool: ToolboxToolType): boolean; /** * Checks if the toolbox is in selected element mode. * This is true if exactly one element is selected. */ get selectedElementMode(): boolean; /** * Checks if the diagram is in a valid state (no errors). */ get isValid(): boolean; } /** * A toolbox edit entry */ export interface ToolboxEditEntry { /** * The group of the toolbox item */ group: string; /** * The name of the toolbox item */ name: string; /** * The full key of the edit */ edit: `toolbox/${string}`; /** * The id & optional edit expression of the target element */ target: Pick; /** * If true, dragging this item is allowed */ canMove: boolean; /** * If true, the item requires an expression for the element to be set */ requiresExpression: boolean; } /** * A connection edit entry */ export interface ConnectionEditEntry { /** * The name of the connection operator */ name: string; /** * The full key of the edit */ edit: `connection/${string}`; } //# sourceMappingURL=toolbox.d.ts.map