@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
44 lines (43 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clearMultipleCells = void 0;
var _state = require("@atlaskit/editor-prosemirror/state");
var _utils = require("@atlaskit/editor-tables/utils");
var clearMultipleCells = exports.clearMultipleCells = function clearMultipleCells(targetCellPosition) {
return function (state, dispatch) {
var cursorPos;
var tr = state.tr;
if ((0, _utils.isSelectionType)(tr.selection, 'cell')) {
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var selection = tr.selection;
selection.forEachCell(function (_node, pos) {
var $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
tr = (0, _utils.emptyCell)((0, _utils.findCellClosestToPos)($pos), state.schema)(tr);
});
cursorPos = selection.$headCell.pos;
} else if (targetCellPosition) {
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
var cell = (0, _utils.findCellClosestToPos)(tr.doc.resolve(targetCellPosition + 1));
tr = (0, _utils.emptyCell)(cell, state.schema)(tr);
cursorPos = cell.pos;
}
if (tr.docChanged && cursorPos) {
var $pos = tr.doc.resolve(tr.mapping.map(cursorPos));
var textSelection = _state.Selection.findFrom($pos, 1, true);
if (textSelection) {
tr.setSelection(textSelection);
}
if (dispatch) {
dispatch(tr);
}
return true;
}
return false;
};
};