-
-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathfixUtil.ts
More file actions
102 lines (87 loc) 路 2.86 KB
/
Copy pathfixUtil.ts
File metadata and controls
102 lines (87 loc) 路 2.86 KB
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
101
102
import type { FixedType, StickyOffsets } from '../interface';
export interface FixedInfo {
fixStart: number | false;
fixEnd: number | false;
isSticky: boolean;
// Position info(for shadow usage)
/** `fixed: start` with shadow */
fixedStartShadow?: boolean;
/** `fixed: end` with shadow */
fixedEndShadow?: boolean;
/** Show the shadow when `scrollLeft` arrive for `fixed: start` */
offsetFixedStartShadow?: number;
/** Show the shadow when `scrollLeft` arrive for `fixed: end` */
offsetFixedEndShadow?: number;
/** First sticky column `zIndex` will be larger than next */
zIndex?: number;
/** First sticky column `zIndex` will be smaller than next */
zIndexReverse?: number;
}
function isFixedStart(column: { fixed?: FixedType }) {
return column.fixed === 'start';
}
function isFixedEnd(column: { fixed?: FixedType }) {
return column.fixed === 'end';
}
export function getCellFixedInfo(
colStart: number,
colEnd: number,
columns: readonly { fixed?: FixedType }[],
stickyOffsets: StickyOffsets,
): FixedInfo {
const startColumn = columns[colStart] || {};
const endColumn = columns[colEnd] || {};
let fixStart: number = null;
let fixEnd: number = null;
if (isFixedStart(startColumn) && isFixedStart(endColumn)) {
fixStart = stickyOffsets.start[colStart];
} else if (isFixedEnd(endColumn) && isFixedEnd(startColumn)) {
fixEnd = stickyOffsets.end[colEnd];
}
// check if need to add shadow
let fixedStartShadow = false;
let fixedEndShadow = false;
// Calc `zIndex`.
// first fixed start (start -> end) column `zIndex` should be greater than next column.
// first fixed end (end -> start) column `zIndex` should be greater than next column.
let zIndex = 0;
let zIndexReverse = 0;
if (fixStart !== null) {
fixedStartShadow = !columns[colEnd + 1] || !isFixedStart(columns[colEnd + 1]);
zIndex = columns.length * 2 - colStart; // Fix start always overlay fix end
zIndexReverse = colStart;
}
if (fixEnd !== null) {
fixedEndShadow = !columns[colStart - 1] || !isFixedEnd(columns[colStart - 1]);
zIndex = colEnd;
zIndexReverse = columns.length * 2 - colEnd; // Fix end always overlay fix start
}
// Check if scrollLeft will show the shadow
let offsetFixedStartShadow = 0;
let offsetFixedEndShadow = 0;
if (fixedStartShadow) {
for (let i = 0; i < colStart; i += 1) {
if (!isFixedStart(columns[i])) {
offsetFixedStartShadow += stickyOffsets.widths[i] || 0;
}
}
}
if (fixedEndShadow) {
for (let i = columns.length - 1; i > colEnd; i -= 1) {
if (!isFixedEnd(columns[i])) {
offsetFixedEndShadow += stickyOffsets.widths[i] || 0;
}
}
}
return {
fixStart,
fixEnd,
fixedStartShadow,
fixedEndShadow,
offsetFixedStartShadow,
offsetFixedEndShadow,
isSticky: stickyOffsets.isSticky,
zIndex,
zIndexReverse,
};
}