import LazyFactoryMap from '../lazyFactoryMap'; import type ColumnMeta from './columnMeta'; import type { CellProperties } from '../../../settings'; /** * @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. * Pass `null` to append at the end. * @param {number} amount An amount of rows to add. */ createRow(physicalRow: number | null, 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. * Pass `null` to append at the end. * @param {number} amount An amount of columns to add. */ createColumn(physicalColumn: number | null, 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): CellProperties; /** * 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; /** * Checks whether a cell meta object has already been created for the given coordinates, without * creating one. Used to decide whether a cell carries its own (user/declarative) meta that must be * reused, as opposed to deriving a fresh object from the column layer. * * @param {number} physicalRow The physical row index. * @param {number} physicalColumn The physical column index. * @returns {boolean} */ hasMeta(physicalRow: number, physicalColumn: number): boolean; /** * Returns the stored cell meta object for the given coordinates, or `undefined` when the cell * has no materialized meta. Unlike `getMeta`, it never creates row or cell objects, so it is * safe for bulk scans; unlike `hasMeta` followed by `getMeta`, it resolves in two map lookups * instead of five, which matters on the per-cell read path. * * @param {number} physicalRow The physical row index. * @param {number} physicalColumn The physical column index. * @returns {object|undefined} */ getMetaIfExists(physicalRow: number, physicalColumn: number): CellProperties | undefined; /** * Creates a cell meta object inheriting from the column layer without storing it in the map. The * returned object is transient (eligible for garbage collection) and carries no per-cell overrides, * so it must only be used for reads that do not need persisted per-cell meta. * * @param {number} physicalColumn The physical column index. * @returns {object} */ createTransientMeta(physicalColumn: number): CellProperties; /** * 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(): CellProperties[]; /** * 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): CellProperties[]; /** * 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; }[]; /** * Releases render-derived cell meta objects for a single physical row, freeing memory for rows * scrolled out of the viewport. A cell is evicted only when it is purely render-derived: it carries * no persisted meta props (nothing set through `setMeta`/`setCellMeta`, whether imperatively or via * the declarative `cell` option) and is not flagged invalid (`valid === false`, written directly by * the validation flow and not rebuilt on render). Such cells are pure cascade/`cells`/`type` * derivations and are re-created lazily on the next `getMeta` call. Cells with persisted props or a * failed validation result are kept so those values survive scrolling. When the whole row is purely * render-derived, its inner map is dropped as well. * * @param {number} physicalRow The physical row index to evict. * @returns {number[]} The physical column indexes whose meta was evicted (empty when nothing was). */ evictRow(physicalRow: number): number[]; /** * 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): CellProperties; }