import LazyFactoryMap from '../lazyFactoryMap'; import type ColumnMeta from './columnMeta'; /** * @class CellMeta * * The cell meta object is a root of all settings defined for the specific cell rendered by the * Handsontable. Each cell meta inherits settings from higher layers. When a property doesn't * exist in that layer, it is looked up through a prototype to the highest layer. Starting * from CellMeta -> ColumnMeta and ending to GlobalMeta, which stores default settings. Adding, * removing, or changing property in that object has no direct reflection on any other layers. * * +-------------+ * │ GlobalMeta │ * │ (prototype) │ * +-------------+\ * │ \ * │ \ * \│/ _\| * +-------------+ +-------------+ * │ TableMeta │ │ ColumnMeta │ * │ (instance) │ │ (prototype) │ * +-------------+ +-------------+ * │ * │ * \│/ * +-------------+ * │ CellMeta │ * │ (instance) │ * +-------------+ */ export default class CellMeta { #private; /** * Reference to the ColumnMeta layer. While creating new cell meta objects, all new objects * inherit properties from the ColumnMeta layer. * * @type {ColumnMeta} */ columnMeta: ColumnMeta; /** * Holder for cell meta objects, organized as a grid of LazyFactoryMap of LazyFactoryMaps. * The access to the cell meta object is done through access to the row defined by the physical * row index and then by accessing the second LazyFactory Map under the physical column index. * * @type {LazyFactoryMap>} */ metas: LazyFactoryMap>>; /** * Initializes the cell meta layer with a reference to the ColumnMeta layer used as the prototype source for new cell meta objects. */ constructor(columnMeta: ColumnMeta); /** * Resumes tracking of user-defined cell meta properties by closing one suspension scope opened by * `disableUserDefinedMetaRecording`. Recording becomes active again only once every suspension has * been closed. Subsequent `setMeta` calls then mark their keys as user-defined, so they are * preserved across `updateSettings`. */ enableUserDefinedMetaRecording(): void; /** * Suspends tracking of user-defined cell meta properties. While suspended, `setMeta` calls are * treated as declarative writes and de-mark their keys, so they are not preserved across * `updateSettings`. Suspensions nest - each call must be matched by an `enableUserDefinedMetaRecording` * call before recording resumes. */ disableUserDefinedMetaRecording(): void; /** * Updates cell meta object by merging settings with the current state. * * @param {number} physicalRow The physical row index which points what cell meta object is updated. * @param {number} physicalColumn The physical column index which points what cell meta object is updated. * @param {object} settings An object to merge with. */ updateMeta(physicalRow: number, physicalColumn: number, settings: Record): void; /** * Creates one or more rows at specific position. * * @param {number} physicalRow The physical row index which points from what position the row is added. * @param {number} amount An amount of rows to add. */ createRow(physicalRow: number, amount: number): void; /** * Creates one or more columns at specific position. * * @param {number} physicalColumn The physical column index which points from what position the column is added. * @param {number} amount An amount of columns to add. */ createColumn(physicalColumn: number, amount: number): void; /** * Removes one or more rows from the collection. * * @param {number} physicalRow The physical row index which points from what position the row is removed. * @param {number} amount An amount of rows to remove. */ removeRow(physicalRow: number, amount: number): void; /** * Removes one or more columns from the collection. * * @param {number} physicalColumn The physical column index which points from what position the column is removed. * @param {number} amount An amount of columns to remove. */ removeColumn(physicalColumn: number, amount: number): void; /** * Gets settings object for this layer. * * @param {number} physicalRow The physical row index. * @param {number} physicalColumn The physical column index. * @param {string} [key] If the key exists its value will be returned, otherwise the whole cell meta object. * @returns {object} */ getMeta(physicalRow: number, physicalColumn: number): Record; /** * Returns the value of the specified property key from the cell meta object at the given physical row and column. */ getMeta(physicalRow: number, physicalColumn: number, key: string): unknown; /** * Sets settings object for this layer defined by "key" property. * * @param {number} physicalRow The physical row index. * @param {number} physicalColumn The physical column index. * @param {string} key The property name to set. * @param {*} value Value to save. */ setMeta(physicalRow: number, physicalColumn: number, key: string, value: unknown): void; /** * Removes a property defined by the "key" argument from the cell meta object. * * @param {number} physicalRow The physical row index. * @param {number} physicalColumn The physical column index. * @param {string} key The property name to remove. */ removeMeta(physicalRow: number, physicalColumn: number, key: string): void; /** * Returns all cell meta objects that were created during the Handsontable operation. As cell meta * objects are created lazy, the length of the returned collection depends on how and when the * table has asked for access to that meta objects. * * @returns {object[]} */ getMetas(): Record[]; /** * Returns all cell meta objects that were created during the Handsontable operation but for * specific row index. * * @param {number} physicalRow The physical row index. * @returns {object[]} */ getMetasAtRow(physicalRow: number): Record[]; /** * Returns a flat snapshot of all cell meta properties that were set imperatively through * `setMeta` (tracked in each cell's `_userDefinedMetaProps`). The coordinates are read from the * map keys (physical indexes), not from the meta object's `row`/`col` properties, which are only * populated on `getCellMeta` and become stale after row or column shifts. Used to preserve * user-defined meta across a cache clear during `updateSettings`. * * @returns {{physicalRow: number, physicalColumn: number, key: string, value: *}[]} */ getUserDefinedMetas(): { physicalRow: number; physicalColumn: number; key: string; value: unknown; }[]; /** * Clears all saved cell meta objects. */ clearCache(): void; /** * Creates and returns new structure for cell meta objects stored in columnar axis. * * @private * @returns {object} */ _createRow(): LazyFactoryMap>; /** * Creates and returns new cell meta object with properties inherited from the column meta layer. * * @private * @param {number} physicalColumn The physical column index. * @returns {object} */ _createMeta(physicalColumn: number): Record; }