UNPKG

tanstack-table-header-rowspan

Version:
1 lines 3.56 kB
{"version":3,"file":"rowspan.modern.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Header } from '@tanstack/react-table';\nimport { type CSSProperties } from 'react';\n\nfunction deepestHeader<D, V>(header: Header<D, V>): Header<D, V> | null {\n let last = header;\n while (true) {\n const next =\n last.isPlaceholder && last.colSpan === 1 && last.subHeaders.length === 1\n ? last.subHeaders[0]\n : null;\n if (next) {\n last = next;\n } else {\n return last === header ? null : last;\n }\n }\n}\n\nexport function tableHeaderRowSpan(header: Header<any, any>): number | null {\n const deepest = deepestHeader(header);\n const rowSpan = (deepest ? deepest.depth - header.depth : 0) + 1;\n const above = header.depth - header.column.depth;\n if (above > 1) {\n return null;\n }\n return rowSpan;\n}\nexport function tableFooterRowSpan(header: Header<any, any>): number | null {\n const deepest = deepestHeader(header);\n const below = (deepest ? deepest.depth - header.depth : 0) + 1;\n const above = header.depth - header.column.depth;\n if (below > 1) {\n return null;\n }\n return above;\n}\n\nexport function flexTableHeaderRowSpan(header: Header<any, any>) {\n const rowSpan = header.depth - header.column.depth;\n return {\n rowSpan,\n topBorderMightBeNeeded: header.column.depth === 0,\n styles: (cssRowHeight: CSSProperties['height']): CSSProperties => ({\n /** @ts-ignore */\n '--rowspan': rowSpan,\n height: `calc(var(--rowspan, 1) * ${cssRowHeight})`,\n marginTop: `calc(-1 * (var(--rowspan, 1) - 1) * ${cssRowHeight})`,\n visibility: header.isPlaceholder ? 'hidden' : undefined,\n }),\n };\n}\n\nexport function flexTableFooterRowSpan(header: Header<any, any>) {\n const rowSpan = header.depth - header.column.depth;\n return {\n rowSpan,\n bottomBorderMightBeNeeded: header.column.depth === 0,\n styles: (cssRowHeight: CSSProperties['height']): CSSProperties => ({\n /** @ts-ignore */\n '--rowspan': rowSpan,\n height: `calc(var(--rowspan, 1) * ${cssRowHeight})`,\n marginBottom: `calc(-1*(var(--rowspan, 1) - 1) * ${cssRowHeight})`,\n visibility: header.isPlaceholder ? 'hidden' : undefined,\n }),\n };\n}\n"],"names":["deepestHeader","header","last","next","isPlaceholder","colSpan","subHeaders","length","tableHeaderRowSpan","deepest","depth","column","tableFooterRowSpan","flexTableHeaderRowSpan","rowSpan","topBorderMightBeNeeded","styles","cssRowHeight","height","marginTop","visibility","undefined","flexTableFooterRowSpan","bottomBorderMightBeNeeded","marginBottom"],"mappings":"AAGA,SAASA,EAAoBC,GAC3B,IAAIC,EAAOD,EACX,OAAa,CACX,MAAME,EACJD,EAAKE,eAAkC,IAAjBF,EAAKG,SAA4C,IAA3BH,EAAKI,WAAWC,OACxDL,EAAKI,WAAW,GAChB,KACN,IAAIH,EAGF,OAAOD,IAASD,EAAS,KAAOC,EAFhCA,EAAOC,CAIX,CACF,CAEM,SAAUK,EAAmBP,GACjC,MAAMQ,EAAUT,EAAcC,GAG9B,OADcA,EAAOS,MAAQT,EAAOU,OAAOD,MAC/B,OAFmD,GAA9CD,EAAUA,EAAQC,MAAQT,EAAOS,MAAQ,EAM5D,CACM,SAAUE,EAAmBX,GACjC,MAAMQ,EAAUT,EAAcC,GAG9B,OAF6D,GAA9CQ,EAAUA,EAAQC,MAAQT,EAAOS,MAAQ,GAE5C,OADET,EAAOS,MAAQT,EAAOU,OAAOD,KAK7C,CAEM,SAAUG,EAAuBZ,GACrC,MAAMa,EAAUb,EAAOS,MAAQT,EAAOU,OAAOD,MAC7C,MAAO,CACLI,UACAC,uBAAgD,IAAxBd,EAAOU,OAAOD,MACtCM,OAASC,IAAqC,CAE5C,YAAaH,EACbI,OAAQ,4BAA4BD,KACpCE,UAAW,uCAAuCF,KAClDG,WAAYnB,EAAOG,cAAgB,cAAWiB,IAGpD,CAEgB,SAAAC,EAAuBrB,GACrC,MAAMa,EAAUb,EAAOS,MAAQT,EAAOU,OAAOD,MAC7C,MAAO,CACLI,UACAS,0BAAmD,IAAxBtB,EAAOU,OAAOD,MACzCM,OAASC,IAA0D,CAEjE,YAAaH,EACbI,OAAQ,4BAA4BD,KACpCO,aAAc,qCAAqCP,KACnDG,WAAYnB,EAAOG,cAAgB,cAAWiB,IAGpD"}