UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

71 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var prosemirror_1 = require("../../prosemirror"); exports.getColumnPos = function (column, tableNode) { var map = prosemirror_1.TableMap.get(tableNode); var from = map.positionAt(0, column, tableNode); var to = map.positionAt(map.height - 1, column, tableNode); return { from: from, to: to }; }; exports.getRowPos = function (row, tableNode) { var map = prosemirror_1.TableMap.get(tableNode); var from = map.positionAt(row, 0, tableNode); var to = map.positionAt(row, map.width - 1, tableNode); return { from: from, to: to }; }; exports.getTablePos = function (tableNode) { var map = prosemirror_1.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 }; }; exports.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, prosemirror_1.Fragment.from(cellNodes))); } return table.create(null, prosemirror_1.Fragment.from(rowNodes)); }; exports.isIsolating = function (node) { return !!node.type.spec.isolating; }; exports.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 }; }; exports.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 }; }; exports.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; }; exports.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