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;
});
|