import type { Area } from './area'; import type { CellStyle } from './style'; import type { TextPart } from './text_part'; import type { Complex } from './value-type'; import { ValueType } from './value-type'; import type { CellValue, UnionValue } from './union'; import type { PreparedText } from './render_text'; import type { Table } from './table'; export interface RenderFunctionOptions { height: number; width: number; context: CanvasRenderingContext2D; cell: Cell; style: CellStyle; scale?: number; } export interface RenderFunctionResult { handled: boolean; } export type RenderFunction = (options: RenderFunctionOptions) => RenderFunctionResult; export interface ClickFunctionOptions { cell: Cell; x?: number; y?: number; width?: number; height?: number; scale?: number; } export interface ClickFunctionResult { /** * change the cell value, to the value passed here * * NOTE: this must be in canonical form (english), not translated. */ value?: CellValue; /** * set to true to block normal click handling semantics * (selecting the cell, generally) */ block_selection?: boolean; } export type ClickFunction = (options: ClickFunctionOptions) => ClickFunctionResult; export declare class Cell { static StringToColumn(s: string): number; value?: CellValue; type: ValueType; calculated?: CellValue; calculated_type?: ValueType; formatted?: string | TextPart[]; /** * rendered type may be different than value type: could be a function * returns a number, or an error. rendering an empty value should result * in a string, so you can test on this type -- it should never be 0 * (or undefined) if the cell has been rendered. * * NOTE: no one really uses this. it's only read in two places -- one in * grid to check if it's a number and we want to format as % (which seems * wrong anyway, because what if it's a function?) -- and in sheet, as a * flag indicating we have already rendered it (it gets flushed on change). * * so we could maybe remove it or switch to a boolean or something... is * boolean any smaller than number? */ rendered_type?: ValueType; style?: CellStyle; /** if this cell is part of an array, pointer to the area. */ area?: Area; /** testing spill */ spill?: Area; /** * if this cell is merged, pointer to the area */ merge_area?: Area; /** this cell is part of a table */ table?: Table; /** * opaque data for cell rendering, we can cache some data * that's reused frequently (is that wasting space?) * * render data will be flushed any time there is any change to * the cell data or style. * * UPDATE: renderer data is no longer flushed. we set a dirty flag. */ renderer_data?: { text_data?: PreparedText; overflowed?: boolean; width?: number; height?: number; }; /** * step 1: invert flag (dirty -> clean) */ render_clean: boolean[]; note?: string; /** * moving hyperlink in here, as a cell property. hyperlink will not be * removed on value change, but will be removed on clear/delete. */ hyperlink?: string; editing?: boolean; /** * TODO: add a return value which affects control flow. default/falsy should * behave as now, for backwards compatibility; but it should be possible to * return a value that says "don't exit the standard rendering process" * * UPDATE: return value now means "I have handled this", so if you paint you * should return true. that's a breaking change but we should get help from * tooling. */ render_function?: RenderFunction; click_function?: ClickFunction; /** * moving locked property to style. not because it's properly a style, * or not properly a property of cell, but rather because that will allow * us to cascade the property over areas. */ /** not editable */ constructor(value?: CellValue, value_type?: ValueType); /** type guard */ ValueIsNumber(): this is { value: number; }; /** type guard */ ValueIsFormula(): this is { value: string; }; /** type guard */ ValueIsBoolean(): this is { value: boolean; }; /** type guard */ ValueIsComplex(): this is { value: Complex; }; /** flush style information and things that rely on it (formatted value) */ FlushStyle(): void; /** flush array information */ FlushArray(): void; /** flush cached data: formatted and calculated */ FlushCache(): void; Reset(): void; Set(value: CellValue, type?: ValueType): void; /** * sets calculated value and flushes cached value */ SetCalculatedValue(value: CellValue, type?: ValueType): void; /** * get value -- calculation result (not formatted) or literal. for * literal strings, we strip leading apostrophes (these are used to * prevent parsing of literal strings that look like other things). */ GetValue(): CellValue; /** * this function follows the rule of GetValue3, which is: if the type * is a function but there is no calculated value, then return 0. */ GetValue4(): UnionValue; /** * set note. set undefined to clear. */ SetNote(note?: string): void; /** sets error (FIXME: error type) */ SetCalculationError(err?: string): void; SetArray(area: Area): void; SetArrayHead(area: Area, value: CellValue): void; }