import type { AnyRecord } from '../../Shared/Types'; import Serializable from '../Serializable.js'; import type { JSON as SerializableJSON } from '../Serializable'; /** * Contains presentation information like column order, usually in relation to a * table instance. */ declare class SharedComponentState implements Serializable { /** * Sorted array of column names. */ private columnOrder?; private columnVisibilityMap; private hiddenRowIndexes; private hoverPoint?; private hoverRow?; private selection; /** * Whether the state has been changed since initialization. */ protected isModified?: boolean; /** * Emits an event on this table to all registered callbacks of the given * event. * * @param {Event} e * Event object with event information. */ emit(e: Event): void; /** * Returns an ordered array of column names. * * @return {Array} * Array of column names in order. */ getColumnOrder(): Array; getColumnVisibility(columnId: string): boolean | undefined; /** * Returns a function for `Array.sort` to change the order of an array of * column names. Unknown column names come last. * * @return {ColumnOrderCallback} * Sort function to change the order. */ getColumnSorter(): ColumnOrderCallback; /** * @return {boolean} * Returns true, if the state was changed since initialization. */ isSet(): boolean; /** * Registers a callback for a specific event. * * @param {string} type * Event type as a string. * * @param {Function} callback * Function to register for an event callback. * * @return {Function} * Function to unregister callback from the event. */ on(type: Event['type'], callback: (this: this, e: Event) => void): Function; /** * Sets the order of the columns in place. * * @param {Array} columnOrder * Array of column names in order. * * @param {AnyRecord} [eventDetail] * Custom information for pending events. */ setColumnOrder(columnOrder: Array, eventDetail?: AnyRecord): void; setColumnVisibility(columnVisibility: Record, eventDetail?: {}): void; setHiddenRows(rowIndexes: number[], hidden?: boolean): void; getHiddenRows(): number[]; setHoverPoint(point?: PresentationHoverPointType | HTMLElement, eventDetail?: HoverPointEventDetails): void; getHoverPoint(): (PresentationHoverPointType | undefined); getSelection(): SelectionObjectType; setSelection(selection: SelectionObjectType, reset?: boolean, eventDetail?: {}): void; } /** * Additionally provided types for events and JSON conversion. */ /** * Event types related to the column order. */ export type ColumnOrderEventType = ('columnOrderChange' | 'afterColumnOrderChange'); export type ColumnVisibilityEventType = ('columnVisibilityChange' | 'afterColumnVisibilityChange'); export type HoverPointEventType = ('hoverPointChange' | 'afterHoverPointChange'); export type selectionEventType = ('selectionChange' | 'afterSelectionChange'); export type eventTypes = (selectionEventType | HoverPointEventType | ColumnVisibilityEventType); /** * Function to sort an array of column names. */ export interface ColumnOrderCallback { (a: string, b: string): number; } export interface HoverPointEventDetails { detail?: AnyRecord; isGrid?: boolean; sender?: string; } /** * All information objects of DataPresentationState events. */ export type Event = (ColumnOrderEvent | ColumnVisibilityEvent | PointHoverEvent | SelectionEvent | HiddenRowEvent); /** * Describes the information object for order-related events. */ export interface ColumnOrderEvent { type: ColumnOrderEventType; detail?: AnyRecord; newColumnOrder: Array; oldColumnOrder: Array; } export interface ColumnVisibilityEvent { type: ColumnVisibilityEventType; detail?: AnyRecord; visibilityMap: Record; } export interface HiddenRowEvent { type: ('afterSetHiddenRows'); detail?: AnyRecord; hiddenRows: number[]; } export interface PointHoverEvent { type: HoverPointEventType; detail?: AnyRecord; hoverPoint?: PresentationHoverPointType; hoverRow?: HTMLElement; } export type ColumnVisibilityType = Record; export type SelectionObjectType = Record; export type PresentationHoverPointType = Partial; export interface SelectionEvent { type: selectionEventType; detail?: AnyRecord; reset: boolean; selection: Record; } /** * Describes the class JSON of a presentation state. */ export interface JSON extends SerializableJSON<'Dashboards.SharedComponentState'> { columnOrder?: Array; visibilityMap?: ColumnVisibilityType; hoverpoint?: { x: number; y: number; id: string; }; selection?: SelectionObjectType; } export default SharedComponentState;