import { VNode , createElement , Ref } from '../vdom' ; import { findElements } from '../util/dom-manip' ; import { ViewContext } from '../ViewContext' ; import { computeSmallestCellWidth } from '../util/misc' ; import { isPropsEqual } from '../util/object' ; import { isArraysEqual } from '../util/array' ; import { BaseOptionsRefined } from '../options' ; export type CssDimValue = string | number ; export interface ColProps { width ? : CssDimValue ; minWidth ? : CssDimValue ; span ? : number ; } export interface SectionConfig { outerContent ? : VNode ; type : 'body' | 'header' | 'footer' ; className ? : string ; maxHeight ? : number ; liquid ? : boolean ; expandRows ? : boolean ; syncRowHeights ? : boolean ; isSticky ? : boolean ; } export type ChunkConfigContent = ( contentProps : ChunkContentCallbackArgs ) => VNode ; export type ChunkConfigRowContent = VNode | ChunkConfigContent ; export interface ChunkConfig { outerContent ? : VNode ; content ? : ChunkConfigContent ; rowContent ? : ChunkConfigRowContent ; scrollerElRef ? : Ref < HTMLDivElement > ; elRef ? : Ref < HTMLTableCellElement > ; tableClassName ? : string ; } export interface ChunkContentCallbackArgs { tableColGroupNode : VNode ; tableMinWidth : CssDimValue ; clientWidth : number | null ; clientHeight : number | null ; expandRows : boolean ; syncRowHeights : boolean ; rowSyncHeights : number [ ] ; reportRowHeightChange : ( rowEl : HTMLElement , isStable : boolean ) => void ; } export function computeShrinkWidth ( chunkEls ) { let shrinkCells = findElements ( chunkEls , '.fc-scrollgrid-shrink' ) ; let largestWidth = 0 ; for ( let shrinkCell of shrinkCells ) { largestWidth = Math . max ( largestWidth , computeSmallestCellWidth ( shrinkCell ) ) ; } return Math . ceil ( largestWidth ) ; } export interface ScrollerLike { needsYScrolling ( ) : boolean ; needsXScrolling ( ) : boolean ; } export function getSectionHasLiquidHeight ( props , sectionConfig ) { return props . liquid && sectionConfig . liquid ; } export function getAllowYScrolling ( props , sectionConfig ) { return sectionConfig . maxHeight != null || getSectionHasLiquidHeight ( props , sectionConfig ) ; } export function renderChunkContent ( sectionConfig , chunkConfig , arg , isHeader ) { let { expandRows } = arg ; let content = typeof chunkConfig . content === 'function' ? chunkConfig . content ( arg ) : createElement ( 'table' , { role : 'presentation' , className : [ chunkConfig . tableClassName , sectionConfig . syncRowHeights ? 'fc-scrollgrid-sync-table' : '' , ] . join ( ' ' ) , style : { minWidth : arg . tableMinWidth , width : arg . clientWidth , height : expandRows ? arg . clientHeight : '' , } , } , arg . tableColGroupNode , createElement ( isHeader ? 'thead' : 'tbody' , { role : 'presentation' , } , typeof chunkConfig . rowContent === 'function' ? chunkConfig . rowContent ( arg ) : chunkConfig . rowContent ) ) ; return content ; } export function isColPropsEqual ( cols0 , cols1 ) { return isArraysEqual ( cols0 , cols1 , isPropsEqual ) ; } export function renderMicroColGroup ( cols , shrinkWidth ? ) { let colNodes = [ ] ; for ( let colProps of cols ) { let span = colProps . span || 1 ; for ( let i = 0 ; i < span ; i += 1 ) { colNodes . push ( < col style = { { width : colProps . width === 'shrink' ? sanitizeShrinkWidth ( shrinkWidth ) : ( colProps . width || '' ) , minWidth : colProps . minWidth || '' , } } />); } } return createElement ( 'colgroup' , { } , ... colNodes ) ; } export function sanitizeShrinkWidth ( shrinkWidth ? ) { return shrinkWidth == null ? 4 : shrinkWidth ; } export function hasShrinkWidth ( cols ) { for ( let col of cols ) { if ( col . width === 'shrink' ) { return true ; } } return false ; } export function getScrollGridClassNames ( liquid , context ) { let classNames = [ 'fc-scrollgrid' , context . theme . getClass ( 'table' ) , ] ; if ( liquid ) { classNames . push ( 'fc-scrollgrid-liquid' ) ; } return classNames ; } export function getSectionClassNames ( sectionConfig , wholeTableVGrow ) { let classNames = [ 'fc-scrollgrid-section' , `fc-scrollgrid-section-${ sectionConfig . type }` , sectionConfig . className , ] ; if ( wholeTableVGrow && sectionConfig . liquid && sectionConfig . maxHeight == null ) { classNames . push ( 'fc-scrollgrid-section-liquid' ) ; } if ( sectionConfig . isSticky ) { classNames . push ( 'fc-scrollgrid-section-sticky' ) ; } return classNames ; } export function renderScrollShim ( arg ) { return ( < div className = "fc-scrollgrid-sticky-shim" style = { { width : arg . clientWidth , minWidth : arg . tableMinWidth , } } />); } export function getStickyHeaderDates ( options ) { let { stickyHeaderDates } = options ; if ( stickyHeaderDates == null || stickyHeaderDates === 'auto' ) { stickyHeaderDates = options . height === 'auto' || options . viewHeight === 'auto' ; } return stickyHeaderDates ; } export function getStickyFooterScrollbar ( options ) { let { stickyFooterScrollbar } = options ; if ( stickyFooterScrollbar == null || stickyFooterScrollbar === 'auto' ) { stickyFooterScrollbar = options . height === 'auto' || options . viewHeight === 'auto' ; } return stickyFooterScrollbar ; }