UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

31 lines (30 loc) 1.52 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import { defaultState } from '../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; }; export var getMovedPayload = function getMovedPayload(nextState, nextAction, prevState) { var nextActionType = getNextActionType(nextState, nextAction, prevState); if (nextActionType === 'none') { return 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(_toConsumableArray(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 }; };