import { DEFAULT_COLUMN_WIDTH } from '../constants' import { GridEditorInput } from '../editors' import { GridCellDefaultRenderer, GridFooterCellDefaultRenderer, GridHeaderCellDefaultRenderer, } from '../renderers' import type { Column, ColumnGroup } from '../types' const columnGroupDefault: Partial> = { resizable: true, movable: true, lockedLocation: 'none', sticky: 'none', } const columnDefault: Partial> = { width: DEFAULT_COLUMN_WIDTH, resizable: true, movable: true, sortable: true, lockedLocation: 'none', sortStrategy: 'fast', sticky: 'none', cell: { Renderer: GridCellDefaultRenderer, Editor: GridEditorInput, }, header: { Renderer: GridHeaderCellDefaultRenderer, }, footer: { Renderer: GridFooterCellDefaultRenderer, }, } export const setColumnDefaults = (col: Column): Column => ({ ...columnDefault, ...col, lockedLocation: col.sticky && col.sticky !== 'none' ? col.sticky : col.lockedLocation || columnDefault.lockedLocation, movable: (col.sticky && col.sticky !== 'none') || (col.lockedLocation && col.lockedLocation !== 'none') ? false : typeof col.movable === 'boolean' ? col.movable : columnDefault.movable, header: { ...columnDefault.header, ...col.header, }, hideable: col.tree ? false : col.hideable, hidden: col.tree ? false : col.hidden, cell: { ...columnDefault.cell, ...col.cell, }, footer: { ...columnDefault.footer, ...col.footer, }, }) export const setColumnGroupDefaults = ( group: ColumnGroup ): ColumnGroup => ({ ...columnGroupDefault, ...group, })