# table-commands-generator > Comprehensive table operation command generator library (@aptx/table-commands-generator). Use when working with table operations including: (1) Inserting/deleting rows and columns, (2) Merging/unmerging cells, (3) Implementing custom command interpreters for different frameworks, (4) Managing sparse table data structures, (5) Recording/replaying table command sequences - Author: HaibaraAi - Repository: HaibaraAiAPTX/table-commands-generator-skill - Version: 20260126233902 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/HaibaraAiAPTX/table-commands-generator-skill - Web: https://mule.run/skillshub/@@HaibaraAiAPTX/table-commands-generator-skill~table-commands-generator:20260126233902 --- --- name: table-commands-generator description: "Comprehensive table operation command generator library (@aptx/table-commands-generator). Use when working with table operations including: (1) Inserting/deleting rows and columns, (2) Merging/unmerging cells, (3) Implementing custom command interpreters for different frameworks, (4) Managing sparse table data structures, (5) Recording/replaying table command sequences" --- # Table Commands Generator Skill ## Overview This library provides a table operation command generator that handles various table operations internally and converts them to commands. External adapters can be used to adapt to different frameworks to meet various usage scenarios. ### Features - ✅ Insert rows/columns with automatic merged cell adjustment - ✅ Delete rows/columns with automatic merged cell adjustment - ✅ Merge cells with automatic unmerging of overlapping cells - ✅ Unmerge cells ### Architecture The library follows a three-layer architecture: 1. **Data Layer** (`TableState`, `Cell`, `WorksheetData`) - Core sparse data structure 2. **Command Layer** (`CommandInterpreter`, `BuildinStateInterpreter`, `TableCommand` types) - Command pattern implementation 3. **Transaction Layer** (`TableCommandPlanner`) - High-level operations that generate commands --- ## API Reference ### DataStructure.ts Core data structures for the table system. - [Cell](references/DataStructure/Cell.md) - Cell data interface with merge and placeholder properties - [WorksheetData](references/DataStructure/WorksheetData.md) - Sparse table data structure (Map>) ### TableState.ts Core table state management with sparse storage. - [TableState](references/TableState/constructor.md) - Constructor to create table instances - [TableState.getCell](references/TableState/getCell.md) - Get cell data at specified position - [TableState.updateCell](references/TableState/updateCell.md) - Update cell data with partial updates - [TableState.getRowCount](references/TableState/getRowCount.md) - Get total row count - [TableState.getColCount](references/TableState/getColCount.md) - Get total column count - [TableState.cellIsEmpty](references/TableState/cellIsEmpty.md) - Check if cell is empty - [TableState.getGridData](references/TableState/getGridData.md) - Get rendering data - [RenderingData](references/TableState/RenderingData.md) - Interface for renderable table data ### Commands.ts Command type definitions for table operations. - [StructuralCommand](references/Commands/StructuralCommand.md) - Row/column insert/delete commands - [CellCommand](references/Commands/CellCommand.md) - Cell attribute set/clear commands - [TableCommand](references/Commands/TableCommand.md) - Union type for all commands ### CommandInterpreter.ts Abstract command interpreter base class. - [CommandInterpreter](references/CommandInterpreter/CommandInterpreter.md) - Abstract base class overview - [CommandInterpreter.applyCommands](references/CommandInterpreter/applyCommands.md) - Batch execute commands synchronously - [CommandInterpreter.applyCommandsAsync](references/CommandInterpreter/applyCommandsAsync.md) - Batch execute commands asynchronously - [CommandInterpreter.applyCommand](references/CommandInterpreter/applyCommand.md) - Execute single command - [CommandInterpreter.handleInsertRow](references/CommandInterpreter/handleInsertRow.md) - Abstract: Handle row insertion - [CommandInterpreter.handleInsertCol](references/CommandInterpreter/handleInsertCol.md) - Abstract: Handle column insertion - [CommandInterpreter.handleDeleteRow](references/CommandInterpreter/handleDeleteRow.md) - Abstract: Handle row deletion - [CommandInterpreter.handleDeleteCol](references/CommandInterpreter/handleDeleteCol.md) - Abstract: Handle column deletion - [CommandInterpreter.handleSetCellAttr](references/CommandInterpreter/handleSetCellAttr.md) - Abstract: Handle cell attribute setting - [CommandInterpreter.handleClearCellAttr](references/CommandInterpreter/handleClearCellAttr.md) - Abstract: Handle cell attribute clearing ### BuildinStateInterpreter.ts Built-in interpreter for TableState. - [BuildinStateInterpreter](references/BuildinStateInterpreter/BuildinStateInterpreter.md) - Overview of built-in interpreter - [BuildinStateInterpreter - constructor](references/BuildinStateInterpreter/constructor.md) - Create interpreter instance ### TableCommandPlanner.ts High-level transaction layer for table operations. - [TableCommandPlanner - constructor](references/TableCommandPlanner/constructor.md) - Create planner instance - [TableCommandPlanner.getCommands](references/TableCommandPlanner/getCommands.md) - Get generated commands - [TableCommandPlanner.getNewCommandsAndReset](references/TableCommandPlanner/getNewCommandsAndReset.md) - Get commands and reset cache - [TableCommandPlanner.forEachMainMergedCell](references/TableCommandPlanner/forEachMainMergedCell.md) - Iterate over merged cells - [TableCommandPlanner.insertRow](references/TableCommandPlanner/insertRow.md) - Insert row with merged cell adjustment - [TableCommandPlanner.insertCol](references/TableCommandPlanner/insertCol.md) - Insert column with merged cell adjustment - [TableCommandPlanner.deleteRow](references/TableCommandPlanner/deleteRow.md) - Delete row with merged cell adjustment - [TableCommandPlanner.deleteCol](references/TableCommandPlanner/deleteCol.md) - Delete column with merged cell adjustment - [TableCommandPlanner.merge](references/TableCommandPlanner/merge.md) - Merge cells - [TableCommandPlanner.unmerge](references/TableCommandPlanner/unmerge.md) - Unmerge cells --- ## Quick Start ```typescript import { TableState, TableCommandPlanner } from '@aptx/table-commands-generator' // Create table state const table = new TableState(5, 5) // Create command planner const planner = new TableCommandPlanner(table) // Perform operations planner.merge(0, 0, 1, 2) // Merge cells (0,0) to (1,2) planner.insertRow(2, 1) // Insert 1 row at index 2 // Get generated commands const commands = planner.getCommands() console.log(commands) // Get renderable data const grid = table.getGridData() ``` --- ## Usage Patterns ### Custom Command Interpreter Extend `CommandInterpreter` to implement custom command handling (e.g., direct DOM manipulation, database operations): ```typescript class DOMInterpreter extends CommandInterpreter { constructor(private tableElement: HTMLTableElement) { super() } protected handleInsertRow(index: number, count: number): void { // Implement DOM row insertion } // ... implement other abstract methods } ``` ### Command Replay and Undo The command pattern enables easy replay, undo, and synchronization: ```typescript const planner = new TableCommandPlanner(tableState, { autoClear: false }) // Generate commands const commands = planner.merge(0, 0, 2, 2) // Save commands for later replay const savedCommands = [...commands] // Replay later interpreter.applyCommands(savedCommands) ``` --- ## Design Philosophy 1. **Separation of Concerns**: Data storage, command execution, and high-level operations are separated into distinct layers 2. **Extensibility**: Command interpreter pattern allows easy adaptation to different storage backends 3. **Automatic Merged Cell Handling**: High-level operations automatically adjust merged cells during structural changes 4. **Sparse Storage**: Uses Map-based sparse storage for memory efficiency