@sheetxl/models
Version:
Models - A Headless javascript spreadsheet library.
183 lines • 10.7 kB
TypeScript
import { CartesianDirection, RemoveListener, Bounds, CellCoords, CellRangeCoords, SetOptions } from "@sheetxl/common";
import { ListenerEmitter, Listener, ListenerOptions } from "../listener";
import { ITransaction } from "../transaction";
import { SerializableProperties } from "../primitives";
import { AdjustedColor } from '../color';
import { ITableModel, TableModelValues } from "../table";
import { CellRangeCoordsAddress, SetCellOptions, ICellValue, CellCoordsAddress, CellVisitorContext, CellAddressValuePair, CoordsValuePair, CellUpdateValue, CellUpdate, RangeSortOptions, MergeType, ClearType, AutoFillRange, AutoFitOptions, CopyCellsOptions, RangeAutoFillOptions, OverflowedCell } from "../cell/CellTypes";
import { IRowHeader, IColumnHeader, RowHeaderJSON, ColumnHeaderJSON, ICellHeader, RowHeaderUpdate, ColumnHeaderUpdate } from "../cell/ICellHeader";
import { ICellModel } from "../cell/ICellModel";
import { ISheetStyle } from "../cell/ISheetStyle";
import { ISharedResource, ISharedResourceCollection, AddSharedResourceOptions } from "../resource";
import { IDrawingModel, DrawingSearchOptions, TypedAddDrawingOptions, IDrawingContainer, AddDrawingImageOptions, IDrawingImageModel } from "../drawing";
import { ISheetHeadersModel } from "./ISheetHeadersModel";
import { ISheetView, CellSelection } from "./ISheetView";
import { ModifyTableSetOptions, ISheetRangeListener, SheetJSON, ISheetModel, ISheetModelListener, ISheetModelOptions, SheetProtection, RangeProtection, ISheetRange, ISheetRangeUpdate, FindCellOptions, RangeListenerOptions, SheetModelEvent, SheetModelListenerType, CopySheetSource, CopyableSheetItem, CountCellItemType } from "./ISheetModel";
export type InternalCellVisitor<T = any> = (value: ICellValue, coords: CellCoords, context: CellVisitorContext, headerOpp: ICellHeader) => {
break: T;
} | void;
/**
* Base implementation of @see {@link ISheetModel}.
*/
declare class SheetModel implements ISheetModel, IDrawingContainer<ISheetModel> {
private _listeners;
private _sheetStyle;
private _ownStyles;
private _sheetStyleRemoveListener;
private _sharedResources;
private _ownResources;
private _lastCellDecoded;
private _lastCellRead;
private _lastMergeRead;
private _lastRangesRead;
private _lastCellBounds;
private _maxCellRange;
private _view;
private _protection;
private _tabColor;
private _isDate1904System;
private _getName;
private _transactionStore;
private _transactionStoreRemoveListener;
private _lastTransactionUUID;
protected _emitter: ListenerEmitter;
private _colHeaders;
private _colHeadersListener;
private _colHeaderUnlistener;
private _rowHeaders;
private _rowHeadersListener;
private _rowHeaderUnlistener;
private _tableModelListener;
private _emptyCell;
private _initialized;
private _closed;
private _deleted;
private _onBeforeDelete;
private _defaultColWidthCache;
private _defaultRowHeightCache;
private _defaultFontBoundsCache;
constructor(initialState?: SheetJSON | ISheetRangeUpdate | ICellValue[][], options?: ISheetModelOptions);
private _parseCellAddress;
getCell(address?: CellCoordsAddress): ICellModel;
private _validateCellCoords;
protected _createSheetRange(range: CellRangeCoords, readonly?: string): ISheetRange;
getRange(address?: CellRangeCoordsAddress): ISheetRange;
private _coordsAsRange;
private _scanRange;
private _getCell;
private _calcTextOverflows;
/**
* Updates the overflow calc and returns a range if overflowed
*/
private _calcTextOverflow;
private _indexOverflows;
setCellPairs(pairs: CellAddressValuePair[], options?: SetCellOptions): void;
private _setCellPairsInternal;
setCell(address: CellCoordsAddress, update: CellUpdateValue): ICellModel;
sort(address: CellRangeCoordsAddress, options?: RangeSortOptions): void;
autoFill(ranges: AutoFillRange[], direction?: CartesianDirection, options?: RangeAutoFillOptions): (offset: number) => CellAddressValuePair;
clear(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], clearType?: ClearType): CellRangeCoords | null;
merge(addresses: CellRangeCoordsAddress | CellRangeCoordsAddress[], mergeType?: MergeType): CellRangeCoords | null;
private _updateMergeRowSpan;
unmerge(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): CellRangeCoords | null;
getMerges(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): CellRangeCoords[];
getCopyableItems(ranges: CellRangeCoords[]): CopyableSheetItem[];
copyCells(aDestination: CellRangeCoordsAddress | CellRangeCoordsAddress[], aSource: CellRangeCoordsAddress | CellRangeCoordsAddress[] | CopySheetSource, options?: CopyCellsOptions): void;
private _updateHeaders;
hideRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void;
hideColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void;
unhideRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void;
unhideColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: SetOptions): void;
insertCells(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], direction?: CartesianDirection.Down | CartesianDirection.Right, options?: SetOptions): void;
removeCells(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], direction?: CartesianDirection.Up | CartesianDirection.Left, options?: SetOptions): void;
private _autoFitHeader;
autoFit(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void;
autoFitRows(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void;
autoFitColumns(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: AutoFitOptions): void;
private _createSheetRangeEvent;
private _notifyRangeListener;
private _notifyRangeListeners;
notifyCellChange(): void;
notifyDelete(): void;
notifyMergeChange(): void;
notifyDrawingsChange(): void;
notifyLayoutChange(): void;
notifyProtectionChange(): void;
notifyStyleChange(): void;
notifyViewChange(update: ISheetView | null): void;
notifyTabColorChange(): void;
addListener(listener: ISheetModelListener): RemoveListener;
addRangeListener(address: CellRangeCoordsAddress, listener: ISheetRangeListener, options?: RangeListenerOptions): RemoveListener;
getCellBounds(includeHeaders?: boolean, includeHidden?: boolean): CellRangeCoords;
countItems(address?: CellCoordsAddress | CellRangeCoordsAddress, types?: Record<CountCellItemType, number | boolean>): Record<CountCellItemType, number>;
getSelectionBounds(): CellRangeCoords;
getActiveAddressCoordsA1(): string;
getActiveAddressCoords(): CellCoords;
find(findText: string, options?: FindCellOptions): CoordsValuePair<ICellModel> | null;
is1904DateSystem(): boolean;
private _findMergeRuns;
findRegionBounds(selection?: CellSelection): CellRangeCoords;
findNextBoundary(coords: CellCoords, direction: CartesianDirection, first?: boolean, limit?: number): number;
private _defaultFontSize;
/**
* Return the column width as a font unit.
* @see {@link https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths}
* @see {@link https://www.ablebits.com/office-addins-blog/change-autofit-column-width-excel/}
*
* @param pixelWidth
*/
getColumnWidthAsFontUnit(pixelWidth: number): number;
/** col width in character units. To get pixels multiple by scale */
private _defaultColWidth;
/** row height in character pts. To get pixels multiple by scale */
private _defaultRowHeight;
getProtection(): Readonly<SheetProtection>;
private _defaultProtection;
setProtection(protection: Partial<SheetProtection>): void;
getProtectedRanges(_addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[]): RangeProtection[];
protectRanges(_addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], _rangeProtection?: RangeProtection): CellRangeCoords | null;
unprotectRanges(_addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], _password?: string): CellRangeCoords | null;
getView(): ISheetView;
setView(view: Partial<ISheetView>): void;
getTabColor(): AdjustedColor;
setTabColor(color: AdjustedColor | string): void;
getRowHeaders(): ISheetHeadersModel<IRowHeader, RowHeaderJSON, RowHeaderUpdate>;
getColumnHeaders(): ISheetHeadersModel<IColumnHeader, ColumnHeaderJSON, ColumnHeaderUpdate>;
toJSON(): Promise<SheetJSON>;
sheetStyle(): ISheetStyle;
sharedResources(): ISharedResourceCollection;
searchDrawings(options?: DrawingSearchOptions): IDrawingModel[];
getDrawingsCount(): number;
updateSelectedDrawings(update: (drawing: IDrawingModel) => void, action?: string): void;
addDrawing(options?: TypedAddDrawingOptions): IDrawingModel;
addEventListener(type: SheetModelListenerType, listener: Listener<SheetModelEvent>, options?: ListenerOptions): RemoveListener;
addImage(image: string | AddSharedResourceOptions | ISharedResource, options?: AddDrawingImageOptions): Promise<IDrawingImageModel>;
getTables(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], includeHidden?: boolean): ITableModel[];
upsertTable(address: CellRangeCoordsAddress, update?: SerializableProperties<TableModelValues>, options?: ModifyTableSetOptions): ITableModel;
removeTables(addresses?: CellRangeCoordsAddress | CellRangeCoordsAddress[], options?: ModifyTableSetOptions): number;
getOverflows(address?: CellRangeCoordsAddress, includeHidden?: boolean): OverflowedCell[];
createCellTemplate(update: CellUpdate | ICellModel, coords?: CellCoords): ICellModel | null;
getMaxCellRange(): CellRangeCoords;
getBoundsFromRange(address: CellCoordsAddress | CellRangeCoordsAddress): Bounds;
getRangeFromBounds(bounds: Bounds): CellRangeCoords;
private _getRanges;
private _shiftRanges;
emptyCell(): ICellModel;
isClosed(): boolean;
delete(): void;
close(): void;
pushTransaction(description?: string): ITransaction;
private _getTransactionState;
private _pushTransaction;
private _updateTransactionState;
private _init;
private _clearState;
private _createDrawingNode;
fromJSON(json: SheetJSON): void;
private _fromJSON;
getName(): string;
get isISheetModel(): true;
}
export default SheetModel;
export { SheetModel };
//# sourceMappingURL=SheetModel.d.ts.map