fix: improve hidecolumns behaviour
This commit is contained in:
parent
66cbf0c508
commit
9a4f30b811
@ -5,17 +5,26 @@ import * as defer from 'lodash.defer';
|
|||||||
class Overhang {
|
class Overhang {
|
||||||
colSpan;
|
colSpan;
|
||||||
rowSpan;
|
rowSpan;
|
||||||
|
cell;
|
||||||
|
|
||||||
constructor(colSpan, rowSpan) {
|
constructor(colSpan, rowSpan, cell) {
|
||||||
this.colSpan = colSpan;
|
this.colSpan = colSpan;
|
||||||
this.rowSpan = rowSpan;
|
this.rowSpan = rowSpan;
|
||||||
|
this.cell = cell;
|
||||||
|
|
||||||
if (new.target === Overhang)
|
if (new.target === Overhang)
|
||||||
Object.freeze(this);
|
Object.freeze(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
nextLine() {
|
nextLine() {
|
||||||
return new Overhang(this.colSpan, Math.max(0, this.rowSpan - 1));
|
return new Overhang(this.colSpan, Math.max(0, this.rowSpan - 1), this.cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
reduceCol(n) {
|
||||||
|
if (this.colSpan > n)
|
||||||
|
return new Overhang(this.colSpan - n, this.rowSpan, this.cell);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isHole() {
|
isHole() {
|
||||||
@ -57,11 +66,10 @@ export class TableIndices {
|
|||||||
this._table = table;
|
this._table = table;
|
||||||
|
|
||||||
|
|
||||||
let overhangs = new Array();
|
let currentOverhangs = new Array();
|
||||||
let currentRow = 0;
|
let currentRow = 0;
|
||||||
|
|
||||||
for (const rowParent of this._table.rows) {
|
for (const rowParent of this._table.rows) {
|
||||||
let currentOverhangs = Array.from(overhangs);
|
|
||||||
let newOverhangs = new Array();
|
let newOverhangs = new Array();
|
||||||
|
|
||||||
let cellBefore = 0;
|
let cellBefore = 0;
|
||||||
@ -77,17 +85,37 @@ export class TableIndices {
|
|||||||
else
|
else
|
||||||
newOverhangs.push(overhang.nextLine());
|
newOverhangs.push(overhang.nextLine());
|
||||||
|
|
||||||
|
if (DEBUG_MODE > 1)
|
||||||
|
console.log('From overhang', overhang);
|
||||||
|
|
||||||
cellBefore += overhang.colSpan;
|
cellBefore += overhang.colSpan;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentOverhangs = currentOverhangs.slice(i);
|
currentOverhangs = currentOverhangs.slice(i);
|
||||||
|
let remCols = this.colSpan(cell);
|
||||||
|
while (remCols > 0 && currentOverhangs[0]) {
|
||||||
|
let firstOverhang = currentOverhangs[0].reduceCol(this.colSpan(cell));
|
||||||
|
if (firstOverhang) {
|
||||||
|
if (DEBUG_MODE > 1)
|
||||||
|
console.log('Replace first overhang', remCols, currentOverhangs[0], firstOverhang);
|
||||||
|
currentOverhangs[0] = firstOverhang;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (DEBUG_MODE > 1)
|
||||||
|
console.log('Drop first overhang', remCols, currentOverhangs[0], firstOverhang);
|
||||||
|
remCols -= currentOverhangs[0].colSpan;
|
||||||
|
currentOverhangs.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._cellToIndices.set(cell, { row: currentRow, col: cellBefore });
|
this._cellToIndices.set(cell, { row: currentRow, col: cellBefore });
|
||||||
|
|
||||||
let rows = range(currentRow, currentRow + this.rowSpan(cell));
|
let rows = range(currentRow, currentRow + this.rowSpan(cell));
|
||||||
let columns = range(cellBefore, cellBefore + this.colSpan(cell));
|
let columns = range(cellBefore, cellBefore + this.colSpan(cell));
|
||||||
|
|
||||||
if (DEBUG_MODE > 0) {
|
if (DEBUG_MODE > 1) {
|
||||||
|
console.log('Result', rows, columns);
|
||||||
|
|
||||||
cell.dataset.rows = JSON.stringify(rows);
|
cell.dataset.rows = JSON.stringify(rows);
|
||||||
cell.dataset.columns = JSON.stringify(columns);
|
cell.dataset.columns = JSON.stringify(columns);
|
||||||
}
|
}
|
||||||
@ -104,11 +132,14 @@ export class TableIndices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newOverhangs.push(new Overhang(this.colSpan(cell), this.rowSpan(cell) - 1));
|
newOverhangs.push(new Overhang(this.colSpan(cell), this.rowSpan(cell) - 1, cell));
|
||||||
|
|
||||||
|
if (DEBUG_MODE > 1)
|
||||||
|
console.log('From current cell', this.colSpan(cell));
|
||||||
cellBefore += this.colSpan(cell);
|
cellBefore += this.colSpan(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
overhangs = newOverhangs;
|
currentOverhangs = Array.from(newOverhangs);
|
||||||
currentRow++;
|
currentRow++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user