UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

69 lines 2.68 kB
import { TableMap, Fragment } from '../../prosemirror'; export var getColumnPos = function (column, tableNode) { var map = TableMap.get(tableNode); var from = map.positionAt(0, column, tableNode); var to = map.positionAt(map.height - 1, column, tableNode); return { from: from, to: to }; }; export var getRowPos = function (row, tableNode) { var map = TableMap.get(tableNode); var from = map.positionAt(row, 0, tableNode); var to = map.positionAt(row, map.width - 1, tableNode); return { from: from, to: to }; }; export var getTablePos = function (tableNode) { var map = TableMap.get(tableNode); var from = map.positionAt(0, 0, tableNode); var to = map.positionAt(map.height - 1, map.width - 1, tableNode); return { from: from, to: to }; }; export var createTableNode = function (rows, columns, schema) { var _a = schema.nodes, table = _a.table, tableRow = _a.tableRow, tableCell = _a.tableCell, tableHeader = _a.tableHeader; var rowNodes = []; for (var i = 0; i < rows; i++) { var cell = i === 0 ? tableHeader : tableCell; var cellNodes = []; for (var j = 0; j < columns; j++) { cellNodes.push(cell.createAndFill()); } rowNodes.push(tableRow.create(null, Fragment.from(cellNodes))); } return table.create(null, Fragment.from(rowNodes)); }; export var isIsolating = function (node) { return !!node.type.spec.isolating; }; export var getSelectedColumn = function (state, map) { var _a = state.selection, $anchorCell = _a.$anchorCell, $headCell = _a.$headCell; var start = $anchorCell.start(-1); var anchor = map.colCount($anchorCell.pos - start); var head = map.colCount($headCell.pos - start); return { anchor: anchor, head: head }; }; export var getSelectedRow = function (state) { var _a = state.selection, $anchorCell = _a.$anchorCell, $headCell = _a.$headCell; var anchor = $anchorCell.index(-1); var head = $headCell.index(-1); return { anchor: anchor, head: head }; }; export var containsTable = function (view, slice) { var table = view.state.schema.nodes.table; var tablePresent = false; slice.content.forEach(function (node) { if (node.type === table) { tablePresent = true; } }); return tablePresent; }; export var containsTableHeader = function (view, table) { var tableHeader = view.state.schema.nodes.tableHeader; var headerPresent = false; table.content.forEach(function (row) { if (row.firstChild.type === tableHeader) { headerPresent = true; } }); return headerPresent; }; //# sourceMappingURL=utils.js.map