import type { Component, Snippet } from 'svelte'; import type { StatusType, AnyProp, TableAction, EmptyStateProps, TableSortBy } from '../types.js'; import type { IconSource } from '@steeze-ui/svelte-icon'; import type { Table, Row, Header, Cell } from '@tanstack/table-core'; import type { RenderComponentConfig, RenderSnippetConfig } from './render-helpers.js'; import type BaseDropdown from '../BaseDropdown.svelte'; export type CellType = 'text' | 'boolean' | 'tag' | 'date' | 'currency' | 'uuid' | 'custom'; export type StickyCellWrapperSnippet = Snippet<[ { children: any; align?: 'left' | 'right'; isFirst?: boolean; isLast?: boolean; isFrozen?: boolean; isLastFrozen?: boolean; } ]>; export interface BooleanCellConfig { icon?: IconSource; iconClass?: string; showWhenTrue?: boolean; showWhenFalse?: boolean; hintWhenTrue?: string; hintWhenFalse?: string; } export type CellConfig = TextCellConfig | BooleanCellConfig | TagCellConfig | DateCellConfig | CurrencyCellConfig | UuidCellConfig; export interface CurrencyCellConfig { className?: string; } export interface DataTableColumn { id: string; accessorKey?: keyof TData; header?: string; cellType?: CellType; cellConfig?: CellConfig; cell?: Snippet<[TData]> | ((value: any, row: TData) => Snippet | Component | string | RenderComponentConfig | RenderSnippetConfig); enableSorting?: boolean; enableHiding?: boolean; enableResizing?: boolean; disableColumnFilter?: boolean; size?: number; minSize?: number; maxSize?: number; meta?: DataTableColumnMeta; loadingConfig?: LoadingConfig; } export interface DataTableColumnMeta { cellType?: CellType; dbField?: string; disableColumnFilter?: boolean; filterIcon?: IconSource; filterLabel?: string; filterOptions?: Array<{ value: string; label: string; [key: string]: any; }>; filterType?: 'select' | 'text' | 'numeric' | 'date' | 'uuid'; loadingConfig?: LoadingConfig; } export interface DataTableCellProps { cell: Cell; index: number; visibleCells: Cell[]; allCells: Cell[]; frozenColumns: Set; loading?: boolean; StickyCellWrapper: StickyCellWrapperSnippet; } export interface DataTableHeaderCellProps { header: Header; index: number; headers: Header[]; frozenColumns: Set; columnDropdowns?: Record; onSortingChange?: (columnId: string, direction: TableSortBy) => void; onFilterChange?: (columnId: string) => void; onFreezeChange?: (columnId: string) => void; manualPagination?: boolean; loading?: boolean; } export interface DataTablePaginationProps { table: Table; id?: string; class?: string; showRowsPerPage?: boolean; rowsPerPageOptions?: number[]; itemsLabel?: string; children?: Snippet; onPageChange?: (pageIndex: number) => void; onPageSizeChange?: (pageSize: number) => void; data?: T[]; rowCount?: number; manualPagination?: boolean; disabled?: boolean; disableJumpToPage?: boolean; } export interface DataTableRowProps { row: Row; rowIndex: number; frozenColumns: Set; focusedRowIndex: number; loading?: boolean; onRowClick?: (row: TData) => void; getRowClassName?: (row: TData) => string; getRowState?: (row: TData) => { isSuccess?: boolean; isError?: boolean; isWarning?: boolean; }; StickyCellWrapper: StickyCellWrapperSnippet; } export interface DataTableProps { data: TData[]; columns: DataTableColumn[]; loading?: boolean; disableSelection?: boolean; disablePagination?: boolean; disableKeyboardNavigation?: boolean; disableControls?: boolean; disableJumpToPage?: boolean; rowActions?: TableAction[]; getRowActions?: (row: TData) => TableAction[]; onRowAction?: (action: AnyProp, row: TData) => void; initialPageSize?: number; initialPage?: number; initialSortColumn?: string; initialSortDirection?: TableSortBy; initialFrozenColumns?: string[]; initialColumnOrder?: string[]; initialColumnVisibility?: Record; initialColumnSizing?: Record; pageSizeOptions?: number[]; emptyState?: Omit; onRowClick?: (row: TData) => void; onSelectionChange?: (selectedRows: TData[]) => void; filters?: Snippet; paginationSlot?: Snippet; children?: Snippet; manualPagination?: boolean; manualSorting?: boolean; pageCount?: number; rowCount?: number; onPageChange?: (pageIndex: number) => void; onPageSizeChange?: (pageSize: number) => void; onSortingChange?: (columnId: string, direction: TableSortBy) => void; onFilterChange?: (columnId: string) => void; onFreezeChange?: (columnId: string) => void; onColumnResize?: (columnSizes: Record) => void; onColumnOrderChange?: (columnOrder: string[]) => void; onColumnVisibilityChange?: (visibility: Record) => void; getRowClassName?: (row: TData) => string; getRowState?: (row: TData) => { isSuccess?: boolean; isError?: boolean; isWarning?: boolean; }; } export interface DateCellConfig { className?: string; } export interface CellSkeletonProps { isBoolean?: boolean; loadingConfig?: LoadingConfig; withPadding?: boolean; } export interface LoadingConfig { lines?: number; showAvatar?: boolean; avatarSize?: number; } declare module '@tanstack/table-core' { interface ColumnMeta { cellType?: CellType; disableColumnFilter?: boolean; loadingConfig?: LoadingConfig; } } export interface TagCellConfig { options: Array<{ value: string; label: string; color: StatusType; }>; showDot?: boolean; } export interface TextCellConfig { className?: string; } export interface UuidCellConfig { prefixLength?: number; suffixLength?: number; full?: boolean; disabled?: boolean; onCopy?: (value: string) => void; }