qbs-react-grid 1.3.15 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/ColumnGroup.js +1 -1
- package/es/ColumnResizeHandler.js +2 -2
- package/es/Scrollbar.js +1 -1
- package/es/Table.d.ts +1 -1
- package/es/qbsTable/QbsTable.js +125 -9
- package/es/qbsTable/TableCardList.js +1 -1
- package/es/utils/getTableColumns.js +10 -10
- package/es/utils/useAffix.d.ts +4 -4
- package/es/utils/useAffix.js +5 -5
- package/es/utils/useCellDescriptor.d.ts +2 -2
- package/es/utils/usePosition.d.ts +5 -5
- package/es/utils/usePosition.js +3 -3
- package/es/utils/useScrollListener.d.ts +4 -4
- package/es/utils/useScrollListener.js +15 -15
- package/es/utils/useTableDimension.d.ts +11 -11
- package/es/utils/useTableDimension.js +2 -2
- package/es/utils/useTableRows.d.ts +1 -1
- package/lib/ColumnGroup.js +1 -1
- package/lib/ColumnResizeHandler.js +2 -2
- package/lib/Scrollbar.js +1 -1
- package/lib/Table.d.ts +1 -1
- package/lib/qbsTable/QbsTable.js +125 -9
- package/lib/qbsTable/TableCardList.js +1 -1
- package/lib/utils/getTableColumns.js +10 -10
- package/lib/utils/useAffix.d.ts +4 -4
- package/lib/utils/useAffix.js +5 -5
- package/lib/utils/useCellDescriptor.d.ts +2 -2
- package/lib/utils/usePosition.d.ts +5 -5
- package/lib/utils/usePosition.js +3 -3
- package/lib/utils/useScrollListener.d.ts +4 -4
- package/lib/utils/useScrollListener.js +14 -14
- package/lib/utils/useTableDimension.d.ts +11 -11
- package/lib/utils/useTableDimension.js +2 -2
- package/lib/utils/useTableRows.d.ts +1 -1
- package/package.json +7 -7
- package/src/ColumnGroup.tsx +25 -11
- package/src/ColumnResizeHandler.tsx +2 -2
- package/src/Scrollbar.tsx +1 -1
- package/src/Table.tsx +4 -4
- package/src/qbsTable/QbsTable.tsx +227 -117
- package/src/qbsTable/TableCardList.tsx +2 -2
- package/src/utils/getTableColumns.ts +4 -4
- package/src/utils/useAffix.ts +11 -11
- package/src/utils/useCellDescriptor.ts +4 -4
- package/src/utils/usePosition.ts +9 -9
- package/src/utils/useScrollListener.ts +19 -19
- package/src/utils/useTableDimension.ts +4 -4
|
@@ -98,7 +98,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
98
98
|
const [checkedKeys, setCheckedKeys] = useState<(number | string)[]>([]);
|
|
99
99
|
const dataTheme = useMemo(() => localStorage.getItem('theme') ?? theme, [theme]);
|
|
100
100
|
const [isOpen, setIsOpen] = useState(false);
|
|
101
|
-
const prevColumns = useRef<any | null>();
|
|
101
|
+
const prevColumns = useRef<any | null>(null);
|
|
102
102
|
const [tableViewToggle, setTableViewToggle] = useState(tableView);
|
|
103
103
|
const isMobile = useResponsiveStore();
|
|
104
104
|
const tableBodyRef = useRef<HTMLDivElement>(null);
|
|
@@ -328,131 +328,241 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
328
328
|
}, [columns, handleColumnsResizable]);
|
|
329
329
|
|
|
330
330
|
useEffect(() => {
|
|
331
|
-
|
|
331
|
+
if (tableView) {
|
|
332
|
+
setTableViewToggle(!isMobile);
|
|
333
|
+
} else {
|
|
334
|
+
setTableViewToggle(false);
|
|
335
|
+
}
|
|
332
336
|
}, [isMobile]);
|
|
333
337
|
|
|
334
338
|
const findGrouped = () => {
|
|
335
339
|
return columns?.find(item => item.grouped) ? true : false;
|
|
336
340
|
};
|
|
341
|
+
// const columnsRendered: React.ReactElement[] = useMemo(
|
|
342
|
+
// () =>
|
|
343
|
+
// (columns ?? []).map(
|
|
344
|
+
// ({
|
|
345
|
+
// title,
|
|
346
|
+
// field,
|
|
347
|
+
// resizable,
|
|
348
|
+
// sortable,
|
|
349
|
+
// colWidth,
|
|
350
|
+
// align,
|
|
351
|
+
// grouped,
|
|
352
|
+
// groupHeader,
|
|
353
|
+
// fixed,
|
|
354
|
+
// children,
|
|
355
|
+
// customCell,
|
|
356
|
+
// renderCell,
|
|
357
|
+
// isVisible,
|
|
358
|
+
// link,
|
|
359
|
+
// getPath,
|
|
360
|
+
// rowClick,
|
|
361
|
+
// sortKey,
|
|
362
|
+
// type,
|
|
363
|
+
// hideLink
|
|
364
|
+
// }) =>
|
|
365
|
+
// isVisible &&
|
|
366
|
+
// (grouped ? (
|
|
367
|
+
// <ColumnGroup
|
|
368
|
+
// header={groupHeader}
|
|
369
|
+
// fixed={fixed}
|
|
370
|
+
// align={align}
|
|
371
|
+
// verticalAlign="middle"
|
|
372
|
+
// groupHeaderHeight={40}
|
|
373
|
+
// >
|
|
374
|
+
// {children?.map(child => (
|
|
375
|
+
// <Column
|
|
376
|
+
// key={child.title}
|
|
377
|
+
// sortable={child.sortable}
|
|
378
|
+
// width={child.colWidth ?? COLUMN_WIDTH}
|
|
379
|
+
// resizable={child.resizable}
|
|
380
|
+
// align={child.align}
|
|
381
|
+
// onResize={handleColumnWidth}
|
|
382
|
+
// fixed={child.fixed}
|
|
383
|
+
// >
|
|
384
|
+
// <HeaderCell
|
|
385
|
+
// dataTheme={dataTheme}
|
|
386
|
+
// verticalAlign={'middle'}
|
|
387
|
+
// className={` ${classes.headerClass}`}
|
|
388
|
+
// sortKey={child.sortKey}
|
|
389
|
+
// renderSortIcon={renderSortIcon}
|
|
390
|
+
// >
|
|
391
|
+
// {child.title}
|
|
392
|
+
// </HeaderCell>
|
|
393
|
+
// {child.customCell || child.link ? (
|
|
394
|
+
// <CustomTableCell
|
|
395
|
+
// renderCell={child.renderCell}
|
|
396
|
+
// dataKey={child.field}
|
|
397
|
+
// dataTheme={dataTheme}
|
|
398
|
+
// type={child.type}
|
|
399
|
+
// path={child.getPath}
|
|
400
|
+
// link={child.link}
|
|
401
|
+
// />
|
|
402
|
+
// ) : (
|
|
403
|
+
// <Cell
|
|
404
|
+
// className={` ${classes.cellClass}`}
|
|
405
|
+
// dataKey={child.field}
|
|
406
|
+
// dataTheme={dataTheme}
|
|
407
|
+
// />
|
|
408
|
+
// )}
|
|
409
|
+
// </Column>
|
|
410
|
+
// ))}
|
|
411
|
+
// </ColumnGroup>
|
|
412
|
+
// ) : (
|
|
413
|
+
// <Column
|
|
414
|
+
// key={title}
|
|
415
|
+
// sortable={sortable}
|
|
416
|
+
// width={colWidth ?? COLUMN_WIDTH}
|
|
417
|
+
// resizable={resizable}
|
|
418
|
+
// align={align}
|
|
419
|
+
// fixed={fixed}
|
|
420
|
+
// onResize={handleColumnWidth}
|
|
421
|
+
// >
|
|
422
|
+
// <HeaderCell
|
|
423
|
+
// dataTheme={dataTheme}
|
|
424
|
+
// verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
425
|
+
// className={` ${classes.headerClass}`}
|
|
426
|
+
// sortKey={sortKey}
|
|
427
|
+
// renderSortIcon={renderSortIcon}
|
|
428
|
+
// >
|
|
429
|
+
// {title}
|
|
430
|
+
// </HeaderCell>
|
|
431
|
+
// {customCell || link ? (
|
|
432
|
+
// <CustomTableCell
|
|
433
|
+
// renderCell={renderCell}
|
|
434
|
+
// dataKey={field}
|
|
435
|
+
// rowClick={rowClick}
|
|
436
|
+
// type={type}
|
|
437
|
+
// hideLink={hideLink}
|
|
438
|
+
// path={getPath}
|
|
439
|
+
// dataTheme={dataTheme}
|
|
440
|
+
// link={link}
|
|
441
|
+
// />
|
|
442
|
+
// ) : (
|
|
443
|
+
// <Cell dataKey={field} dataTheme={dataTheme} className={` ${classes.cellClass}`} />
|
|
444
|
+
// )}
|
|
445
|
+
// </Column>
|
|
446
|
+
// ))
|
|
447
|
+
// ),
|
|
448
|
+
// [columns, dataTheme]
|
|
449
|
+
// );
|
|
337
450
|
const columnsRendered: React.ReactElement[] = useMemo(
|
|
338
451
|
() =>
|
|
339
|
-
(columns ?? [])
|
|
340
|
-
(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
{
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
onResize={handleColumnWidth}
|
|
381
|
-
fixed={child.fixed}
|
|
382
|
-
>
|
|
383
|
-
<HeaderCell
|
|
384
|
-
dataTheme={dataTheme}
|
|
385
|
-
verticalAlign={'middle'}
|
|
386
|
-
className={` ${classes.headerClass}`}
|
|
387
|
-
sortKey={child.sortKey}
|
|
388
|
-
renderSortIcon={renderSortIcon}
|
|
389
|
-
>
|
|
390
|
-
{child.title}
|
|
391
|
-
</HeaderCell>
|
|
392
|
-
{child.customCell || child.link ? (
|
|
393
|
-
<CustomTableCell
|
|
394
|
-
renderCell={child.renderCell}
|
|
395
|
-
dataKey={child.field}
|
|
396
|
-
dataTheme={dataTheme}
|
|
397
|
-
type={child.type}
|
|
398
|
-
path={child.getPath}
|
|
399
|
-
link={child.link}
|
|
400
|
-
/>
|
|
401
|
-
) : (
|
|
402
|
-
<Cell
|
|
403
|
-
className={` ${classes.cellClass}`}
|
|
404
|
-
dataKey={child.field}
|
|
405
|
-
dataTheme={dataTheme}
|
|
406
|
-
/>
|
|
407
|
-
)}
|
|
408
|
-
</Column>
|
|
409
|
-
))}
|
|
410
|
-
</>
|
|
411
|
-
</ColumnGroup>
|
|
412
|
-
) : (
|
|
413
|
-
<Column
|
|
414
|
-
key={title}
|
|
415
|
-
sortable={sortable}
|
|
416
|
-
width={colWidth ?? COLUMN_WIDTH}
|
|
417
|
-
resizable={resizable}
|
|
418
|
-
align={align}
|
|
419
|
-
fixed={fixed}
|
|
420
|
-
onResize={handleColumnWidth}
|
|
421
|
-
>
|
|
422
|
-
<HeaderCell
|
|
423
|
-
dataTheme={dataTheme}
|
|
424
|
-
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
425
|
-
className={` ${classes.headerClass}`}
|
|
426
|
-
sortKey={sortKey}
|
|
427
|
-
renderSortIcon={renderSortIcon}
|
|
452
|
+
(columns ?? [])
|
|
453
|
+
.map(
|
|
454
|
+
({
|
|
455
|
+
title,
|
|
456
|
+
field,
|
|
457
|
+
resizable,
|
|
458
|
+
sortable,
|
|
459
|
+
colWidth,
|
|
460
|
+
align,
|
|
461
|
+
grouped,
|
|
462
|
+
groupHeader,
|
|
463
|
+
fixed,
|
|
464
|
+
children,
|
|
465
|
+
customCell,
|
|
466
|
+
renderCell,
|
|
467
|
+
isVisible,
|
|
468
|
+
link,
|
|
469
|
+
getPath,
|
|
470
|
+
rowClick,
|
|
471
|
+
sortKey,
|
|
472
|
+
type,
|
|
473
|
+
hideLink
|
|
474
|
+
}) =>
|
|
475
|
+
isVisible ? (
|
|
476
|
+
grouped ? (
|
|
477
|
+
<ColumnGroup
|
|
478
|
+
header={groupHeader}
|
|
479
|
+
fixed={fixed}
|
|
480
|
+
align={align}
|
|
481
|
+
verticalAlign="middle"
|
|
482
|
+
groupHeaderHeight={40}
|
|
483
|
+
>
|
|
484
|
+
{children?.map(child => (
|
|
485
|
+
<Column
|
|
486
|
+
key={child.title}
|
|
487
|
+
sortable={child.sortable}
|
|
488
|
+
width={child.colWidth ?? COLUMN_WIDTH}
|
|
489
|
+
resizable={child.resizable}
|
|
490
|
+
align={child.align}
|
|
491
|
+
onResize={handleColumnWidth}
|
|
492
|
+
fixed={child.fixed}
|
|
428
493
|
>
|
|
429
|
-
|
|
430
|
-
</HeaderCell>
|
|
431
|
-
{customCell || link ? (
|
|
432
|
-
<CustomTableCell
|
|
433
|
-
renderCell={renderCell}
|
|
434
|
-
dataKey={field}
|
|
435
|
-
rowClick={rowClick}
|
|
436
|
-
type={type}
|
|
437
|
-
hideLink={hideLink}
|
|
438
|
-
path={getPath}
|
|
439
|
-
dataTheme={dataTheme}
|
|
440
|
-
link={link}
|
|
441
|
-
/>
|
|
442
|
-
) : (
|
|
443
|
-
<Cell
|
|
444
|
-
dataKey={field}
|
|
494
|
+
<HeaderCell
|
|
445
495
|
dataTheme={dataTheme}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
496
|
+
verticalAlign="middle"
|
|
497
|
+
className={` ${classes.headerClass}`}
|
|
498
|
+
sortKey={child.sortKey}
|
|
499
|
+
renderSortIcon={renderSortIcon}
|
|
500
|
+
>
|
|
501
|
+
{child.title}
|
|
502
|
+
</HeaderCell>
|
|
503
|
+
{child.customCell || child.link ? (
|
|
504
|
+
<CustomTableCell
|
|
505
|
+
renderCell={child.renderCell}
|
|
506
|
+
dataKey={child.field}
|
|
507
|
+
dataTheme={dataTheme}
|
|
508
|
+
type={child.type}
|
|
509
|
+
path={child.getPath}
|
|
510
|
+
link={child.link}
|
|
511
|
+
/>
|
|
512
|
+
) : (
|
|
513
|
+
<Cell
|
|
514
|
+
className={` ${classes.cellClass}`}
|
|
515
|
+
dataKey={child.field}
|
|
516
|
+
dataTheme={dataTheme}
|
|
517
|
+
/>
|
|
518
|
+
)}
|
|
519
|
+
</Column>
|
|
520
|
+
))}
|
|
521
|
+
</ColumnGroup>
|
|
522
|
+
) : (
|
|
523
|
+
<Column
|
|
524
|
+
key={title}
|
|
525
|
+
sortable={sortable}
|
|
526
|
+
width={colWidth ?? COLUMN_WIDTH}
|
|
527
|
+
resizable={resizable}
|
|
528
|
+
align={align}
|
|
529
|
+
fixed={fixed}
|
|
530
|
+
onResize={handleColumnWidth}
|
|
531
|
+
>
|
|
532
|
+
<HeaderCell
|
|
533
|
+
dataTheme={dataTheme}
|
|
534
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
535
|
+
className={` ${classes.headerClass}`}
|
|
536
|
+
sortKey={sortKey}
|
|
537
|
+
renderSortIcon={renderSortIcon}
|
|
538
|
+
>
|
|
539
|
+
{title}
|
|
540
|
+
</HeaderCell>
|
|
541
|
+
{customCell || link ? (
|
|
542
|
+
<CustomTableCell
|
|
543
|
+
renderCell={renderCell}
|
|
544
|
+
dataKey={field}
|
|
545
|
+
rowClick={rowClick}
|
|
546
|
+
type={type}
|
|
547
|
+
hideLink={hideLink}
|
|
548
|
+
path={getPath}
|
|
549
|
+
dataTheme={dataTheme}
|
|
550
|
+
link={link}
|
|
551
|
+
/>
|
|
552
|
+
) : (
|
|
553
|
+
<Cell
|
|
554
|
+
dataKey={field}
|
|
555
|
+
dataTheme={dataTheme}
|
|
556
|
+
className={` ${classes.cellClass}`}
|
|
557
|
+
/>
|
|
558
|
+
)}
|
|
559
|
+
</Column>
|
|
560
|
+
)
|
|
561
|
+
) : (
|
|
562
|
+
<></>
|
|
563
|
+
) // ✅ Fix: Return `null` instead of `false`
|
|
454
564
|
)
|
|
455
|
-
|
|
565
|
+
.filter(Boolean), // ✅ Fix: Remove `undefined` and `false` elements
|
|
456
566
|
[columns, dataTheme]
|
|
457
567
|
);
|
|
458
568
|
|
|
@@ -466,7 +576,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
466
576
|
key={tableKey}
|
|
467
577
|
tableKey={tableKey}
|
|
468
578
|
data={data}
|
|
469
|
-
tableBodyRef={tableBodyRef}
|
|
579
|
+
tableBodyRef={tableBodyRef as React.RefObject<HTMLDivElement>}
|
|
470
580
|
dataTheme={dataTheme}
|
|
471
581
|
wordWrap={wordWrap}
|
|
472
582
|
autoHeight={autoHeight}
|
|
@@ -88,7 +88,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
88
88
|
const [checkedKeys, setCheckedKeys] = useState<(number | string)[]>([]);
|
|
89
89
|
const dataTheme = useMemo(() => localStorage.getItem('theme') ?? theme, [theme]);
|
|
90
90
|
const [isOpen, setIsOpen] = useState(false);
|
|
91
|
-
const prevColumns = useRef<any | null>();
|
|
91
|
+
const prevColumns = useRef<any | null>(null);
|
|
92
92
|
const tableBodyRef = useRef<HTMLDivElement>(null);
|
|
93
93
|
const handleSortColumn = useCallback(
|
|
94
94
|
(sortColumn: any, sortType: any) => {
|
|
@@ -445,7 +445,7 @@ const QbsTable: React.FC<QbsTableProps> = ({
|
|
|
445
445
|
key={tableKey}
|
|
446
446
|
tableKey={tableKey}
|
|
447
447
|
data={data}
|
|
448
|
-
tableBodyRef={tableBodyRef}
|
|
448
|
+
tableBodyRef={tableBodyRef as React.RefObject<HTMLDivElement>}
|
|
449
449
|
dataTheme={dataTheme}
|
|
450
450
|
wordWrap={wordWrap}
|
|
451
451
|
autoHeight={autoHeight}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import flatten from 'lodash/flatten';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import * as ReactIs from 'react-is';
|
|
3
|
-
import flatten from 'lodash/flatten';
|
|
4
4
|
import ColumnGroup from '../ColumnGroup';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -11,7 +11,7 @@ import ColumnGroup from '../ColumnGroup';
|
|
|
11
11
|
function getTableColumns(children) {
|
|
12
12
|
const childrenArray = Array.isArray(children) ? children : [children];
|
|
13
13
|
|
|
14
|
-
const flattenColumns = flatten(childrenArray).map((column:
|
|
14
|
+
const flattenColumns = flatten(childrenArray).map((column: any) => {
|
|
15
15
|
// If the column is a group, we need to get the columns from the children.
|
|
16
16
|
if (column?.type === ColumnGroup) {
|
|
17
17
|
const {
|
|
@@ -21,7 +21,7 @@ function getTableColumns(children) {
|
|
|
21
21
|
fixed,
|
|
22
22
|
verticalAlign,
|
|
23
23
|
groupHeaderHeight
|
|
24
|
-
} = column?.props;
|
|
24
|
+
} = column?.props as any;
|
|
25
25
|
|
|
26
26
|
const childColumns = getTableColumns(groupChildren);
|
|
27
27
|
|
|
@@ -56,7 +56,7 @@ function getTableColumns(children) {
|
|
|
56
56
|
});
|
|
57
57
|
} else if (ReactIs.isFragment(column)) {
|
|
58
58
|
// If the column is a fragment, we need to get the columns from the children.
|
|
59
|
-
return getTableColumns(column.props?.children);
|
|
59
|
+
return getTableColumns(column.props?.children as any);
|
|
60
60
|
} else if (Array.isArray(column)) {
|
|
61
61
|
// If the column is an array, need check item in the array.
|
|
62
62
|
return getTableColumns(column);
|
package/src/utils/useAffix.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import React, { useRef, useCallback, useEffect } from 'react';
|
|
2
|
-
import getHeight from 'dom-lib/getHeight';
|
|
3
1
|
import addStyle from 'dom-lib/addStyle';
|
|
4
|
-
import
|
|
2
|
+
import getHeight from 'dom-lib/getHeight';
|
|
5
3
|
import on from 'dom-lib/on';
|
|
6
|
-
import
|
|
4
|
+
import removeStyle from 'dom-lib/removeStyle';
|
|
5
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
6
|
+
import type { ElementOffset, ListenerCallback } from '../@types/common';
|
|
7
|
+
import type { ScrollbarInstance } from '../Scrollbar';
|
|
7
8
|
import isNumberOrTrue from './isNumberOrTrue';
|
|
9
|
+
import toggleClass from './toggleClass';
|
|
8
10
|
import useUpdateEffect from './useUpdateEffect';
|
|
9
|
-
import type { ListenerCallback, ElementOffset } from '../@types/common';
|
|
10
|
-
import type { ScrollbarInstance } from '../Scrollbar';
|
|
11
11
|
|
|
12
12
|
interface AffixProps {
|
|
13
13
|
getTableHeight: () => number;
|
|
14
14
|
contentHeight: React.MutableRefObject<number>;
|
|
15
15
|
affixHeader?: boolean | number;
|
|
16
16
|
affixHorizontalScrollbar?: boolean | number;
|
|
17
|
-
tableOffset: React.RefObject<ElementOffset>;
|
|
18
|
-
headerOffset: React.RefObject<ElementOffset>;
|
|
17
|
+
tableOffset: React.RefObject<ElementOffset | null>;
|
|
18
|
+
headerOffset: React.RefObject<ElementOffset | null>;
|
|
19
19
|
headerHeight: number;
|
|
20
|
-
scrollbarXRef: React.RefObject<ScrollbarInstance>;
|
|
21
|
-
affixHeaderWrapperRef: React.RefObject<HTMLDivElement>;
|
|
20
|
+
scrollbarXRef: React.RefObject<ScrollbarInstance | null>;
|
|
21
|
+
affixHeaderWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const useAffix = (props: AffixProps) => {
|
|
@@ -34,7 +34,7 @@ const useAffix = (props: AffixProps) => {
|
|
|
34
34
|
affixHeaderWrapperRef
|
|
35
35
|
} = props;
|
|
36
36
|
|
|
37
|
-
const scrollListener = useRef<ListenerCallback>();
|
|
37
|
+
const scrollListener = useRef<ListenerCallback>(null);
|
|
38
38
|
const handleAffixHorizontalScrollbar = useCallback(() => {
|
|
39
39
|
const scrollY = window.scrollY || window.pageYOffset;
|
|
40
40
|
const windowHeight = getHeight(window);
|
|
@@ -32,8 +32,8 @@ interface CellDescriptorProps<Row> {
|
|
|
32
32
|
onSortColumn?: (dataKey: string, sortType?: SortType) => void;
|
|
33
33
|
onHeaderCellResize?: (width: number, dataKey: string) => void;
|
|
34
34
|
rowHeight?: number | ((rowData?: Row) => number);
|
|
35
|
-
mouseAreaRef: React.RefObject<HTMLDivElement>;
|
|
36
|
-
tableRef: React.RefObject<HTMLDivElement>;
|
|
35
|
+
mouseAreaRef: React.RefObject<HTMLDivElement | null>;
|
|
36
|
+
tableRef: React.RefObject<HTMLDivElement | null>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
interface CellDescriptor {
|
|
@@ -68,7 +68,7 @@ const useCellDescriptor = <Row extends RowDataType>(
|
|
|
68
68
|
rowHeight,
|
|
69
69
|
onSortColumn,
|
|
70
70
|
onHeaderCellResize,
|
|
71
|
-
prefix
|
|
71
|
+
prefix
|
|
72
72
|
} = props;
|
|
73
73
|
|
|
74
74
|
const [sortType, setSortType] = useControlled(sortTypeProp, defaultSortType);
|
|
@@ -196,7 +196,7 @@ const useCellDescriptor = <Row extends RowDataType>(
|
|
|
196
196
|
const count = columns.length;
|
|
197
197
|
const { totalFlexGrow, totalWidth } = getTotalByColumns(columns);
|
|
198
198
|
|
|
199
|
-
React.Children.forEach(columns, (column: React.ReactElement<ColumnProps>, index) => {
|
|
199
|
+
React.Children.forEach(columns as any, (column: React.ReactElement<ColumnProps>, index) => {
|
|
200
200
|
if (React.isValidElement(column)) {
|
|
201
201
|
const columnChildren = column.props.children as React.ReactNode[];
|
|
202
202
|
const columnProps = getColumnProps(column);
|
package/src/utils/usePosition.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import React, { useCallback, useRef } from 'react';
|
|
2
1
|
import addStyle, { CSSProperty } from 'dom-lib/addStyle';
|
|
2
|
+
import React, { useCallback, useRef } from 'react';
|
|
3
|
+
import type { RowDataType } from '../@types/common';
|
|
3
4
|
import { SCROLLBAR_WIDTH } from '../constants';
|
|
5
|
+
import defer from './defer';
|
|
6
|
+
import isSupportTouchEvent from './isSupportTouchEvent';
|
|
4
7
|
import toggleClass from './toggleClass';
|
|
5
8
|
import useUpdateEffect from './useUpdateEffect';
|
|
6
|
-
import type { RowDataType } from '../@types/common';
|
|
7
|
-
import isSupportTouchEvent from './isSupportTouchEvent';
|
|
8
|
-
import defer from './defer';
|
|
9
9
|
|
|
10
10
|
interface PositionProps {
|
|
11
11
|
data: readonly RowDataType[];
|
|
12
12
|
height: number;
|
|
13
13
|
tableWidth: React.MutableRefObject<number>;
|
|
14
|
-
tableRef: React.RefObject<HTMLDivElement>;
|
|
14
|
+
tableRef: React.RefObject<HTMLDivElement | null>;
|
|
15
15
|
prefix: (str: string) => string;
|
|
16
16
|
translateDOMPositionXY: React.MutableRefObject<any>;
|
|
17
|
-
wheelWrapperRef: React.RefObject<HTMLDivElement>;
|
|
18
|
-
headerWrapperRef: React.RefObject<HTMLDivElement>;
|
|
19
|
-
affixHeaderWrapperRef: React.RefObject<HTMLDivElement>;
|
|
20
|
-
tableHeaderRef: React.RefObject<HTMLDivElement>;
|
|
17
|
+
wheelWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
18
|
+
headerWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
19
|
+
affixHeaderWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
20
|
+
tableHeaderRef: React.RefObject<HTMLDivElement | null>;
|
|
21
21
|
scrollX: React.MutableRefObject<number>;
|
|
22
22
|
scrollY: React.MutableRefObject<number>;
|
|
23
23
|
contentWidth: React.MutableRefObject<number>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { useRef, useCallback, useState, useEffect } from 'react';
|
|
2
|
-
import WheelHandler from 'dom-lib/WheelHandler';
|
|
3
|
-
import scrollLeft from 'dom-lib/scrollLeft';
|
|
4
|
-
import scrollTop from 'dom-lib/scrollTop';
|
|
5
1
|
import on from 'dom-lib/on';
|
|
6
2
|
import removeStyle from 'dom-lib/removeStyle';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import type { ScrollbarInstance } from '../Scrollbar';
|
|
3
|
+
import scrollLeft from 'dom-lib/scrollLeft';
|
|
4
|
+
import scrollTop from 'dom-lib/scrollTop';
|
|
5
|
+
import WheelHandler from 'dom-lib/WheelHandler';
|
|
6
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
12
7
|
import type { ListenerCallback, RowDataType } from '../@types/common';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
8
|
+
import { BEZIER, SCROLLBAR_WIDTH, TRANSITION_DURATION } from '../constants';
|
|
9
|
+
import type { ScrollbarInstance } from '../Scrollbar';
|
|
15
10
|
import defer from './defer';
|
|
11
|
+
import flushSync from './flushSync';
|
|
12
|
+
import isSupportTouchEvent from './isSupportTouchEvent';
|
|
13
|
+
import { cancelAnimationTimeout, requestAnimationTimeout } from './requestAnimationTimeout';
|
|
14
|
+
import useMount from './useMount';
|
|
15
|
+
import useUpdateEffect from './useUpdateEffect';
|
|
16
16
|
|
|
17
17
|
// Inertial sliding start time threshold
|
|
18
18
|
const momentumTimeThreshold = 300;
|
|
@@ -29,11 +29,11 @@ interface ScrollListenerProps {
|
|
|
29
29
|
headerHeight: number;
|
|
30
30
|
autoHeight?: boolean;
|
|
31
31
|
tableBodyRef: React.RefObject<HTMLDivElement>;
|
|
32
|
-
scrollbarXRef: React.RefObject<ScrollbarInstance>;
|
|
33
|
-
scrollbarYRef: React.RefObject<ScrollbarInstance>;
|
|
32
|
+
scrollbarXRef: React.RefObject<ScrollbarInstance | null>;
|
|
33
|
+
scrollbarYRef: React.RefObject<ScrollbarInstance | null>;
|
|
34
34
|
disabledScroll?: boolean;
|
|
35
35
|
loading?: boolean;
|
|
36
|
-
tableRef: React.RefObject<HTMLDivElement>;
|
|
36
|
+
tableRef: React.RefObject<HTMLDivElement | null>;
|
|
37
37
|
contentWidth: React.MutableRefObject<number>;
|
|
38
38
|
tableWidth: React.MutableRefObject<number>;
|
|
39
39
|
scrollY: React.MutableRefObject<number>;
|
|
@@ -109,10 +109,10 @@ const useScrollListener = (props: ScrollListenerProps) => {
|
|
|
109
109
|
tableKey
|
|
110
110
|
} = props;
|
|
111
111
|
|
|
112
|
-
const wheelListener = useRef<ListenerCallback>();
|
|
113
|
-
const touchStartListener = useRef<ListenerCallback>();
|
|
114
|
-
const touchMoveListener = useRef<ListenerCallback>();
|
|
115
|
-
const touchEndListener = useRef<ListenerCallback>();
|
|
112
|
+
const wheelListener = useRef<ListenerCallback>(null);
|
|
113
|
+
const touchStartListener = useRef<ListenerCallback>(null);
|
|
114
|
+
const touchMoveListener = useRef<ListenerCallback>(null);
|
|
115
|
+
const touchEndListener = useRef<ListenerCallback>(null);
|
|
116
116
|
const [isChildFocused, setIsChildFocused] = useState(false);
|
|
117
117
|
|
|
118
118
|
const [isScrolling, setScrolling] = useState(false);
|
|
@@ -247,7 +247,7 @@ const useScrollListener = (props: ScrollListenerProps) => {
|
|
|
247
247
|
[handleWheel, scrollbarXRef, scrollbarYRef]
|
|
248
248
|
);
|
|
249
249
|
|
|
250
|
-
const wheelHandler = useRef<WheelHandler | null>();
|
|
250
|
+
const wheelHandler = useRef<WheelHandler | null>(null);
|
|
251
251
|
|
|
252
252
|
// Stop unending scrolling and remove transition
|
|
253
253
|
const stopScroll = useCallback(() => {
|
|
@@ -16,8 +16,8 @@ interface TableDimensionProps<Row, Key> {
|
|
|
16
16
|
rowHeight: number | ((rowData?: Row) => number);
|
|
17
17
|
height: number;
|
|
18
18
|
minHeight: number;
|
|
19
|
-
tableRef?: React.RefObject<HTMLDivElement>;
|
|
20
|
-
headerWrapperRef?: React.RefObject<HTMLDivElement>;
|
|
19
|
+
tableRef?: React.RefObject<HTMLDivElement | null>;
|
|
20
|
+
headerWrapperRef?: React.RefObject<HTMLDivElement | null>;
|
|
21
21
|
width?: number;
|
|
22
22
|
prefix: (str: string) => string;
|
|
23
23
|
affixHeader?: boolean | number;
|
|
@@ -74,8 +74,8 @@ const useTableDimension = <Row extends RowDataType, Key>(props: TableDimensionPr
|
|
|
74
74
|
const tableWidth = useRef(widthProp || 0);
|
|
75
75
|
const tableHeight = useRef(heightProp || 0);
|
|
76
76
|
const columnCount = useRef(0);
|
|
77
|
-
const resizeObserver = useRef<ResizeObserver>();
|
|
78
|
-
const containerResizeObserver = useRef<ResizeObserver>();
|
|
77
|
+
const resizeObserver = useRef<ResizeObserver>(null);
|
|
78
|
+
const containerResizeObserver = useRef<ResizeObserver>(null);
|
|
79
79
|
const headerOffset = useRef<ElementOffset | null>(null);
|
|
80
80
|
const tableOffset = useRef<ElementOffset | null>(null);
|
|
81
81
|
|