all files / common/utils/ table-utils.js

80.77% Statements 42/52
59.38% Branches 19/32
91.67% Functions 11/12
80.39% Lines 41/51
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   364×   59×   129×   186×                         47× 47× 47×   43× 43×     43× 43×     43× 43× 43×           600× 600× 600×        
define(["require", "exports", "./block", "../../common/constant"], function (require, exports, block_1, constants) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function toDomCol(dataCol, rowNumberEnabled) {
        return rowNumberEnabled ? dataCol + 1 : dataCol;
    }
    exports.toDomCol = toDomCol;
    function toDomRow(dataRow, headerEnabled) {
        return headerEnabled ? dataRow + 1 : dataRow;
    }
    exports.toDomRow = toDomRow;
    function toModelRow(domRow, headerEnabled) {
        return headerEnabled ? domRow - 1 : domRow;
    }
    exports.toModelRow = toModelRow;
    function getDataCell(tableElement, row, col) {
        return tableElement.querySelector("td[data-row=\"" + row + "\"][data-col=\"" + col + "\"]")
            || tableElement.querySelector("th[data-row=\"" + row + "\"][data-col=\"" + col + "\"]");
    }
    exports.getDataCell = getDataCell;
    function getHeaderCell(tableElement, col) {
        var thead = tableElement.tHead;
        if (!thead) {
            return null;
        }
        var cell = thead.querySelector("th[data-row=\"0\"][data-col=\"" + col + "\"]");
        if (!cell) {
            cell = thead.querySelectorAll('th')[col];
        }
        return cell || null;
    }
    exports.getHeaderCell = getHeaderCell;
    function doesHtmlHasTable(html, text) {
        var htmlHasTable = !!(html && /<table[\s\S]*?>[\s\S]*?<\/table>/i.test(html));
        var textLooksTabular = !!(text && (text.indexOf('\t') !== -1 || /\r?\n.*\t/.test(text)));
        return htmlHasTable || textLooksTabular;
    }
    exports.doesHtmlHasTable = doesHtmlHasTable;
    function getTableElements(blockId, rootEditorElement, blocks) {
        var blockEl = rootEditorElement.querySelector("#" + blockId);
        Iif (!blockEl) {
            return null;
        }
        var table = blockEl.querySelector('table.e-table-element');
        Iif (!table) {
            return null;
        }
        var block = block_1.getBlockModelById(blockId, blocks);
        var props = (block && block.properties) || {};
        return { table: table, props: props };
    }
    exports.getTableElements = getTableElements;
    function focusAllCellsInTable(tableEl) {
        var cells = tableEl.querySelectorAll('td[role="gridcell"]');
        cells.forEach(function (cell) {
            Iif (cell.classList.contains('e-row-number')) {
                return;
            }
            cell.classList.add(constants.TABLE_CELL_FOCUS);
        });
    }
    exports.focusAllCellsInTable = focusAllCellsInTable;
    function removeFocusFromAllCells(table) {
        var focusedCells = table.querySelectorAll('.' + constants.TABLE_CELL_FOCUS);
        Eif (focusedCells) {
            focusedCells.forEach(function (cell) { return cell.classList.remove(constants.TABLE_CELL_FOCUS); });
        }
    }
    exports.removeFocusFromAllCells = removeFocusFromAllCells;
});