Skip to content

Commit e662a12

Browse files
civingjgroth
authored andcommitted
chore(table): update tabulator to 6
1 parent 785a629 commit e662a12

File tree

12 files changed

+160
-116
lines changed

12 files changed

+160
-116
lines changed

package-lock.json

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/lodash-es": "^4.17.12",
5151
"@types/react": "^19.1.10",
5252
"@types/react-dom": "^19.1.7",
53-
"@types/tabulator-tables": "^4.9.4",
53+
"@types/tabulator-tables": "^6.2.4",
5454
"codemirror": "^5.65.9",
5555
"cross-env": "^7.0.3",
5656
"dayjs": "^1.11.13",
@@ -89,7 +89,7 @@
8989
"shelljs": "0.10.0",
9090
"shx": "^0.4.0",
9191
"style-to-object": "^1.0.9",
92-
"tabulator-tables": "^4.9.3",
92+
"tabulator-tables": "^6.3.1",
9393
"typescript": "^4.9.5",
9494
"unified": "^11.0.5",
9595
"unist-util-visit": "^5.0.0"

src/components/table/columns.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Column, ColumnSorter, ColumnAggregatorFunction } from './table.types';
2-
import Tabulator from 'tabulator-tables';
2+
import {
3+
CellComponent,
4+
ColumnCalc,
5+
ColumnComponent,
6+
ColumnDefinition,
7+
Formatter,
8+
SorterFromTable,
9+
} from 'tabulator-tables';
310
import { escape } from 'html-escaper';
411
import { ElementPool } from './element-pool';
512
import { pickBy, negate } from 'lodash-es';
@@ -15,8 +22,8 @@ export class ColumnDefinitionFactory {
1522
* @param column - config describing the column
1623
* @returns Tabulator column
1724
*/
18-
public create(column: Column<object>): Tabulator.ColumnDefinition {
19-
const definition: Tabulator.ColumnDefinition = {
25+
public create(column: Column<object>): ColumnDefinition {
26+
const definition: ColumnDefinition = {
2027
title: column.title,
2128
field: column.field,
2229
hozAlign: column.horizontalAlign,
@@ -82,10 +89,7 @@ export const formatHeader = (column: Column) => (): string | HTMLElement => {
8289
* @param pool - pool to get custom components from
8390
* @returns Tabulator formatter
8491
*/
85-
export function createFormatter(
86-
column: Column,
87-
pool: ElementPool
88-
): Tabulator.Formatter {
92+
export function createFormatter(column: Column, pool: ElementPool): Formatter {
8993
if (!column.component?.name) {
9094
return formatCell;
9195
}
@@ -100,7 +104,7 @@ export function createFormatter(
100104
return formatCell;
101105
}
102106

103-
return (cell: Tabulator.CellComponent) => {
107+
return (cell: CellComponent) => {
104108
const value = formatCell(cell, column);
105109

106110
return createCustomComponent(cell, column, value, pool);
@@ -126,10 +130,7 @@ function columnElementExists(column: Column<any>) {
126130
* @param column - configuration for the current column
127131
* @returns the formatted value
128132
*/
129-
export function formatCell(
130-
cell: Tabulator.CellComponent,
131-
column: Column
132-
): string {
133+
export function formatCell(cell: CellComponent, column: Column): string {
133134
const data = cell.getData();
134135
let value = cell.getValue();
135136

@@ -154,7 +155,7 @@ export function formatCell(
154155
* @returns custom component that renders a value in the table
155156
*/
156157
export function createCustomComponent(
157-
cell: Tabulator.CellComponent,
158+
cell: CellComponent,
158159
column: Column,
159160
value: string,
160161
pool: ElementPool
@@ -233,10 +234,7 @@ function getEventName(eventListener: string): string {
233234
return eventListener.charAt(2).toLowerCase() + eventListener.slice(3);
234235
}
235236

236-
function createResizeObserver(
237-
element: HTMLElement,
238-
column: Tabulator.ColumnComponent
239-
) {
237+
function createResizeObserver(element: HTMLElement, column: ColumnComponent) {
240238
if (!('ResizeObserver' in window)) {
241239
return;
242240
}
@@ -263,12 +261,6 @@ function createResizeObserver(
263261
}, RESIZE_TIMEOUT);
264262
}
265263

266-
// Tabulator seems to also have this `field` property, that does not appear on
267-
// the interface for some reason
268-
interface TabulatorSorter extends Tabulator.Sorter {
269-
field: string;
270-
}
271-
272264
/**
273265
* Create a column sorter from a tabulator sorter
274266
*
@@ -277,7 +269,7 @@ interface TabulatorSorter extends Tabulator.Sorter {
277269
*/
278270
export const createColumnSorter =
279271
(columns: Column[]) =>
280-
(sorter: TabulatorSorter): ColumnSorter => {
272+
(sorter: SorterFromTable): ColumnSorter => {
281273
const column = columns.find((col) => col.field === sorter.field);
282274
const direction = sorter.dir.toUpperCase() as 'ASC' | 'DESC';
283275

@@ -291,7 +283,7 @@ export const createColumnSorter =
291283
*
292284
* @param column
293285
*/
294-
export function getColumnAggregator(column: Column): Tabulator.ColumnCalc {
286+
export function getColumnAggregator(column: Column): ColumnCalc {
295287
const aggregator = column.aggregator;
296288
if (isAggregatorFunction(aggregator)) {
297289
return (values: any[], data: object[]) => {

src/components/table/partial-styles/_row-selection.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $checkbox-distance-to-left-edge: 0.5rem;
1313
position: absolute;
1414
z-index: $table--limel-table--row-selector;
1515
left: $checkbox-distance-to-left-edge;
16-
top: functions.pxToRem(6);
16+
top: functions.pxToRem(4);
1717
}
1818

1919
.limel-table--row-selector {

src/components/table/partial-styles/_table-main-layout.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
flex-shrink: 0;
1717
}
1818

19-
.tabulator-tableHolder {
19+
.tabulator-tableholder {
2020
isolation: isolate;
2121
flex-grow: 1;
2222
$unset-tabulators-calculated-and-hardcoded-height: unset !important; // tabulator calculates (not so precisely) height of the scrollable area of the table and adds it inline.

src/components/table/partial-styles/tabulator-arrow.scss

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
@use '../../../style/functions';
22

3-
.tabulator-col-sorter {
4-
transition: opacity 0.2s ease;
5-
right: 0 !important;
6-
position: relative !important;
7-
justify-content: center;
8-
cursor: pointer;
9-
10-
[aria-sort='none'] & {
11-
opacity: 0;
12-
}
13-
14-
[aria-sort='desc'] &,
15-
[aria-sort='asc'] & {
16-
opacity: 1;
17-
18-
&:before {
19-
position: absolute;
20-
content: '';
21-
width: 0.125rem;
22-
height: 0.4rem;
23-
background-color: var(--table-arrow-color--active);
3+
.tabulator {
4+
.tabulator-header .tabulator-col .tabulator-col-content {
5+
.tabulator-col-sorter {
6+
position: relative;
7+
cursor: pointer;
8+
transition: opacity 0.2s ease;
9+
right: 0;
2410
}
2511
}
2612
}
2713

2814
.tabulator-sortable {
15+
&[aria-sort='none'] {
16+
.tabulator-col-sorter {
17+
opacity: 0;
18+
}
19+
}
20+
2921
&[aria-sort='desc'],
3022
&[aria-sort='asc'] {
23+
.tabulator-col-sorter {
24+
opacity: 1;
25+
}
26+
3127
&:hover {
3228
.tabulator-col-sorter {
3329
opacity: 1;
@@ -51,6 +47,8 @@
5147
}
5248

5349
.tabulator-arrow {
50+
rotate: 180deg; // changes the direction of the arrow, according to our sorting direction convention
51+
5452
transition: border 0.2s ease;
5553
border-left: 0.25rem solid transparent !important;
5654
border-right: 0.25rem solid transparent !important;
@@ -77,7 +75,7 @@
7775
.tabulator-col.tabulator-sortable[aria-sort='desc']
7876
& {
7977
height: 0;
80-
transform: translate3d(0, -0.2rem, 0) rotate(180deg);
78+
transform: translate3d(0, -0.2rem, 0);
8179
border-top-width: 0.25rem;
8280
border-bottom-width: 0;
8381
border-top-color: var(--table-arrow-color--active);
@@ -88,7 +86,7 @@
8886
.tabulator-col.tabulator-sortable[aria-sort='asc']
8987
& {
9088
height: 0;
91-
transform: translate3d(0, 0.2rem, 0) rotate(180deg);
89+
transform: translate3d(0, 0.2rem, 0);
9290
border-top-width: 0;
9391
border-bottom-width: 0.25rem;
9492
border-bottom-color: var(--table-arrow-color--active);

src/components/table/partial-styles/tabulator-custom-styles.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
order: 2;
147147
}
148148

149-
.tabulator-tableHolder {
149+
.tabulator-tableholder {
150150
order: 3;
151151
}
152152

@@ -162,15 +162,15 @@
162162
}
163163

164164
&:has(.tabulator-calcs-holder) {
165-
.tabulator-tableHolder {
165+
.tabulator-tableholder {
166166
// makes sure aggregations row doesn't cover the last table row,
167167
// and the horizontal scroll bar which is shown on windows
168168
margin-bottom: $height-of-aggregations-row;
169169
}
170170
}
171171

172172
.select-all {
173-
top: functions.pxToRem(42);
173+
top: functions.pxToRem(51);
174174
}
175175

176176
#tabulator-container {

src/components/table/table-selection.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CellComponent, RowComponent, Tabulator } from 'tabulator-tables';
12
import { ElementPool } from './element-pool';
23
import { TableSelection } from './table-selection';
34

@@ -41,7 +42,7 @@ describe('table selection', () => {
4142
...rowData: any[]
4243
) => Map<any, { checked: boolean }> = (...rowData: any[]) => {
4344
const rowCheckboxMap = new Map<any, { checked: boolean }>();
44-
const makeCell: (row: any, data: any) => Tabulator.CellComponent = (
45+
const makeCell: (row: any, data: any) => CellComponent = (
4546
row: any,
4647
data: any
4748
) => {
@@ -57,11 +58,11 @@ describe('table selection', () => {
5758
return cell as any;
5859
};
5960

60-
const makeRow: (
61-
data: any,
62-
position: number
63-
) => Tabulator.RowComponent = (data, position) => {
64-
const row: Partial<Tabulator.RowComponent> = {
61+
const makeRow: (data: any, position: number) => RowComponent = (
62+
data,
63+
position
64+
) => {
65+
const row: Partial<RowComponent> = {
6566
getData: () => data,
6667
getPosition: () => position,
6768
};

0 commit comments

Comments
 (0)