@nova-ui/bits
Version:
SolarWinds Nova Framework
281 lines (280 loc) • 9.45 kB
TypeScript
import { NgZone, TrackByFunction } from "@angular/core";
import { Subject } from "rxjs";
import { TableResizePhase } from "./table-resizer/table-resizer.directive";
import { TableSelectionMode } from "./types";
import { ISelection, ISelectorState } from "../../services/public-api";
import { SelectionType } from "../selector/public-api";
import { SelectorService } from "../selector/selector.service";
import { ISortedItem } from "../sorter/public-api";
import * as i0 from "@angular/core";
export declare const enum AlignmentClasses {
RIGHT = "align-right",
LEFT = "align-left",
CENTER = "align-center"
}
export declare const enum DropAlignment {
left = "left",
right = "right"
}
export interface ColumnWidthInfo {
width: number;
autoCalculated?: boolean;
}
export interface ITableState {
columnAlignments: {
[key: string]: string;
};
columnsWidths: {
[key: string]: ColumnWidthInfo;
};
columns: string[];
sortedColumn?: ISortedItem;
widthCalculationPerformed: boolean;
columnsTypes: string[];
}
export interface DraggedOverCell {
cellIndex: number;
dropAlignment: DropAlignment;
}
export interface TableCellEdgeHighlight {
columnIndex: number;
side: DropAlignment;
eventPhase: TableResizePhase;
}
export interface ColumnType {
columnName: string;
columnType: string;
}
export interface ITableSortingState {
sortingIcon?: string;
isColumnSorted: boolean;
}
export declare class TableStateHandlerService {
protected zone: NgZone;
protected selectorService: SelectorService;
tableParentWidth: number;
columnsState: Subject<string[]>;
sortingState: Subject<ISortedItem>;
draggedOverCell: Subject<DraggedOverCell | undefined>;
shouldHighlightEdge: Subject<TableCellEdgeHighlight>;
dataSourceChanged: Subject<any[]>;
selectionChanged: Subject<ISelection>;
selectableChanged: Subject<boolean>;
selectionModeChanged: Subject<TableSelectionMode>;
columnWidthSubject: Subject<void>;
stickyHeaderChangedSubject: Subject<void>;
private _reorderable;
private _sortable;
private _resizable;
private _dragCellIndex;
private _draggedOverCellIndex;
private _newCellIndex;
private _dropCellOffsetX;
private _dropCellWidth;
private _dragOverDirection;
private _selectable;
private _selectionMode;
private _hasVirtualScroll;
private _totalItems;
private _dataSource;
private _selection;
_trackBy: TrackByFunction<any>;
protected state: ITableState;
protected sortIcons: {
[key: string]: string;
};
constructor(zone: NgZone, selectorService: SelectorService);
/**
* Used to sync directives and components in table to apply additional styles and logic
*/
set sortable(isSortable: boolean);
get sortable(): boolean;
set dragCellIndex(cellIndex: number);
get dragCellIndex(): number;
set draggedOverCellIndex(cellIndex: number);
get draggedOverCellIndex(): number;
set newCellIndex(cellIndex: number);
get newCellIndex(): number;
set dropCellOffsetX(cellIndex: number);
get dropCellOffsetX(): number;
set dropCellWidth(cellIndex: number);
get dropCellWidth(): number;
set dragOverDirection(cellIndex: string);
get dragOverDirection(): string;
set reorderable(isDraggable: boolean);
get reorderable(): boolean;
set resizable(isResizable: boolean);
get resizable(): boolean;
set tableColumns(columns: string[]);
get tableColumns(): string[];
set columnType(column: ColumnType);
get columnsTypes(): string[];
set sortedColumn(columnToSort: ISortedItem);
set selectable(isSelectable: boolean);
get selectable(): boolean;
set selectionMode(mode: TableSelectionMode);
get selectionMode(): TableSelectionMode;
get hasVirtualScroll(): boolean;
set hasVirtualScroll(value: boolean);
set totalItems(paginationTotal: number);
get totalItems(): number;
set dataSource(dataSource: any[]);
get dataSource(): any[];
set selection(selection: ISelection);
get selection(): ISelection;
get trackBy(): TrackByFunction<any>;
set trackBy(value: TrackByFunction<any>);
get selectionEnabled(): boolean;
/**
* Gets the width of the specified column
*
* @param column The id for the column being queried
*
* @returns The state's column width
*/
getColumnWidth(column: string): number;
/**
* Updates the width of the specified column,
* then broadcasts that a width change has occurred to all listeners of columnWidthSubject
*
* @param column The id for the column
* @param width The new width of the column
*
*/
setColumnWidth(column: string, width: number): void;
/**
* Returns the current alignment direction for the queried column
*
* @param column The id of the column
*
* @returns The current alignment direction
*/
getAlignment(column: string): string;
/**
* Updates the specified column's alignment with the given alignment direction
*
* @param column the id for the column that is being updated
* @param alignment the new alignment direction
*
*/
setAlignment(column: string, alignment?: string): void;
/**
* Determines the alignment for a column based on the type of the provided value.
* Returns AlignmentClasses.RIGHT if the value given is a number; otherwise, returns 'undefined'.
*
* @param value The data for a given column
*
* @returns The alignment direction for that column
*/
defineAlignment(value: any): string | undefined;
/**
* Updates the state's columnWidths for each column and sets the state's widthCalculationPerformed property
* to true once the calculation is complete
*/
calculateWidthsOfColumns(): void;
/**
* Updates the state's sortedColumn and sortedColumn.direction properties and then broadcasts the
* state object to all listeners of sortingState
*
* @param sortCellIndex the index of the column to sort by
*/
sortColumn(sortCellIndex: number): void;
/**
* Updates the state's column order and broadcasts the state's columns to all listeners of columnsState
*
* @param dragCellIndex
* @param newCellIndex
*/
reorderColumns(dragCellIndex: number, newCellIndex: number): void;
/**
* Checks to see if there has been any change in the column's order
* If there was it calls reorderColumns to update the state's column order
*/
reorderColumnsOnDrop(): void;
/**
* Updates the newCellIndex property if the current value is different from draggedOverCellIndex
*/
getNewCellIndex(): void;
/**
* Finds the index for the column that the event happened to
*
* @param event
*
* @returns The column index
*/
getTargetElementCellIndex(event: DragEvent): number;
/**
* Returns the DropAlignment direction for the recently dragged column
*
* @returns The drop alignment direction
*/
getDropCellAlignment(): DropAlignment;
/**
* Checks to see if the recent drag event changed the order of the columns
* then broadcasts the results to all listeners of draggedOverCell
*/
emitDraggedOverCell(): void;
/**
* Broadcasts the given resize information to all listeners of shouldHighlightEdge
*
* @param columnIndex
* @param eventPhase
*/
emitResizeEvent(columnIndex: number, eventPhase: TableResizePhase): void;
/**
* Updates the draggedOverCellIndex
*
* @param event
*/
setDraggedOverCell(event: DragEvent): void;
/**
* Updates the dataSource property and broadcasts the change to all listeners of dataSourceChanged
*
* @param dataSource
*/
changeDataSource(dataSource: any[]): void;
/**
* Returns an array of the selected items
*
* @returns An array of all currently selected items
*/
getSelectedItems(): any[];
/**
* Returns the current state of the selector
*
* @returns
*/
getSelectorState(): ISelectorState;
/**
* Updates the selection type and returns a new selection object based on that new selection type
*
* @param selectorValue
*
* @returns The newly applied selection
*/
applySelector(selectorValue: SelectionType): ISelection;
/**
* Updates the selection object to either include or exclude the row based on the current selection
* type and the row's current selection state
* Then the selection object is broadcast to all listeners of selectionChanged
*
* @param rowObject
*/
handleRowSelect(rowObject: object): void;
private handleRowSelectSingle;
private handleRowSelectMulti;
/**
* Returns the current sorting state of the specified cell index
*
* @param cellIndex
*
* @returns The current sorting state
*/
getSortingState(cellIndex: number): ITableSortingState;
/**
* Broadcasts to all listeners of stickyHeaderChangedSubject that a change has occurred
*/
applyStickyStyles(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<TableStateHandlerService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<TableStateHandlerService>;
}