@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
107 lines (106 loc) • 3.42 kB
TypeScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
/**
* @hidden
* Represents a node in the undo-redo linked list.
*/
export interface UndoRedoNode<T> {
/** The state data stored in the node */
state: T;
/** Reference to the previous node (the previous state) */
previous: UndoRedoNode<T> | null;
/** Reference to the next node (the next state) */
next: UndoRedoNode<T> | null;
/** Optional identifier for the node */
id?: string | number;
}
/**
* @hidden
* A linked-list based implementation of an undo-redo stack.
* Maintains a chain of states that can be navigated forward and backward.
*/
export declare class UndoRedoStack<T> {
private maxSize;
/** The current active node in the undo-redo history */
private currentNode;
/** The root node of the stack (first state) */
private rootNode;
/** Track the size of the stack */
private _size;
/**
* Creates a new UndoRedoStack.
* @param maxSize Optional maximum number of states to maintain (unlimited if not provided)
*/
constructor(maxSize?: number);
/**
* Gets the current number of states in the stack
*/
get size(): number;
/**
* Gets the current active state
*/
get current(): T | null;
/**
* Checks if undo is available (if there's a previous state)
*/
get canUndo(): boolean;
/**
* Checks if redo is available (if there's a next state)
*/
get canRedo(): boolean;
/**
* Adds a new state to the undo-redo stack
* @param state The state to add
* @param id Optional identifier for the state
* @returns The newly created node
*/
add(state: T, id?: string | number): UndoRedoNode<T>;
/**
* Finds a node by its identifier
* @param id The identifier to search for
* @returns The found node or null if not found
*/
find(id: string | number): UndoRedoNode<T> | null;
/**
* Removes a node by its identifier
* @param id The identifier of the node to remove
* @returns True if the node was found and removed, false otherwise
*/
remove(id: string | number): boolean;
/**
* Performs an undo operation, moving to the previous state
* @returns The previous state or null if can't undo
*/
undo(): T | null;
peekNext(): T | null;
peekPrev(): T | null;
/**
* Performs a redo operation, moving to the next state
* @returns The next state or null if can't redo
*/
redo(): T | null;
/**
* Clears all history
*/
clear(): void;
/**
* Removes all states after the specified node
* @param node The node to truncate from
* @returns The number of nodes removed
*/
private truncateForward;
/**
* Ensures the stack doesn't exceed the maximum size by removing oldest nodes
*/
private enforceMaxSize;
/**
* Gets all states in the stack as an array (from oldest to newest)
*/
toArray(): T[];
/**
* Gets the history nodes as an array (useful for debugging)
*/
getNodes(): UndoRedoNode<T>[];
}