All files / src/components/u-table-view.vue createTableHeadExporter.js

2.85% Statements 1/35
0% Branches 0/17
0% Functions 0/7
3.44% Lines 1/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 541x                                                                                                          
export const createTableHeaderExportHelper = (rowCount) => {
    const emptyPlaceholder = {};
    let headContents = Array.from({ length: rowCount }, () => []);
 
    let rowIndex = 0;
    let colIndex = 0;
    let ejectFlag = false;
 
    return {
        setCell,
        eject,
    };
 
    function setCell(content, isCurrentRowEnd = false, rowSpan = 1, colSpan = 1) {
        if (ejectFlag) { return; }
        headContents[rowIndex][colIndex] = content;
        for (let i = 0; i < rowSpan; ++i) {
            for (let j = 0; j < colSpan; ++j) {
                const rIdx = rowIndex + i;
                const cIdx = colIndex + j;
                if (i === 0 && j === 0) {
                    headContents[rIdx][cIdx] = content;
                } else {
                    headContents[rIdx][cIdx] = emptyPlaceholder;
                }
            }
        }
 
        // move rowIndex and colIndex to the right place
        let searchColStart = isCurrentRowEnd ? 0 : colIndex + colSpan;
        const searchRowStart = isCurrentRowEnd ? rowIndex + 1 : rowIndex;
        while (headContents[searchRowStart] && headContents[searchRowStart][searchColStart] === emptyPlaceholder)
            searchColStart++;
 
        const cols = Array.from({ length: colSpan }, (_, i) => i + colIndex);
 
        colIndex = searchColStart;
        rowIndex = searchRowStart;
 
        return cols;
    }
 
    function eject() {
        ejectFlag = true;
 
        const matrix = headContents.map((arr) =>
            arr.map((v) => (v === emptyPlaceholder ? null : v)),
        );
        headContents = null;
 
        return matrix;
      }
};