import type { HotInstance } from '../core/types'; /** * Represents the MetaManager dependency shape used by DataMap. */ interface MetaManagerLike { getTableMeta(): Record; createRow(physicalIndex: number | null, amount: number): void; createColumn(physicalIndex: number | null, amount: number): void; removeRow(physicalIndex: number, amount: number): void; removeColumn(physicalIndex: number, amount: number): void; getCellMeta(physicalRow: number, physicalColumn: number, options?: object): Record; } /** * Utility class that gets and saves data from/to the data source using mapping of columns numbers to object property names. * * @todo Refactor arguments of methods getRange, getText to be numbers (not objects). * @todo Remove priv, GridSettings from object constructor. * * @class DataMap * @private */ declare class DataMap { #private; /** * @type {number} */ static get DESTINATION_RENDERER(): number; /** * @type {number} */ static get DESTINATION_CLIPBOARD_GENERATOR(): number; /** * Instance of {@link Handsontable}. * * @private * @type {Handsontable} */ hot: HotInstance | null; /** * Instance of {@link MetaManager}. * * @private * @type {MetaManager} */ metaManager: MetaManagerLike | null; /** * Instance of {@link TableMeta}. * * @private * @type {TableMeta} */ tableMeta: Record & { maxRows?: number; maxCols?: number; columns?: ((column: number) => Record) | Record[]; dataSchema?: unknown; startRows?: number; startCols?: number; colHeaders?: boolean; rowHeaders?: boolean; data?: unknown; dataDotNotation?: boolean; }; /** * Reference to the original dataset. * * @type {*} */ dataSource: (Record | unknown[])[] | null; /** * Generated schema based on the first row from the source data. * * @type {object} */ duckSchema: unknown; /** * Cached array of properties to columns. * * @type {Array} */ colToPropCache: (string | number)[]; /** * Cached map of properties to columns. * * @type {Map} */ propToColCache: Map | undefined; /** * @param {object} hotInstance Instance of Handsontable. * @param {Array} data Array of arrays or array of objects containing data. * @param {MetaManager} metaManager The meta manager instance. */ constructor(hotInstance: HotInstance, data: (Record | unknown[])[], metaManager: MetaManagerLike); /** * Generates cache for property to and from column addressation. */ createMap(): void; /** * Get the amount of physical columns in the first data row. * * @returns {number} Amount of physical columns in the first data row. */ countFirstRowKeys(): number; /** * Generates columns' translation cache. * * @param {object} schema An object to generate schema from. * @param {number} lastCol The column index. * @param {number} parent The property cache for recursive calls. * @returns {number} */ recursiveDuckColumns(schema: unknown, lastCol?: number, parent?: string): number; /** * Returns property name that corresponds with the given column index. * * @param {string|number} column Visual column index or another passed argument. * @returns {string|number} Column property, physical column index or passed argument. */ colToProp(column: number): string | number; /** * Translates property into visual column index. * * @param {string|number} prop Column property which may be also a physical column index. * @returns {string|number} Visual column index or passed argument. */ propToCol(prop: string | number): string | number; /** * Returns data's schema. * * @returns {object} */ getSchema(): unknown[] | Record; /** * Creates the duck schema based on the current dataset. * * @returns {Array|object} */ createDuckSchema(): unknown; /** * Refresh the data schema. */ refreshDuckSchema(): void; /** * Creates row at the bottom of the data array. * * @param {number} [index] Physical index of the row before which the new row will be inserted. * @param {number} [amount=1] An amount of rows to add. * @param {object} [options] Additional options for created rows. * @param {string} [options.source] Source of method call. * @param {'above'|'below'} [options.mode] Sets where the row is inserted: above or below the passed index. * @fires Hooks#afterCreateRow * @returns {number} Returns number of created rows. */ createRow(index: number | undefined, amount?: number, { source, mode }?: { source?: string; mode?: string; }): { delta: number; startPhysicalIndex?: undefined; } | { delta: number; startPhysicalIndex: number; }; /** * Creates column at the right of the data array. * * @param {number} [index] Visual index of the column before which the new column will be inserted. * @param {number} [amount=1] An amount of columns to add. * @param {object} [options] Additional options for created columns. * @param {string} [options.source] Source of method call. * @param {'start'|'end'} [options.mode] Sets where the column is inserted: at the start (left in [LTR](@/api/options.md#layoutdirection), right in [RTL](@/api/options.md#layoutdirection)) or at the end (right in LTR, left in LTR) * the passed index. * @fires Hooks#afterCreateCol * @returns {number} Returns number of created columns. */ createCol(index: number | undefined, amount?: number, { source, mode }?: { source?: string; mode?: 'start' | 'end'; }): { delta: number; startPhysicalIndex?: undefined; } | { delta: number; startPhysicalIndex: number; }; /** * Removes row from the data array. * * @fires Hooks#beforeRemoveRow * @fires Hooks#afterRemoveRow * @param {number} [index] Visual index of the row to be removed. If not provided, the last row will be removed. * @param {number} [amount=1] Amount of the rows to be removed. If not provided, one row will be removed. * @param {string} [source] Source of method call. * @returns {boolean} Returns `false` when action was cancelled, otherwise `true`. */ removeRow(index: number, amount: number | undefined, source: string): boolean; /** * Removes column from the data array. * * @fires Hooks#beforeRemoveCol * @fires Hooks#afterRemoveCol * @param {number} [index] Visual index of the column to be removed. If not provided, the last column will be removed. * @param {number} [amount=1] Amount of the columns to be removed. If not provided, one column will be removed. * @param {string} [source] Source of method call. * @returns {boolean} Returns `false` when action was cancelled, otherwise `true`. */ removeCol(index: number, amount: number | undefined, source: string): boolean; /** * Add/Removes data from the column. * * @param {number} col Physical index of column in which do you want to do splice. * @param {number} index Index at which to start changing the array. If negative, will begin that many elements from the end. * @param {number} amount An integer indicating the number of old array elements to remove. If amount is 0, no elements are removed. * @param {Array} [elements] The new columns to add. * @returns {Array} Returns removed portion of columns. */ spliceCol(col: number, index: number, amount: number, ...elements: unknown[]): unknown[]; /** * Add/Removes data from the row. * * @param {number} row Physical index of row in which do you want to do splice. * @param {number} index Index at which to start changing the array. If negative, will begin that many elements from the end. * @param {number} amount An integer indicating the number of old array elements to remove. If amount is 0, no elements are removed. * @param {Array} [elements] The new rows to add. * @returns {Array} Returns removed portion of rows. */ spliceRow(row: number, index: number, amount: number, ...elements: unknown[]): unknown[]; /** * Add/remove row(s) to/from the data source. * * @param {number} index Physical index of the element to add/remove. * @param {number} deleteCount Number of rows to remove. * @param {Array} elements Row elements to be added. */ spliceData(index: number, deleteCount: number, elements: unknown[]): void; /** * Filter unwanted data elements from the data source. * * @param {number} index Visual index of the element to remove. * @param {number} amount Number of rows to add/remove. * @param {number} physicalRows Physical row indexes. */ filterData(index: number, amount: number, physicalRows: number[]): void; /** * Returns single value from the data array. * * @param {number} row Visual row index. * @param {number} prop The column property. * @returns {*} */ get(row: number, prop: string | number): unknown; /** * Returns single value from the data array (intended for clipboard copy to an external application). * * @param {number} row Visual row index. * @param {number} prop The column property. * @returns {string} */ getCopyable(row: number, prop: string | number): unknown; /** * Saves single value to the data array. * * @param {number} row Visual row index. * @param {number|string} prop The column property. * @param {string} value The value to set. */ set(row: number, prop: string | number, value: unknown): void; /** * This ridiculous piece of code maps rows Id that are present in table data to those displayed for user. * The trick is, the physical row id (stored in settings.data) is not necessary the same * as the visual (displayed) row id (e.g. When sorting is applied). * * @param {number} index Visual row index. * @param {number} amount An amount of rows to translate. * @returns {number} */ visualRowsToPhysical(index: number, amount: number): number[]; /** * * @param {number} index Visual column index. * @param {number} amount An amount of rows to translate. * @returns {Array} */ visualColumnsToPhysical(index: number, amount: number): number[]; /** * Clears the data array. */ clear(): void; /** * Get data length. * * @returns {number} */ getLength(): number; /** * Returns the data array. * * @returns {Array} */ getAll(): unknown[][]; /** * Count the number of columns cached in the `colToProp` cache. * * @returns {number} Amount of cached columns. */ countCachedColumns(): number; /** * Returns data range as array. * * @param {object} [start] Start selection position. Visual indexes. * @param {object} [end] End selection position. Visual indexes. * @param {number} destination Destination of datamap.get. * @returns {Array} */ getRange(start: { row: number; col: number; }, end: { row: number; col: number; }, destination: number): unknown[][]; /** * Return data as text (tab separated columns). * * @param {object} [start] Start selection position. Visual indexes. * @param {object} [end] End selection position. Visual indexes. * @returns {string} */ getText(start: { row: number; col: number; }, end: { row: number; col: number; }): string; /** * Return data as copyable text (tab separated columns intended for clipboard copy to an external application). * * @param {object} [start] Start selection position. Visual indexes. * @param {object} [end] End selection position. Visual indexes. * @returns {string} */ getCopyableText(start: { row: number; col: number; }, end: { row: number; col: number; }): string; /** * Destroy instance. */ destroy(): void; } export default DataMap;