import * as React from 'react' ; import { EditableColumn } from './Editable' ; import Cell , { CellType } from './Cell' ; import { hasData } from './_utils' ; export default < T extends object > ( columns , curCell , setCurCell , form ) => { const dataIndexMap = [ ] ; const loopColumns = ( lColumns ) : Array < EditableColumn < T > > => { let dataIndexMapItem = [ ] ; return lColumns . map ( ( item ) => { if ( item . children ) { const { children , ... resCol } = item ; return { ... resCol , children : loopColumns ( children ) , } ; } else { const { render , dataIndex , editable = true , rules , isSelect , children , ... res } = item ; const resItem = { dataIndex , ... res , render : ( text , record , rowIndex ) => { const { editable : rowEditbale = true } = record ; const initialValue = hasData ( render ? render ( text , record , rowIndex ) : text ) ; const canRowEditbale = typeof rowEditbale === 'boolean' ? rowEditbale : ( function foo ( ) { const { disabled = [ ] } = rowEditbale ; return ! disabled . includes ( dataIndex ) ; } ) ( ) ; if ( editable && canRowEditbale ) { dataIndexMapItem . includes ( dataIndex ) ? ( dataIndexMapItem = [ dataIndex ] ) : dataIndexMapItem . push ( dataIndex ) ; dataIndexMap [ rowIndex ] = dataIndexMapItem ; const cellprops = { form , key : `${ dataIndex }-${ rowIndex }` , dataIndex , rowIndex , curCell , onSetCurCell : setCurCell , initialValue , rules , isSelect , } ; return < Cell { ... cellprops } / > ; } return < div className = "editable-cell-uneditable" > { initialValue } < /div>; } , } ; return resItem ; } } ) ; } ; return { editColumns : loopColumns ( columns ) , dataIndexMap , } ; } ;