@sheetxl/models
Version:
Models - A Headless javascript spreadsheet library.
154 lines • 6.33 kB
TypeScript
import { Size, Rectangle } from "@sheetxl/common";
import { GridSurfaceStyle } from "@sheetxl/grid";
import { AdjustedColor, SchemeColorLookup } from "../color";
import { UpdatableProperties, SerializableProperties } from "../primitives";
import { ExtendedTextMetrics } from "../font/FontUtils";
import { BorderStrokeStyle, CellBorderValues, ICellBorder } from "./ICellBorder";
import { SolidFillValues, GradientFillValues, NoneFillValues, PatternFillValues, ISolidFill, IGradientFill, IPatternFill, INoneFill } from "./IFill";
import { CellAlignmentValues, ICellAlignment } from "./ICellAlignment";
import { FontValues, IFont } from "./IFont";
import { CellProtectionValues, ICellProtection } from "./ICellProtection";
import { ICellModel } from "./ICellModel";
import { CellUpdate } from "./CellTypes";
import { ISheetStyle } from "./ISheetStyle";
/**
* ICellStyle is an immutable object but values can be set via various updaters using
* the CellStyleValues.
*/
export interface CellStyleValues {
/**
* Font properties. @see {@link FontValues}
*/
font: FontValues;
/** Fill properties for the background */
fill: AdjustedColor | SolidFillValues | GradientFillValues | NoneFillValues | PatternFillValues;
/**
* Alignment properties. @see {@link CellAlignmentValues}
*/
alignment: CellAlignmentValues;
/**
* Border properties. @see {@link CellBorderValues}
*/
border: CellBorderValues;
/**
* Protection properties. @see {@link CellProtectionValues}
*/
protection: CellProtectionValues;
/**
* Format used for
* @see {@link https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformats?view=openxml-2.8.1}
* @see {@link https://customformats.com/}
*
* Additional we allow for aliases to be set.
* @see {@link NumberFormatType}
*/
numberFormat: string;
/**
* A boolean value indicating whether the text string in a cell should be prefixed by a single quote mark (e.g., 'text).
* In these cases, the quote is not stored in the Shared Strings Part.
*/
quotePrefix: boolean;
/**
* The name of the namedStyle that is being referenced. For named styles this is null or ignored.
* If this is not specified then all unspecified fields will inherit from the normal style
*/
namedStyle: string;
}
export interface ICellStyle extends Readonly<CellStyleValues> {
font: IFont;
fill: ISolidFill | IGradientFill | IPatternFill | INoneFill;
alignment: ICellAlignment;
border: ICellBorder;
protection: ICellProtection;
/**
* Returns if the current styled is a named style.
* This is useful when trying to determine if the style contains any customizations
*/
isNamed(): boolean;
/**
* Returns an instance of the named style that this is derived from.
* @remarks
* If this style is a named styled then this will return self.
*/
readonly namedStyleRef: INamedCellStyle;
/**
* Measure the text using the styling properties
* @param text
* @param size optional size @defaultValue 'to the cell font.size'
* @param family optional family @defaultValue 'to the cell font.family'
*/
measureText(text: string, size?: number, family?: string): ExtendedTextMetrics;
/**
* Returns the best fit size assuming no content.
*/
bestFitSize(): Partial<Size> | null;
/**
* Returns insets used for content. This does not taking into account indent because
* this is alignment and type specific.
*/
insets(): Rectangle;
toJSON(): SerializableCellStyleValues;
/**
* This is used to determine if the style has rendering
* artifacts even if there is no content. (For example borders or background)
*/
hasEmptyStyling(): boolean;
readonly isCellStyle: true;
}
export type SerializableCellStyleValues = SerializableProperties<CellStyleValues>;
export type CellStyleUpdate = UpdatableProperties<CellStyleValues>;
export interface ICellStyleUpdater {
(original: ICellStyle | null): CellStyleUpdate;
}
export type SerializableNamedCellStyleValues = SerializableProperties<NamedCellStyleValues & CellStyleValues>;
export type NamedCellStyleUpdate = UpdatableProperties<NamedCellStyleValues & CellStyleValues>;
export interface INamedCellStyleUpdater {
(original: INamedCellStyle | null): NamedCellStyleUpdate;
}
export interface NamedCellStyleValues {
/**
* If 'true' do not show this style in the application UI.
*/
hidden: boolean;
/**
* Indicates that this formatting is for an outline style . When styles are applied to outline levels (using the outline feature), this value is set and the formatting specified on this cell style is applied to the corresponding level of the outline.
*/
iLevel: number | null;
}
export interface INamedCellStyle extends ICellStyle, Readonly<NamedCellStyleValues> {
readonly isNamedCellStyle: true;
readonly name: string;
readonly builtInID: number | null;
toJSON(): SerializableNamedCellStyleValues;
}
export interface ISharedCellStyle extends ICellStyle {
readonly isSharedCellStyle: true;
}
/**
* For providing Adjustable Color Commands additional rendering capabilities.
*/
export interface AdjustedColorContext {
isDarkMode: boolean;
schemeLookup: SchemeColorLookup;
readonly autoColor: AdjustedColor;
readonly quickColor?: AdjustedColor;
recentColors: readonly AdjustedColor[] | (() => readonly AdjustedColor[]);
addRecentColor: (color: AdjustedColor) => readonly AdjustedColor[];
clearRecentColors: () => void;
onColorSelect: (color: AdjustedColor) => void;
}
export interface CellBorderValuesContext {
isDarkMode: boolean;
sheetStyle: ISheetStyle;
readonly autoColor: AdjustedColor;
readonly autoStyle: BorderStrokeStyle;
readonly quickColor: Partial<CellBorderValues>;
onBorderSelect: (border: Partial<CellBorderValues>) => void;
}
export interface SelectedCellStyleContext {
readonly style: () => ICellStyle;
readonly sheetStyle: () => ISheetStyle;
readonly bodyStyle: () => GridSurfaceStyle;
createCellTemplate: (update: CellUpdate | ICellModel | null) => ICellModel;
}
//# sourceMappingURL=ICellStyle.d.ts.map