import { CSSProperties, ReactNode } from 'react'; import { DragItem } from './../stores/dnd-store/store'; import { AggregationType, BeastMode, ChangeType, ChartType, FilterType, MathType, Operation, OperationType, PinType, SortType } from './enums'; import { EChartsCoreOption } from 'echarts'; export interface Row { [key: string]: unknown; _id?: string; _orignalIdx?: number; _hidden?: boolean; _level?: number; _parentRow?: string; _expanded?: boolean; _singleChild?: boolean; _pivotIndexes?: number[]; _childrenMap?: Record; _top?: number; _cachedValue?: Record; children?: Row[]; formatter?: ColumnDef['formatter']; } export type Data = Row[]; export interface StyleProps { width: number; minWidth: number; maxWidth: number; hidden: boolean; flex: number; } export interface FilterProps { filterOptions: IFilter[]; } export interface MenuProps { column: boolean; pin: boolean; filter: boolean; grid: boolean; } export type ColumnId = string; export type NumberFilter = { op: OperationType | undefined; value: number | undefined; }; export type ColumnFilter = { label: string; selected: boolean; id: string; }; export type IFilter = string | NumberFilter | ColumnFilter | boolean; export type AggregationFunction = (row: Row) => string | number; export interface BaseColumnDef { id?: ColumnId; headerName: string; pinned?: PinType; field?: string; sortable?: boolean; children?: ColumnDef[]; childrenMap?: Record; alignment?: 'left' | 'right' | 'center'; autoSortOnPivot?: boolean; formatter?: (value: string & number, row: Row) => string; styleFormatter?: (value: string & number, row: Row, idx: number) => CSSProperties; headerStyleFormatter?: () => CSSProperties; dateFormat?: string; menu?: Partial | boolean; rowGroup?: boolean; aggregation?: AggregationType | AggregationFunction; sort?: SortState; hideInDownload?: boolean; _firstLevel?: boolean; _filters?: Record; _total?: boolean; _summary?: boolean; } export type ColumnDef = Partial & Partial & BaseColumnDef; export interface SortConfig { enabled: boolean; multiple: boolean; } export interface StyleConfig { maxHeight: number | string; border: boolean; } export interface RowEvents { onHover: Partial<{ highlight: boolean; callback: (row: Row, idx: number) => void; }>; onClick: Partial<{ callback: (row: Row, idx: number) => void; }>; } export interface RowGroupConfig { showChildName: boolean; } export interface RowConfig { height: number; border: boolean; groups: RowGroupConfig; events: Partial; } export interface HeaderEvents { onDropOutside: Partial<{ hide: boolean; callback: (column: Column) => void; }>; } export interface HeaderConfig { height: number; border: boolean; events: Partial; } export interface DragOptions { autoScrollSpeed: number; autoScrollMargin: number; } export interface TreeConstructor { name: string; showOriginal: boolean; field: string; width: number; menu: Partial; } export interface ContextualMenuProps { copy: boolean; export: boolean; chart: boolean; } export interface ToolBarButton { enabled: boolean; active: boolean; } export interface ToolBar { download: Partial | boolean; downloadExcel: Partial | boolean; grid: Partial | boolean; pivot: Partial | boolean; filter: Partial | boolean; mode: Partial | boolean; restore: Partial | boolean; history: Partial | boolean; custom: ReactNode; } export interface Chart { defaultValues: Partial<{ dataColumns: string[]; categoryColumns: string[]; chartType: ChartType; }>; groupData: boolean; config: Partial; } export interface PivotValue { field: string; operation: AggregationType; } export interface AsyncRow extends Row { _id: string; _total: boolean; } export interface PivotState { columns: Column[]; rows: Column[]; values: Column[]; data: Data; enabled: boolean; columnTotals: boolean; rowTotals: boolean; rowGroups: boolean; tree: { enabled: boolean; name: string; }; } export interface PivotConfig { rows: string[]; columns: string[]; values: PivotValue[]; rowTotals: boolean; columnTotals: boolean; rowGroups: boolean; } export type CustomSort = ((a: Column, b: Column, columns: ColumnStore) => number) | undefined; export interface Pivot { enabled: boolean; asyncCallback: (pivot: Partial) => Promise; columnSort: CustomSort; applyButton: boolean; totalizable: boolean; pivotableValues: boolean; pivotConfig?: PivotConfig; treeConfig: { enabled: boolean; name: string; }; } export interface Loading { skeleton: ReactNode; rows: number; } export interface BeastGridConfig extends Partial { columnDefs: ColumnDef[]; defaultColumnDef?: Partial; data: T; mode?: BeastMode; topRows?: Data; bottomRows?: Data; fullWidth?: boolean; pivot?: Partial; sort?: Partial; row?: Partial; header?: Partial; style?: Partial; dragOptions?: Partial; tree?: Partial; topToolbar?: Partial; topLeftToolbar?: Partial; bottomToolbar?: Partial; bottomLeftToolbar?: Partial; chart?: Partial; contextualMenu?: Partial; appendModalToBoy?: boolean; loadingState?: Partial; } export interface TableStyles { rowHeight: number; headerHeight: number; border?: boolean; } export interface Position { top: number; left: number; } export interface SortState { order: SortType; priority: number; temporal?: boolean; } export interface Column extends ColumnDef, Position { id: ColumnId; position: number; level: number; final: boolean; width: number; pinned: PinType; finalPosition: number; inView?: boolean; minPosition?: number; maxPosition?: number; childrenId?: ColumnId[]; parent?: ColumnId; original?: ColumnId; originalParent?: ColumnId; filterType?: FilterType; logicDelete?: boolean; lastPinned?: boolean; tree?: boolean; path?: string[]; _formula: Formula | null; _filters?: Record; _summary?: boolean; } export type ColumnStore = Record; export type ColumnArray = Column[][]; export interface HeaderDrag extends DragItem { text: string; isInside: boolean; } export interface BeastGridApi { columns: ColumnStore; setColumns: (columns: ColumnStore) => void; updateConfig: (columnDefs: ColumnDef[], pivotConfig?: PivotConfig) => void; setLoading: (loading: boolean) => void; setPivot: (pivot: PivotConfig) => void; setData: (data: Data, pivot?: PivotConfig) => void; clearHistory: () => void; } export interface Coords { x: number; y: number; } export interface SelectedCells { init: Coords; start: Coords; end: Coords; } export interface SortChanges { sortColumns: Column[]; } export interface SwapChanges { columns: ColumnStore; sortedColumns: Column[]; } export interface PivotChanges { pivot: Partial; } export interface VisibilityChanges { hiddenColumns: Column[]; } export interface ResizeChanges { id: ColumnId; width: number; } export interface Changes extends Partial, Partial, Partial, Partial, Partial { } export type OnChanges = (changeType: ChangeType, changes: Changes) => void; export interface MathCell { type: MathType; cell: string; } export type Operand = MathCell | Formula; export interface Formula { left: Operand | null; right: Operand | null; operation: Operation | null; type: MathType; }