import type { Column } from '../interfaces/iColumn'; import type { IRowNode } from '../interfaces/iRowNode'; import type { ValueFormatterParams, ValueParserParams } from './colDef'; export type ValueParserLiteParams = Omit, 'data' | 'node' | 'oldValue'>; export type ValueParserLiteFunc = (params: ValueParserLiteParams) => TValue | null | undefined; export type ValueFormatterLiteParams = Omit, 'data' | 'node'>; export type ValueFormatterLiteFunc = (params: ValueFormatterLiteParams) => string; /** * The pre-defined base data types. * * `'text'` is type `string`. * * `'number'` is type `number`. * * `'bigint'` is type `bigint`. * * `'boolean'` is type `boolean`. * * `'date'` is type `Date`. * * `'dateString'` is type `string` but represents a date. * * `'dateTime'` is type `Date`. * * `'dateTimeString'` is type `string` but represents a date with time. * * `object` is any other type. */ export type BaseCellDataType = 'text' | 'number' | 'bigint' | 'boolean' | 'date' | 'dateString' | 'object' | 'dateTime' | 'dateTimeString'; interface BaseDataTypeDefinition { /** The underlying data type */ baseDataType: TValueType; /** * The data type that this extends. Either one of the pre-defined data types * (`'text'`, `'number'`, `'bigint'`, `'boolean'`, `'date'`, `'dateString'`, `'dateTime'`, `'dateTimeString'` * or `'object'`) * or another custom data type. */ extendsDataType: string; /** * Parses a value into the correct data type. * This will be used as the `colDef.valueParser` (unless overridden), * and in other places where parsing is required. * As this could be used in places where there is no row, * the `params` do not have row node or data properties. * If not provided, the value parser of the data type that this extends will be used. */ valueParser?: ValueParserLiteFunc; /** * Formats a value for display. * This will be used as the `colDef.valueFormatter` (unless overridden), * and in other places where formatting is required. * As this could be used in places where there is no row, * the `params` do not have row node or data properties. * If not provided, the value formatter of the data type that this extends will be used. */ valueFormatter?: ValueFormatterLiteFunc; /** * Returns `true` if the `value` is of this data type. * Used when inferring cell data types as well as to ensure values of the * wrong data type cannot be set into this column. * If not provided, the data type matcher of the data type that this extends will be used. */ dataTypeMatcher?: (value: any) => boolean; /** * A comma separated string or array of strings containing `ColumnType` keys, * which can be used as a template for columns of this data type. */ columnTypes?: string | string[]; /** * If `true`, this data type will append any specified column types to those of the data type that this extends. * If `false`, the column types for this data type will replace any of the data type that this extends. * @default false */ appendColumnTypes?: boolean; /** * By default, certain column definition properties are set based on the base data type. * If this is set to `true`, these properties will not be set. * @default false */ suppressDefaultProperties?: boolean; } /** Represents a `'text'` data type (type `string`). */ export interface TextDataTypeDefinition extends BaseDataTypeDefinition<'text', TData, string, TContext> { } /** Represents a `'number'` data type (type `number`). */ export interface NumberDataTypeDefinition extends BaseDataTypeDefinition<'number', TData, number, TContext> { } /** Represents a `'bigint'` data type (type `bigint`). */ interface BigIntDataTypeDefinition extends BaseDataTypeDefinition<'bigint', TData, bigint, TContext> { } /** Represents a `'boolean'` data type (type `boolean`). */ export interface BooleanDataTypeDefinition extends BaseDataTypeDefinition<'boolean', TData, boolean, TContext> { } /** Represents a `'date'` data type (type `Date`). */ export interface DateDataTypeDefinition extends BaseDataTypeDefinition<'date', TData, Date, TContext> { } /** Represents a `'dateString'` data type (type `string` that represents a date). */ export interface DateStringDataTypeDefinition extends BaseDataTypeDefinition<'dateString', TData, string, TContext> { /** Converts a date in `string` format to a `Date`. */ dateParser?: (value: string | undefined) => Date | undefined; /** Converts a date in `Date` format to a `string`. */ dateFormatter?: (value: Date | undefined) => string | undefined; } /** Represents a `'dateTime'` data type (type `Date`). */ export interface DateTimeDataTypeDefinition extends BaseDataTypeDefinition<'dateTime', TData, Date, TContext> { } /** Represents a `'dateTimeString'` data type (type `string` that represents a dateTime). */ export interface DateTimeStringDataTypeDefinition extends BaseDataTypeDefinition<'dateTimeString', TData, string, TContext> { /** Converts a date in `string` format to a `Date`. */ dateParser?: (value: string | undefined) => Date | undefined; /** Converts a date in `Date` format to a `string`. */ dateFormatter?: (value: Date | undefined) => string | undefined; } /** Represents an `'object'` data type (any type). */ export interface ObjectDataTypeDefinition extends BaseDataTypeDefinition<'object', TData, TValue, TContext> { } /** Throws an error if not all keys K are present in Record Obj, as well as if Obj has extra keys (though only if you try to access properties) */ export type CheckDataTypes, K extends keyof any = BaseCellDataType> = keyof Obj extends K ? Obj : never; /** Configuration options for a cell data type. */ export type DataTypeDefinition = TextDataTypeDefinition | NumberDataTypeDefinition | BigIntDataTypeDefinition | BooleanDataTypeDefinition | DateDataTypeDefinition | DateStringDataTypeDefinition | DateTimeDataTypeDefinition | DateTimeStringDataTypeDefinition | ObjectDataTypeDefinition; export type DataTypeDefinitions = { [cellDataType: string]: DataTypeDefinition; }; /** Configuration options for pre-defined data types. */ export type CoreDataTypeDefinition = Omit, 'extendsDataType'>; export type DataTypeFormatValueFunc = (params: { column: Column; node: IRowNode | null; value: any; }) => string; export {};