UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

110 lines (109 loc) 6.17 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _defaultTableSelection = require("./default-table-selection"); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _default = exports.default = function _default(pluginState, action) { switch (action.type) { case 'TOGGLE_HEADER_COLUMN': return _objectSpread(_objectSpread({}, pluginState), {}, { isHeaderColumnEnabled: !pluginState.isHeaderColumnEnabled }); case 'TOGGLE_HEADER_ROW': return _objectSpread(_objectSpread({}, pluginState), {}, { isHeaderRowEnabled: !pluginState.isHeaderRowEnabled }); case 'CLEAR_HOVER_SELECTION': return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), _defaultTableSelection.defaultTableSelection); case 'SELECT_COLUMN': return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { isContextualMenuOpen: false }); case 'SET_TARGET_CELL_POSITION': return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { isContextualMenuOpen: false }); case 'TOGGLE_CONTEXTUAL_MENU': return _objectSpread(_objectSpread({}, pluginState), {}, { isContextualMenuOpen: !pluginState.isContextualMenuOpen }); case 'SHOW_INSERT_ROW_BUTTON': if (action.data.insertRowButtonIndex === pluginState.insertRowButtonIndex) { return pluginState; } return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { insertColumnButtonIndex: undefined // We need to assure that column is not shown }); case 'SHOW_INSERT_COLUMN_BUTTON': if (action.data.insertColumnButtonIndex === pluginState.insertColumnButtonIndex) { return pluginState; } return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { insertRowButtonIndex: undefined // We need to assure that row is not shown }); case 'HIDE_INSERT_COLUMN_OR_ROW_BUTTON': if (pluginState.insertRowButtonIndex !== undefined || pluginState.insertColumnButtonIndex !== undefined) { return _objectSpread(_objectSpread({}, pluginState), {}, { insertRowButtonIndex: undefined, insertColumnButtonIndex: undefined }); } return pluginState; case 'HIDE_RESIZE_HANDLE_LINE': return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { resizeHandleColumnIndex: undefined, resizeHandleRowIndex: undefined }); case 'START_KEYBOARD_COLUMN_RESIZE': case 'ADD_RESIZE_HANDLE_DECORATIONS': if (action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex && action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex && action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip && action.data.isKeyboardResize === pluginState.isKeyboardResize) { return pluginState; } return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { isResizeHandleWidgetAdded: true }); case 'UPDATE_RESIZE_HANDLE_DECORATIONS': var _action$data = action.data, resizeHandleColumnIndex = _action$data.resizeHandleColumnIndex, resizeHandleRowIndex = _action$data.resizeHandleRowIndex, resizeHandleIncludeTooltip = _action$data.resizeHandleIncludeTooltip; if ((resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex || !Number.isFinite(resizeHandleColumnIndex)) && (resizeHandleRowIndex === pluginState.resizeHandleRowIndex || !Number.isFinite(resizeHandleRowIndex)) && (resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip || resizeHandleIncludeTooltip === undefined)) { return pluginState; } return _objectSpread(_objectSpread({}, pluginState), {}, { resizeHandleColumnIndex: resizeHandleColumnIndex !== null && resizeHandleColumnIndex !== void 0 ? resizeHandleColumnIndex : pluginState.resizeHandleColumnIndex, resizeHandleRowIndex: resizeHandleRowIndex !== null && resizeHandleRowIndex !== void 0 ? resizeHandleRowIndex : pluginState.resizeHandleRowIndex, resizeHandleIncludeTooltip: resizeHandleIncludeTooltip !== null && resizeHandleIncludeTooltip !== void 0 ? resizeHandleIncludeTooltip : pluginState.resizeHandleIncludeTooltip }); case 'STOP_KEYBOARD_COLUMN_RESIZE': case 'REMOVE_RESIZE_HANDLE_DECORATIONS': if (!pluginState.isResizeHandleWidgetAdded) { return pluginState; } return _objectSpread(_objectSpread(_objectSpread({}, pluginState), action.data), {}, { resizeHandleColumnIndex: undefined, resizeHandleRowIndex: undefined, isResizeHandleWidgetAdded: false, isKeyboardResize: undefined }); case 'UPDATE_TABLE_WIDTH_TO_WIDEST': case 'SET_TABLE_REF': case 'HOVER_ROWS': case 'HOVER_COLUMNS': case 'HOVER_TABLE': case 'TABLE_HOVERED': case 'HOVER_MERGED_CELLS': case 'HOVER_CELL': case 'SHOW_RESIZE_HANDLE_LINE': case 'SET_EDITOR_FOCUS': case 'SET_CELL_MENU_OPEN': return _objectSpread(_objectSpread({}, pluginState), action.data); default: return pluginState; } };