UNPKG

handsontable

Version:

Handsontable is a JavaScript Data Grid available for React, Angular and Vue.

55 lines (53 loc) 2.28 kB
"use strict"; exports.__esModule = true; exports.default = removeRowItem; var _utils = require("../../../selection/utils"); var C = _interopRequireWildcard(require("../../../i18n/constants")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const KEY = exports.KEY = 'remove_row'; /** * @returns {object} */ function removeRowItem() { return { key: KEY, name() { const selection = this.getSelected(); let pluralForm = 0; if (selection) { if (selection.length > 1) { pluralForm = 1; } else { const [fromRow,, toRow] = selection[0]; if (fromRow - toRow !== 0) { pluralForm = 1; } } } return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_REMOVE_ROW, pluralForm); }, callback() { // TODO: Please keep in mind that below `1` may be improper. The table's way of work, before change `f1747b3912ea3b21fe423fd102ca94c87db81379` was restored. // There is still problem when removing more than one row. this.alter('remove_row', (0, _utils.transformSelectionToRowDistance)(this), 1, 'ContextMenu.removeRow'); }, disabled() { const range = this.getSelectedRangeLast(); if (!range) { return true; } if (range.isSingleHeader() && range.highlight.row < 0) { return true; } const totalRows = this.countRows(); if (this.selection.isSelectedByCorner()) { // Enable "Remove row" only when there is at least one row. return totalRows === 0; } return this.selection.isSelectedByColumnHeader() || totalRows === 0; }, hidden() { return !this.getSettings().allowRemoveRow; } }; }