@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
36 lines (33 loc) • 903 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getTableRectFromDoc = getTableRectFromDoc;
var _tableMap = require("@atlaskit/editor-tables/table-map");
/**
* Util to get the table rect from the docs
* @param doc
* @param tablePos
*/
function getTableRectFromDoc(doc, tablePos) {
var table = doc.nodeAt(tablePos);
// Check for table existence
if (!table || table.type.name !== 'table') {
throw new Error("No table at position \"".concat(tablePos, "\"."));
}
// Create transform base on the doc
var map = _tableMap.TableMap.get(table);
var $table = doc.resolve(tablePos);
// Nested tables start position might differ from the original position
var start = $table.start($table.depth + 1);
return {
map: map,
table: table,
tableStart: start,
// Default to zero
bottom: 0,
left: 0,
right: 0,
top: 0
};
}
;