@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
38 lines (36 loc) • 1.78 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getMovedPayload = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _types = require("../types");
var getNextActionType = function getNextActionType(nextState, nextAction, prevState) {
if (nextAction === 'pasted') {
if (prevState && prevState.currentActions.includes('copyOrCut') && prevState.currentActions.includes('addRowOrColumn') && prevState.numberOfCells === nextState.numberOfCells && prevState.type === nextState.type) {
return 'pasted';
}
return 'none';
}
return nextAction;
};
var getMovedPayload = exports.getMovedPayload = function getMovedPayload(nextState, nextAction, prevState) {
var nextActionType = getNextActionType(nextState, nextAction, prevState);
if (nextActionType === 'none') {
return _types.defaultState.rowOrColumnMoved;
}
// a new workflow has started in the opposite axis (e.g. inserted a row, but copied a column) remove old state
if (prevState.type !== nextState.type) {
return {
currentActions: [nextActionType],
numberOfCells: nextState === null || nextState === void 0 ? void 0 : nextState.numberOfCells,
type: nextState.type
};
}
return {
currentActions: prevState.currentActions.includes(nextActionType) ? prevState.currentActions : [].concat((0, _toConsumableArray2.default)(prevState.currentActions), [nextActionType]),
numberOfCells: (nextState === null || nextState === void 0 ? void 0 : nextState.numberOfCells) || prevState.numberOfCells,
type: nextState === null || nextState === void 0 ? void 0 : nextState.type
};
};