@itrocks/table 0.8.0 → 0.8.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/freeze.js +28 -13
- package/package.json +1 -1
package/freeze.js
CHANGED
|
@@ -22,8 +22,9 @@ export class TableFreeze extends Plugin {
|
|
|
22
22
|
const styles = this.of.styleSheet;
|
|
23
23
|
for (const rule of this.rules) {
|
|
24
24
|
const index = styles.indexOf(rule);
|
|
25
|
-
if (index >= 0)
|
|
25
|
+
if (index >= 0) {
|
|
26
26
|
styles.splice(index, 1);
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
// Measure natural positions, including header-backed columns that were previously sticky.
|
|
29
30
|
this.of.refreshStyleSheets();
|
|
@@ -34,7 +35,9 @@ export class TableFreeze extends Plugin {
|
|
|
34
35
|
while (parent && (parent.scrollHeight <= parent.clientHeight)) {
|
|
35
36
|
parent = parent.parentElement;
|
|
36
37
|
}
|
|
37
|
-
return parent
|
|
38
|
+
return parent
|
|
39
|
+
? ((parent instanceof HTMLHtmlElement) ? window : parent)
|
|
40
|
+
: undefined;
|
|
38
41
|
}
|
|
39
42
|
countLeftColumns() {
|
|
40
43
|
let count = 0;
|
|
@@ -54,7 +57,9 @@ export class TableFreeze extends Plugin {
|
|
|
54
57
|
const table = this.of;
|
|
55
58
|
if (!table.element.tFoot?.rows.length)
|
|
56
59
|
return;
|
|
57
|
-
let counter = 1
|
|
60
|
+
let counter = 1;
|
|
61
|
+
let bottom = .0;
|
|
62
|
+
let previousBottom = table.element.getBoundingClientRect().bottom;
|
|
58
63
|
for (const row of Array.from(table.element.tFoot.querySelectorAll(':scope > tr')).reverse()) {
|
|
59
64
|
const actualBottom = row.getBoundingClientRect().bottom;
|
|
60
65
|
bottom += previousBottom - actualBottom;
|
|
@@ -79,7 +84,9 @@ export class TableFreeze extends Plugin {
|
|
|
79
84
|
if (!table.element.tHead?.rows.length)
|
|
80
85
|
return;
|
|
81
86
|
// Header measurements are in scrolled coordinates after refresh removes the sticky rules.
|
|
82
|
-
let counter = 1
|
|
87
|
+
let counter = 1;
|
|
88
|
+
let top = .0;
|
|
89
|
+
let previousTop = table.element.getBoundingClientRect().top - table.element.scrollTop;
|
|
83
90
|
table.element.tHead.querySelectorAll(':scope > tr').forEach(row => {
|
|
84
91
|
const actualTop = row.getBoundingClientRect().top;
|
|
85
92
|
top += actualTop - previousTop;
|
|
@@ -96,7 +103,7 @@ export class TableFreeze extends Plugin {
|
|
|
96
103
|
${table.selector} > thead > tr > * {
|
|
97
104
|
position: sticky;
|
|
98
105
|
${zIndex}
|
|
99
|
-
}
|
|
106
|
+
}
|
|
100
107
|
`);
|
|
101
108
|
}
|
|
102
109
|
freezeLeftColumns() {
|
|
@@ -105,7 +112,10 @@ export class TableFreeze extends Plugin {
|
|
|
105
112
|
const table = this.of;
|
|
106
113
|
const bodySel = [];
|
|
107
114
|
const cornerSel = [];
|
|
108
|
-
|
|
115
|
+
// A scrolling table keeps its own bounds fixed while its natural column positions move.
|
|
116
|
+
let counter = 1;
|
|
117
|
+
let left = .0;
|
|
118
|
+
let previousLeft = table.element.getBoundingClientRect().left - table.element.scrollLeft;
|
|
109
119
|
for (const colCell of Array.from(this.columns).slice(0, this.leftColumnCount)) {
|
|
110
120
|
const actualLeft = colCell.getBoundingClientRect().left;
|
|
111
121
|
left += actualLeft - previousLeft;
|
|
@@ -185,13 +195,18 @@ export class TableFreeze extends Plugin {
|
|
|
185
195
|
const tableElement = this.of.element;
|
|
186
196
|
const rect = tableElement.getBoundingClientRect();
|
|
187
197
|
// Cols supply configuration and layout widths; only rendered cells have sticky viewport positions.
|
|
188
|
-
const cells = tableElement.tHead?.rows[0]?.cells
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
198
|
+
const cells = tableElement.tHead?.rows[0]?.cells
|
|
199
|
+
?? tableElement.tBodies[0]?.rows[0]?.cells;
|
|
200
|
+
const left = (this.leftColumnCount && cells?.[this.leftColumnCount - 1])
|
|
201
|
+
? cells[this.leftColumnCount - 1].getBoundingClientRect().right
|
|
202
|
+
: rect.left;
|
|
203
|
+
const right = (this.rightColumnCount && cells?.[cells.length - this.rightColumnCount])
|
|
204
|
+
? cells[cells.length - this.rightColumnCount].getBoundingClientRect().left
|
|
205
|
+
: rect.right;
|
|
206
|
+
const top = tableElement.tHead?.lastElementChild?.firstElementChild?.getBoundingClientRect().bottom
|
|
207
|
+
?? rect.top;
|
|
208
|
+
const bottom = tableElement.tFoot?.firstElementChild?.firstElementChild?.getBoundingClientRect().top
|
|
209
|
+
?? rect.bottom;
|
|
195
210
|
rect.x = left;
|
|
196
211
|
rect.y = top;
|
|
197
212
|
rect.width = Math.max(0, right - left);
|
package/package.json
CHANGED