/* Copyright 2026 Marimo. All rights reserved. */ import { makeStateUpdater, type Row, type RowData, type Table, type TableFeature, } from "@tanstack/react-table"; import type { FocusRowOptions, FocusRowTableState } from "./types"; export const FocusRowFeature: TableFeature = { getInitialState: (state): FocusRowTableState => { return { ...state, focusedRowIdx: -1, }; }, getDefaultOptions: ( table: Table, ): FocusRowOptions => { return { enableFocusRow: true, onFocusRowChange: makeStateUpdater("focusedRowIdx", table), }; }, createRow: ( row: Row, table: Table, ): void => { row.focusRow = (updater) => { table.options.onFocusRowChange?.(updater); }; row.getFocusedRowIdx = () => { return table.getState().focusedRowIdx; }; }, };