UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

30 lines (29 loc) 1.38 kB
import { defaultState } from '../types'; const 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 const getMovedPayload = (nextState, nextAction, prevState) => { const 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 : [...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 }; };