@atlaskit/editor-plugin-metrics
Version:
Metrics plugin for @atlaskit/editor-core
60 lines (55 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.checkTableColumnResized = void 0;
var _steps = require("@atlaskit/adf-schema/steps");
var _transform = require("@atlaskit/editor-prosemirror/transform");
var _types = require("../types");
var checkTableColumnResized = exports.checkTableColumnResized = function checkTableColumnResized(tr) {
var COL_WIDTH_ATTR = 'colwidth';
var steps = tr.steps;
// Find the step that is changing the column width
var resizingColumnStep = steps.find(function (step) {
return step instanceof _transform.AttrStep || step instanceof _steps.BatchAttrsStep;
});
if (!resizingColumnStep) {
return undefined;
}
var pos;
// Find the position of the first column in the step that is being resized
if (resizingColumnStep instanceof _steps.BatchAttrsStep) {
if (resizingColumnStep.data.length === 0) {
return undefined;
}
var _resizingColumnStep$d = resizingColumnStep.data[0],
attrs = _resizingColumnStep$d.attrs,
nodeType = _resizingColumnStep$d.nodeType,
position = _resizingColumnStep$d.position;
if (['tableHeader', 'tableCell'].includes(nodeType) && attrs !== null && attrs !== void 0 && attrs[COL_WIDTH_ATTR]) {
pos = position;
}
} else if (resizingColumnStep instanceof _transform.AttrStep && resizingColumnStep.attr === COL_WIDTH_ATTR) {
pos = resizingColumnStep.pos;
}
if (!pos) {
return undefined;
}
// Find the range of the table that is being resized
var $pos = tr.doc.resolve(pos);
var blockRange = $pos.blockRange();
if (!blockRange) {
return undefined;
}
var from = blockRange.start;
var to = from + blockRange.parent.content.size;
// Use to and from position of table to check whether column width of same table is being resized
return {
type: _types.ActionType.CHANGING_ATTRS,
extraData: {
attr: COL_WIDTH_ATTR,
from: from,
to: to
}
};
};