@itrocks/table 0.8.0 → 0.8.2

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.
Files changed (2) hide show
  1. package/freeze.js +28 -13
  2. package/package.json +2 -2
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 ? ((parent instanceof HTMLHtmlElement) ? window : parent) : undefined;
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, bottom = .0, previousBottom = table.element.getBoundingClientRect().bottom;
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, top = .0, previousTop = table.element.getBoundingClientRect().top - table.element.scrollTop;
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
- let counter = 1, left = .0, previousLeft = table.element.getBoundingClientRect().left;
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 ?? tableElement.tBodies[0]?.rows[0]?.cells;
189
- const left = this.leftColumnCount && cells?.[this.leftColumnCount - 1]
190
- ? cells[this.leftColumnCount - 1].getBoundingClientRect().right : rect.left;
191
- const right = this.rightColumnCount && cells?.[cells.length - this.rightColumnCount]
192
- ? cells[cells.length - this.rightColumnCount].getBoundingClientRect().left : rect.right;
193
- const top = tableElement.tHead?.lastElementChild?.firstElementChild?.getBoundingClientRect().bottom ?? rect.top;
194
- const bottom = tableElement.tFoot?.firstElementChild?.firstElementChild?.getBoundingClientRect().top ?? rect.bottom;
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
@@ -51,7 +51,7 @@
51
51
  "url": "git+https://github.com/itrocks-ts/table.git"
52
52
  },
53
53
  "scripts": {
54
- "build": "tsc && sass --no-source-map demo:demo src/column-add.scss:column-add.css && node ../prepare-module/prepare-module.js"
54
+ "build": "tsc && sass --no-source-map src/column-add.scss:column-add.css && node ../prepare-module/prepare-module.js && tsc -p tsconfig.demo.json && sass --no-source-map demo:demo"
55
55
  },
56
- "version": "0.8.0"
56
+ "version": "0.8.2"
57
57
  }