import type { HotInstance } from '../../core/types'; import type { ColumnSummary } from './columnSummary'; /** * `HotInstance` augmented with the internal `_setCellMetaDeclarative` method. The method exists on the * Core runtime object but is intentionally NOT part of the public `HotInstance` type, so it is not * exposed to third-party code (it is an implementation detail of how built-in plugins apply * configuration-derived cell meta that must survive the viewport meta eviction but reset on * `updateSettings`, without firing the public `setCellMeta` hooks). ColumnSummary is an internal * consumer and reaches it through this local type. */ type HotInstanceInternal = HotInstance & { _setCellMetaDeclarative(row: number, column: number, key: string, value: unknown): void; }; export interface EndpointConfig { ranges?: number[][]; reversedRowCoords?: boolean; destinationRow?: number; destinationColumn?: number; sourceColumn?: number; type?: string; forceNumeric?: boolean; suppressDataTypeErrors?: boolean; customFunction?: ((endpoint: Record) => number | string) | null; readOnly?: boolean; roundFloat?: number | boolean; result?: number | string; alterRowOffset?: number; alterColumnOffset?: number; [key: string]: unknown; } /** * Class used to make all endpoint-related operations. * * @private * @class Endpoints */ declare class Endpoints { #private; /** * The main plugin instance. */ plugin: ColumnSummary; /** * Handsontable instance. Typed as `HotInstanceInternal` so this internal consumer can call the * non-public `_setCellMetaDeclarative` method (see the type's note). * * @type {object} */ hot: HotInstanceInternal; /** * Array of declared plugin endpoints (calculation destination points). * * @type {Array} * @default {Array} Empty array. */ endpoints: EndpointConfig[]; /** * The plugin settings, taken from Handsontable configuration. * * @type {object|Function} * @default null */ settings: EndpointConfig[] | ((...args: unknown[]) => EndpointConfig[]); /** * Settings type. Can be either 'array' or 'function'. * * @type {string} * @default {'array'} */ settingsType: string; /** * The current endpoint (calculation destination point) in question. * * @type {object} * @default null */ currentEndpoint: EndpointConfig | null; /** * Array containing a list of changes to be applied. * * @private * @type {Array} * @default {[]} */ cellsToSetCache: [number, number | undefined, unknown][]; /** * Initializes the endpoints manager with a reference to the ColumnSummary plugin and the summary endpoint configuration. */ constructor(plugin: ColumnSummary, settings: EndpointConfig[] | ((...args: unknown[]) => EndpointConfig[])); /** * Initialize the endpoints provided in the settings. */ initEndpoints(): void; /** * Get a single endpoint object. * * @param {number} index Index of the endpoint. * @returns {object} */ getEndpoint(index: number): EndpointConfig; /** * Returns the number of physical rows the dataset holds, ignoring trimming. * * Endpoint destination rows and calculation ranges are physical indexes, so they must never be * compared against `countRows()` - that counts only the *visible* rows and shrinks whenever a * plugin trims rows (NestedRows collapsing a group, TrimRows, the Filters plugin). * * @returns {number} */ countPhysicalRows(): number; /** * Returns the number of rows an endpoint may address, that is the physical row count capped by * `maxRows`. Used for the settings defaults that need a row count rather than a bounds check. * * `maxRows` is normalized the same way `DataMap#getLength` does it: `0` or less means zero rows, * anything falsy means no cap. * * @returns {number} */ countAddressableRows(): number; /** * Checks whether an endpoint points outside the table. * * A *trimmed* destination row is not out of bounds - the row exists, it is only hidden - so it is * deliberately not reported here. A row that is visible but sits past `maxRows` is out of bounds, * because the grid renders no cell for it. * * @param {object} endpoint Contains the endpoint information. * @param {number} [rowOffset=0] Row offset to apply before the check. * @param {number} [colOffset=0] Column offset to apply before the check. * @returns {boolean} */ isEndpointOutOfBounds(endpoint: EndpointConfig, rowOffset?: number, colOffset?: number): boolean; /** * Get an array with all the endpoints. * * @returns {Array} */ getAllEndpoints(): EndpointConfig[]; /** * Records the destinations of the endpoints a refresh pass is about to calculate. * * The resolved endpoints are passed in rather than read through `getAllEndpoints()`, which would * re-invoke a settings function and could describe a different layout than the pass is working on. * * @param {object[]} endpoints The endpoints the current pass will calculate. */ cacheSummaryDestinations(endpoints: EndpointConfig[]): void; /** * Checks whether a physical cell holds the result of an endpoint. * * `getCellValue` normally recognizes a result by its `columnSummaryResult` class, but cell meta is * addressed by visual coordinates, so a trimmed row has no readable class. Without this check a * hidden summary row is summed as if it were plain data and inflates every summary covering it. * * @param {number} physicalRow Physical row index. * @param {number} column Column index. * @returns {boolean} */ isSummaryDestination(physicalRow: number, column: number): boolean; /** * Used to fill the blanks in the endpoint data provided by a settings function. * * @private * @param {Function} func Function provided in the HOT settings. * @returns {Array} An array of endpoints. */ fillMissingEndpointData(func: (...args: unknown[]) => EndpointConfig[]): EndpointConfig[]; /** * Parse plugin's settings. * * @param {Array} settings The settings array. * @returns {object[]} */ parseSettings(settings?: EndpointConfig[]): EndpointConfig[] | undefined; /** * Setter for the internal setting objects. * * @param {object} settings Object with the settings. * @param {object} endpoint Contains information about the endpoint for the the calculation. * @param {string} name Settings name. * @param {object} defaultValue Default value for the settings. */ assignSetting(settings: EndpointConfig, endpoint: EndpointConfig, name: string, defaultValue: unknown): void; /** * Resets the endpoint setup before the structure alteration (like inserting or removing rows/columns). Used for settings provided as a function. * * @private * @param {string} action Type of the action performed. * @param {number} index Row/column index. * @param {number} number Number of rows/columns added/removed. */ resetSetupBeforeStructureAlteration(action: string, index: number, number: number): void; /** * AfterCreateRow/afterCreateRow/afterRemoveRow/afterRemoveCol hook callback. Reset and reenables the summary functionality * after changing the table structure. * * @private * @param {string} action Type of the action performed. * @param {number} index Row/column index. * @param {number} number Number of rows/columns added/removed. * @param {Array} [logicRows] Array of the logical indexes. * @param {string} [source] Source of change. * @param {boolean} [forceRefresh] `true` of the endpoints should refresh after completing the function. */ resetSetupAfterStructureAlteration(action: string, index: number, number: number, logicRows: number[] | null | undefined, source: string, forceRefresh?: boolean): void; /** * Clear the offset information from the endpoint object. * * @private * @param {object} endpoint And endpoint object. */ clearOffsetInformation(endpoint: EndpointConfig): void; /** * Extend the row ranges for the provided endpoint. * * @private * @param {object} endpoint The endpoint object. * @param {number} placeOfAlteration Index of the row where the alteration takes place. * @param {number} previousPosition Previous endpoint result position. * @param {number} offset Offset generated by the alteration. */ extendEndpointRanges(endpoint: EndpointConfig, placeOfAlteration: number, previousPosition: number, offset: number): void; /** * Recreate the physical ranges for the provided endpoint. Used (for example) when a row gets moved and extends an existing range. * * @private * @param {object} endpoint An endpoint object. */ recreatePhysicalRanges(endpoint: EndpointConfig): void; /** * Shifts the endpoint coordinates by the defined offset. * * @private * @param {object} endpoint Endpoint object. * @param {number} offsetStartIndex Index of the performed change (if the change is located after the endpoint, nothing about the endpoint has to be changed. */ shiftEndpointCoordinates(endpoint: EndpointConfig, offsetStartIndex: number): void; /** * Resets (removes) the endpoints from the table. * * @param {Array} [endpoints] Array containing the endpoints. * @param {boolean} [useOffset=true] Use the cell offset value. */ resetAllEndpoints(endpoints?: EndpointConfig[], useOffset?: boolean): void; /** * Calculate and refresh all defined endpoints. */ refreshAllEndpoints(): void; /** * Calculate and refresh endpoints only in the changed columns. * * @param {Array} changes Array of changes from the `afterChange` hook. */ refreshChangedEndpoints(changes: unknown[][]): void; /** * Calculate and refresh endpoints whose `sourceColumn` (visual) matches any of the provided columns. * * @param {Set|number[]} visualColumns Visual column indexes to match against. */ refreshEndpointsBySourceColumns(visualColumns: Set | number[]): void; /** * Refreshes the cell meta information for the all endpoints after the `updateSettings` method call which in some * cases (call with `columns` option) can reset the cell metas to the initial state. */ refreshCellMetas(): void; /** * Calculate and refresh a single endpoint. * * @param {object} endpoint Contains the endpoint information. */ refreshEndpoint(endpoint: EndpointConfig): void; /** * Reset the endpoint value. * * @param {object} endpoint Contains the endpoint information. * @param {boolean} [useOffset=true] Use the cell offset value. */ resetEndpointValue(endpoint: EndpointConfig, useOffset?: boolean): void; /** * Set the endpoint value. * * @param {object} endpoint Contains the endpoint information. * @param {string} [source] Source of the call information. * @param {boolean} [render=false] `true` if it needs to render the table afterwards. */ setEndpointValue(endpoint: EndpointConfig, source: string | undefined, render?: boolean): void; /** * Throw an error for the calculation range being out of boundaries. * * @private */ throwOutOfBoundsWarning(): void; } export default Endpoints;