-
-
Notifications
You must be signed in to change notification settings - Fork 604
/
Copy pathfixUtil.ts
100 lines (86 loc) · 2.86 KB
/
fixUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type {
ColumnGroupType,
ColumnType,
Direction,
FixedType,
StickyOffsets,
} from '../interface';
export interface FixedInfo {
fixLeft: number | false;
fixRight: number | false;
lastFixLeft: boolean;
firstFixRight: boolean;
// For Rtl Direction
lastFixRight: boolean;
firstFixLeft: boolean;
isSticky: boolean;
}
function hasColumnChildren<RecordType>(
column: ColumnType<RecordType> | ColumnGroupType<RecordType>,
): boolean {
// no children only
if (!(column as ColumnGroupType<RecordType>)?.children) {
return true;
}
if (
(column as ColumnGroupType<RecordType>)?.children &&
(column as ColumnGroupType<RecordType>)?.children.length > 0
) {
return (column as ColumnGroupType<RecordType>)?.children.some(children =>
hasColumnChildren(children),
);
}
}
export function getCellFixedInfo<RecordType = any>(
colStart: number,
colEnd: number,
columns: readonly { fixed?: FixedType }[],
stickyOffsets: StickyOffsets,
direction: Direction,
curColumns?: ColumnType<RecordType> | ColumnGroupType<RecordType>,
): FixedInfo {
const startColumn = columns[colStart] || {};
const endColumn = columns[colEnd] || {};
let fixLeft: number;
let fixRight: number;
// RTL layout calculation logic processing
if (startColumn.fixed === 'left' || endColumn.fixed === 'left') {
fixLeft = stickyOffsets.left[direction === 'rtl' ? colEnd : colStart];
} else if (endColumn.fixed === 'right' || startColumn.fixed === 'right') {
fixRight = stickyOffsets.right[direction === 'rtl' ? colStart : colEnd];
}
let lastFixLeft: boolean = false;
let firstFixRight: boolean = false;
let lastFixRight: boolean = false;
let firstFixLeft: boolean = false;
const nextColumn = columns[colEnd + 1];
const prevColumn = columns[colStart - 1];
// iff all children of a cell have exactly one child, then onlyChildren is true
const hasChildren = hasColumnChildren(curColumns);
// no children only
const canLastFix = !(curColumns as ColumnGroupType<RecordType>)?.children;
if (direction === 'rtl') {
if (fixLeft !== undefined) {
const prevFixLeft = prevColumn && prevColumn.fixed === 'left';
firstFixLeft = !prevFixLeft && (canLastFix || hasChildren);
} else if (fixRight !== undefined) {
const nextFixRight = nextColumn && nextColumn.fixed === 'right';
lastFixRight = !nextFixRight && (canLastFix || hasChildren);
}
} else if (fixLeft !== undefined) {
const nextFixLeft = nextColumn && nextColumn.fixed === 'left';
lastFixLeft = !nextFixLeft && canLastFix;
} else if (fixRight !== undefined) {
const prevFixRight = prevColumn && prevColumn.fixed === 'right';
firstFixRight = !prevFixRight && (canLastFix || hasChildren);
}
return {
fixLeft,
fixRight,
lastFixLeft,
firstFixRight,
lastFixRight,
firstFixLeft,
isSticky: stickyOffsets.isSticky,
};
}