import type { BodyCell, BodyCellAttributes } from '../bodyCells.js'; import type { BodyRow, BodyRowAttributes } from '../bodyRows.js'; import type { DataColumn, FlatColumn } from '../columns.js'; import type { HeaderCell, HeaderCellAttributes } from '../headerCells.js'; import type { HeaderRow, HeaderRowAttributes } from '../headerRows.js'; import type { PluginInitTableState, TableAttributes, TableBodyAttributes, TableHeadAttributes } from '../createViewModel.js'; import type { Readable } from 'svelte/store'; export type TablePlugin = (init: TablePluginInit) => TablePluginInstance; export type TablePluginInit = { pluginName: string; tableState: PluginInitTableState; columnOptions: Record; }; export type TablePluginInstance = { pluginState: PluginState; transformFlatColumnsFn?: Readable>; deriveFlatColumns?: DeriveFlatColumnsFn; deriveRows?: DeriveRowsFn; derivePageRows?: DeriveRowsFn; deriveTableAttrs?: DeriveFn>; deriveTableHeadAttrs?: DeriveFn>; deriveTableBodyAttrs?: DeriveFn>; columnOptions?: ColumnOptions; hooks?: TableHooks; }; export type AnyPlugins = Record>; export type AnyPluginInstances = Record>; export type TransformFlatColumnsFn = (flatColumns: DataColumn[]) => DataColumn[]; export type DeriveFlatColumnsFn = >(flatColumns: Readable) => Readable; export type DeriveRowsFn = >(rows: Readable) => Readable; export type DeriveFn = (obj: Readable) => Readable; export type Components = { 'thead.tr': HeaderRow; 'thead.tr.th': HeaderCell; 'tbody.tr': BodyRow; 'tbody.tr.td': BodyCell; }; export type AttributesForKey = { 'thead.tr': HeaderRowAttributes; 'thead.tr.th': HeaderCellAttributes; 'tbody.tr': BodyRowAttributes; 'tbody.tr.td': BodyCellAttributes; }; export type ComponentKeys = keyof Components; type TablePropSet = { [K in ComponentKeys]: PropSet[K]; }; export type NewTablePropSet = { [K in ComponentKeys]: unknown extends PropSet[K] ? never : PropSet[K]; }; export type AnyTablePropSet = TablePropSet; type TableAttributeSet = { [K in ComponentKeys]: AttributeSet[K]; }; export type NewTableAttributeSet = { [K in ComponentKeys]: unknown extends AttributeSet[K] ? never : AttributeSet[K]; }; export type AnyTableAttributeSet = TableAttributeSet; export type TableHooks = { [ComponentKey in keyof Components]?: (component: Components[ComponentKey]) => ElementHook; }; export type ElementHook = { props?: Readable; attrs?: Readable; }; export type PluginStates = { [K in keyof Plugins]: ReturnType['pluginState']; }; type TablePropSetForPluginKey = { [K in keyof Plugins]: Plugins[K] extends TablePlugin ? TablePropSet : never; }; export type PluginTablePropSet = { [ComponentKey in ComponentKeys]: { [PluginKey in keyof Plugins]: TablePropSetForPluginKey[PluginKey][ComponentKey]; }; }; export type PluginColumnConfigs = Partial<{ [K in keyof Plugins]: ReturnType['columnOptions']; }>; export {};