import { Ref } from 'vue'; import { Filter, Sorter, Thing, Valuer } from './types'; export declare const UNSORTED = "unsorted"; export declare const ASCENDING = "ascending"; export declare const DESCENDING = "descending"; export type Direction = typeof ASCENDING | typeof DESCENDING | typeof UNSORTED; export type Column = string | undefined; export type Type = "date" | "number" | "string"; export interface State { direction: Direction; column?: Column; } export interface Controls { readonly state: State; readonly click: (column: string, direction?: Direction) => void; readonly isUnsorted: (column: string) => boolean; readonly isAscending: (column: string) => boolean; readonly isDescending: (column: string) => boolean; readonly _unsorted?: Thing[]; readonly _sorted?: Thing[]; } export declare const COLUMN_TYPES: Record; export declare const COLUMN_MAPPINGS: Record; /** * Create a set of controls for sorting a list of objects represented in a table * The source array will be sorted in place, so other consumers can react to the changes. * Likewise, if the source array is changed, the controls will be updated to reflect the new array. * * @param source - A Vue ref for the list of objects to sort * @returns - A reactive set of controls for sorting the list */ export declare function createControls(source: Ref): Controls; /** * Toggles direction thru three states, unsorted -> ascending -> descending -> unsorted * If a direction is specified, it will be set to that direction. * * @param state - The sort state to toggle * @param direction - The direction to set, if any */ export declare function changeDirection(state: State, direction?: Direction): void; /** * Changes the sort column, toggling direction if the column is already selected, * resetting direction to ascending if a new column is selected, unless a direction is specified. * * @param state - The sort state to update * @param column - The column to sort by * @param direction - The direction to sort by, if any */ export declare function changeState(state: State, column?: Column, direction?: Direction): void; /** * Sorts a list of objects column the current state of the sort controls. * If the direction is undefined, the list will be returned to its original order. * * @param state - The current sort state * @param sortMe - The list of objects to sort * @param unsorted - The original order of the objects */ export declare function sortFor(state: State, sortMe: T[], unsorted: T[]): void; /** * Sets the column types for a list of column properties. * This is used to determine the type of a column when sorting. * * @param type - The type to set for the columns * @param columns - The list of columns to set the type for */ export declare function setColumnTypes(type: Type, columns: string[]): void; /** * Adds a mapping for a column to a different column name. * This is useful when the column name is different from the property name. * * @param column - The column name to map * @param toGetter - The property name to map to */ export declare function addColumnMapping(column: string, toGetter: string): void; /** * Returns the type of a column, or "string" if the type is unknown. * If the column is not found, the first object in the list will be used to determine the type. * Otherwise, the type will be "string". * * @param column - The column to get the type for * @param unsorted - The list of objects to determine the type from * @returns - The mapped or detected type of the column */ export declare function getType(column: string, unsorted: Thing[]): Type; /** * Creates a sorter function for a column, based column the type of the column. * If the type is not specified, the sorter will default to string comparison. * * @param column - The column to sort by * @param descending - If true, sort in descending order (default: false) * @param type - The type of the column to sort * @returns - A sorter function that compares two objects column the column value */ export declare function createSorter(column: string, descending?: boolean, type?: Type): Sorter; /** * Returns a sorter function that compares two objects column a property. * * @param get - The property to sort column, or a function that returns the property value * @param descending - If true, sort in descending order (default: false) * @returns - A sorter function that compares two objects column the property value */ export declare function sorter(get: string | Valuer, descending?: boolean): Sorter; /** * Returns a filter function that matches a property to a value. * The match is case-insensitive and can be partial or exact. * * @param get - The property to match, or a function that returns the property * @param match - The value to match * @param perfect - If true, the match must be exact (default: false) * @returns - A filter function that matches the property to the value */ export declare function matcher(get: string | Valuer, match: string, perfect?: boolean): Filter; export declare function stringSorter(column: string, descending?: boolean): Sorter; export declare function dateSorter(column: string, descending?: boolean): Sorter; export declare function numberSorter(column: string, descending?: boolean): Sorter;