@sheetxl/models
Version:
Models - A Headless javascript spreadsheet library.
175 lines • 5.86 kB
TypeScript
import { CellRangeCoords } from "@sheetxl/common";
import { RunCoords } from "../run/RunUtils";
import { ICellStyle, CellStyleUpdate, ICellStyleUpdater } from "./ICellStyle";
import { ICellModel } from "./ICellModel";
import { ISheetModel } from "../sheet";
export declare enum HeaderOrientation {
Column = "column",
Row = "row"
}
export interface CellHeaderCreator<T extends ICellHeader> {
(sheetModel: ISheetModel, update?: CellHeaderUpdate, prevModel?: ICellHeader): T;
}
export interface ICellHeader {
/**
* The size in pixels
*/
readonly size: number;
/**
* Flag to indicate if column is hidden. Note - A column with a size > 0 but hidden is true is valid
* because when hiding a value we don't change the size so that an unhide will restore to it's previous location
*/
readonly hidden: boolean;
/**
* Note - size can be a function of autoFitting isCustomSize means the field has set by the user
* and should not be autoSize due to autoFitting (unless explicitly done so by a user gesture)
*/
readonly isCustomSize: boolean;
/**
* isCustomFormat is a special flag that allows for rows to have normal style and not be cleared.
*/
readonly isCustomFormat: boolean;
/**
* The style for the header. Note - This is actually not reflected in the header but rather in all of the cells
* in this header. For example setting font to bold will bold all of the cell within this span but not the
* header itself.
*/
readonly style: ICellStyle;
/**
* Takes an update and returns 3 possible choices.
* 1. A new CellHeaderModel.
* 2. Itself if no changes.
* 3. Null.
*/
cloneWithUpdate(update: CellHeaderUpdate): ICellHeader | null;
/**
* If a cell has no value or formatting
*/
isEmpty(): boolean;
/**
* Returns true if the headers are logically equal
* @param other
*/
isEqual(other: ICellHeader): boolean;
toJSON(): CellHeaderJSON;
cellTemplate(): ICellModel | null;
}
/**
* Specify either a range a run or a string.
* @remarks
* If the value is a string it will be parse as an a1 style address if it is a number it will be a zero based index.
*/
export type CellHeaderRangeAddress = Partial<CellRangeCoords> | RunCoords | string | number;
export type CellHeaderVisitor<T = any> = (header: ICellHeader, min: number, max: number) => {
break: T;
} | void;
export interface CellHeaderVisitorOptions {
/**
* The bounds for the range.
*/
bounds?: CellHeaderRangeAddress;
/**
* Scan cells that have style but not value.
* @defaultValue false
*/
includeStyles?: boolean;
/**
* If true will visit from min to max
* @defaultValue false
*/
includeEmpty?: boolean;
/**
* Scan cells have hidden headers.
* @remarks
* Note - that this will scan the header event if it doesn't have a style.
* This is slightly different than the cell scanner
* because we are scanning the header itself.
* @defaultValue false
*/
includeHiddenHeaders?: boolean;
/**
* Only include if the size is set and different than the default.
* @defaultValue false
*/
includeSizes?: boolean;
}
export interface ICellHeaderRange<T = any> {
/**
* The bounds for the range.
*/
bounds(): RunCoords;
/**
* Advanced and performant way to iteratively values.
* This allows for visiting only values that are not empty.
* <b>Important note</b>
* If no options for filtering are passed this will not return any values
* @remarks
* * Visitors can return a 'break' value to stop the visit.
* * skipEmpty will ensure that only non-empty cells are visited.
* * getContext().getCell() requires additional work over getCoord or reading value.
*/
forEach(visitor: CellHeaderVisitor<T>, options?: CellHeaderVisitorOptions): void;
/**
* Returns the address as a string
*/
toString(): string;
}
export interface IColumnHeader extends ICellHeader {
}
export interface IRowHeader extends ICellHeader {
}
export interface CellHeaderUpdate {
/**
* If the value is a number then the size is interpreted as the 'native' coordinate.
* If a string is passed in that ends in 'px' this will be interpreted as pixels
* and will translate.
*
* @see {@link https://support.microsoft.com/en-us/office/change-the-column-width-and-row-height-72f5e3cc-994d-43e8-ae58-9774a0905f46}
*/
size?: number | string;
/**
* Flag to indicate if column is hidden. Note - A column with a size > 0 but hidden is true is valid
* because when hiding a value we don't change the size so that an unhide will restore to it's previous location
*/
hidden?: boolean;
/**
* Flag to indicate if the size is a size set by the user.
*/
isCustomSize?: boolean;
/**
* @see {@link isCustomFormat}
*/
isCustomFormat?: boolean;
/**
* Update the style.
*/
style?: ICellStyle | CellStyleUpdate | ICellStyleUpdater | null;
}
export interface ColumnHeaderUpdate extends CellHeaderUpdate {
}
export interface RowHeaderUpdate extends CellHeaderUpdate {
}
export interface CellsHeaderAddressValuePair<U extends CellHeaderUpdate = any> {
/**
* Allows for either a Cell or a Range
*/
address?: CellHeaderRangeAddress;
/**
* If null will clear the value
*/
update: ICellHeader | U | null;
}
export interface CellHeaderJSON {
min: number;
max: number;
sz?: number;
cs?: boolean;
h?: boolean;
s?: number;
cf?: boolean;
}
export interface ColumnHeaderJSON extends CellHeaderJSON {
}
export interface RowHeaderJSON extends CellHeaderJSON {
}
//# sourceMappingURL=ICellHeader.d.ts.map