react-konva-grid
Version:
Declarative React Canvas Grid primitive for Data table, Pivot table, Excel Worksheets
120 lines (119 loc) • 5.46 kB
TypeScript
import { ItemSizer, InstanceInterface, AreaProps, CellInterface, CellMetaData, SelectionArea } from "./Grid";
import { Direction } from "./types";
export declare enum Align {
start = "start",
end = "end",
center = "center",
auto = "auto",
smart = "smart"
}
export declare enum ItemType {
row = "row",
column = "column"
}
export interface IItemMetaData {
itemType: ItemType;
offset: number;
index: number;
rowCount: number;
columnCount: number;
rowHeight: ItemSizer;
columnWidth: ItemSizer;
instanceProps: InstanceInterface;
}
export declare const getRowStartIndexForOffset: ({ rowHeight, columnWidth, rowCount, columnCount, instanceProps, offset, }: Omit<IItemMetaData, "index" | "itemType">) => number;
interface IRowStopIndex extends Omit<IItemMetaData, "itemType" | "index" | "offset" | "columnCount"> {
startIndex: number;
containerHeight: number;
scrollTop: number;
}
export declare const getRowStopIndexForStartIndex: ({ startIndex, rowCount, rowHeight, columnWidth, scrollTop, containerHeight, instanceProps, }: IRowStopIndex) => number;
export declare const getColumnStartIndexForOffset: ({ rowHeight, columnWidth, rowCount, columnCount, instanceProps, offset, }: Omit<IItemMetaData, "index" | "itemType">) => number;
interface IColumnStopIndex extends Omit<IItemMetaData, "itemType" | "index" | "offset" | "rowCount"> {
startIndex: number;
containerWidth: number;
scrollLeft: number;
}
export declare const getColumnStopIndexForStartIndex: ({ startIndex, rowHeight, columnWidth, instanceProps, containerWidth, scrollLeft, columnCount, }: IColumnStopIndex) => number;
export declare const getBoundedCells: (area: AreaProps | null | undefined) => Set<unknown>;
export declare const itemKey: ({ rowIndex, columnIndex }: CellInterface) => string;
export declare const getRowOffset: ({ index, rowHeight, columnWidth, instanceProps, }: Omit<IGetItemMetadata, "itemType">) => number;
export declare const getColumnOffset: ({ index, rowHeight, columnWidth, instanceProps, }: Omit<IGetItemMetadata, "itemType">) => number;
export declare const getRowHeight: (index: number, instanceProps: InstanceInterface) => number;
export declare const getColumnWidth: (index: number, instanceProps: InstanceInterface) => number;
interface IGetItemMetadata extends Pick<IItemMetaData, "itemType" | "index" | "rowHeight" | "columnWidth" | "instanceProps"> {
}
export declare const getItemMetadata: ({ itemType, index, rowHeight, columnWidth, instanceProps, }: IGetItemMetadata) => CellMetaData;
export declare const getEstimatedTotalHeight: (rowCount: number, instanceProps: InstanceInterface) => number;
export declare const getEstimatedTotalWidth: (columnCount: number, instanceProps: InstanceInterface) => number;
export declare const cellIndentifier: (rowIndex: number, columnIndex: number) => string;
/**
* @desc Throttle fn
* @param func function
* @param limit Delay in milliseconds
*/
export declare function throttle(func: Function, limit: number): Function;
export declare function debounce<T extends Function>(cb: T, wait?: number): T;
export declare function rafThrottle(callback: Function): (e: any) => void;
export interface AlignmentProps extends Omit<IItemMetaData, "offset"> {
containerHeight: number;
containerWidth: number;
align?: Align;
scrollOffset: number;
scrollbarSize: number;
frozenOffset: number;
}
export declare const getOffsetForIndexAndAlignment: ({ itemType, containerHeight, containerWidth, rowHeight, columnWidth, columnCount, rowCount, index, align, scrollOffset, instanceProps, scrollbarSize, frozenOffset, }: AlignmentProps) => number;
export declare const getOffsetForColumnAndAlignment: (props: Omit<AlignmentProps, "itemType">) => number;
export declare const getOffsetForRowAndAlignment: (props: Omit<AlignmentProps, "itemType">) => number;
export declare type TimeoutID = {
id: number;
};
export declare function cancelTimeout(timeoutID: TimeoutID): void;
/**
* Create a throttler based on RAF
* @param callback
* @param delay
*/
export declare function requestTimeout(callback: Function, delay: number): TimeoutID;
export declare const selectionFromActiveCell: (activeCell: CellInterface | null) => SelectionArea[];
/**
* Converts a number to alphabet
* @param i
*/
export declare const numberToAlphabet: (i: number) => string;
/**
* Convert selections to html and csv data
* @param rows
*/
export declare const prepareClipboardData: (rows: string[][]) => [string, string];
/**
* Cycles active cell within selecton bounds
* @param activeCellBounds
* @param selectionBounds
* @param direction
*/
export declare const findNextCellWithinBounds: (activeCellBounds: AreaProps, selectionBounds: AreaProps, direction?: Direction) => CellInterface | null;
/**
* Get maximum bound of an area, caters to merged cells
* @param area
* @param boundGetter
*/
export declare const mergedCellBounds: (area: AreaProps, boundGetter: (coords: CellInterface) => AreaProps) => AreaProps;
/**
* Simple Canvas element to measure text size
* @param defaultFont
*
* Usage
*
* ```
* const textSizer = new AutoSizer('12px Arial')
* textSizer.measureText('Hello world').width
* ```
*/
export declare const AutoSizerCanvas: (defaultFont: string) => {
context: CanvasRenderingContext2D | null;
measureText: (text: string) => TextMetrics | undefined;
setFont: (font?: string) => void;
};
export {};