import { SELECTING_KEYS } from './constants'; import { ObjectForExtending } from '../types/utils.type'; import { GroupRow } from '../feature-rows-grouping/types'; import { ChangeEvent } from 'react'; export type ChildrenInfo = { all: RowType[]; disabled: RowIdType[]; notDisabled: RowIdType[]; notDisabledAndNotHidden: RowIdType[]; notDisabledAndNotHiddenAreSelected: boolean; hidden: RowIdType[]; notHidden: RowIdType[]; selected: RowIdType[]; notSelected: RowIdType[]; someChildrenIsSelected: boolean; }; export type RowKeyGetter = (row: RowType) => RowIdType; export type RowShowCheckbox = (row: RowType, lvl?: number, parent?: RowType | null) => boolean; export type RowCheckboxDisabled = (row: RowType, lvl?: number, parent?: RowType | null) => boolean; export type RowGetStatesProps = { isHaveCheckboxCalculated: boolean; isRowSelectedCalculated: boolean; isIndeterminateCalculated: boolean; isRowSelectionDisabled: boolean; rowKeyGetter: RowKeyGetter; row: RowType; flattenedRowsMap: Map; selectedRows: ReadonlySet; setSelectedRows: React.Dispatch>>; level: number; parent: RowType | null; getRowChildrenInfo: () => ChildrenInfo; rowShowCheckbox: RowShowCheckbox | undefined; rowCheckboxDisabled: RowCheckboxDisabled | undefined; }; export type RowGetStatesReturnType = { checked?: boolean | null; indeterminate?: boolean | null; showCheckbox?: boolean | null; checkboxDisabled?: boolean | null; onChange?: ((p: { allParentsMap: Map; isRowInLevels: (row: RowType) => boolean; defaultSetter: () => void; getRowParentsInfo: () => { all: RowType[]; getShouldBeSelectedInfo: (actualSelecteds: ReadonlySet) => { shouldBeSelected: RowIdType[]; shouldNotBeSelected: RowIdType[]; }; }; }) => void) | null; }; export type SummaryCheckedFunc = (props: { rows: RowType[]; flattenedRows: (RowType & { level?: number; parent?: RowType | null; })[]; selectedRowsIds: ReadonlySet; rowKeyGetter: (row: RowType) => RowIdType; rowCheckboxDisabled: RowCheckboxDisabled; rowShowCheckbox: RowShowCheckbox; allRowsInLevels: (RowType & { level?: number; parent?: RowType | null; })[]; getAllRowsInfo: () => ChildrenInfo; } & (AdditionalPropsObj extends ObjectForExtending ? AdditionalPropsObj : {})) => ReturnType; export type SelectingRowConfig = { showDefault?: boolean; showState?: [boolean, React.Dispatch>]; showInControl?: boolean; selectingRules?: { levels?: number | 'all' | number[] | ((lvl: number) => boolean); }; disableSummaryCheckboxInHeader?: boolean; hideSummaryCheckboxInHeader?: boolean; hideSummaryCheckbox?: boolean; summaryChecked?: { checked: boolean | SummaryCheckedFunc; indeterminate: boolean | SummaryCheckedFunc; getCountOfChecked: SummaryCheckedFunc; onChange: SummaryCheckedFunc>>; }>; }; summaryCheckedUncontrolled?: { onChange: (event: ChangeEvent) => void; }; rowShowCheckbox?: RowShowCheckbox; rowCheckboxDisabled?: RowCheckboxDisabled; rowGetStates?: (p: RowGetStatesProps) => RowGetStatesReturnType | null; groupedRow?: { getStates: (p: { checkedCalculated: boolean; indeterminateCalculated: boolean; row: GroupRow; selectedRows: ReadonlySet; selectedChildCount: number; childCount: number; }) => { checked?: boolean | null; indeterminate?: boolean | null; showCheckbox?: boolean | null; checkboxDisabled?: boolean | null; } | null; onChange?: (p: { row: GroupRow; setSelectedRows: React.Dispatch>>; checked: boolean; indeterminate: boolean; checkboxDisabled: boolean; showCheckbox: boolean; defaultSetter: () => void; }) => void; }; }; export type FlattenedRowsArrAndMap = { flattenedRows: (RowType & { [SELECTING_KEYS.level]?: number; [SELECTING_KEYS.parent]?: RowType | null; })[]; flattenedRowsMap: Map; };