UNPKG

handsontable

Version:

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

53 lines (52 loc) 2.23 kB
"use strict"; exports.__esModule = true; exports.default = hideRowItem; require("core-js/modules/es.array.push.js"); 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); } /** * @param {HiddenRows} hiddenRowsPlugin The plugin instance. * @returns {object} */ function hideRowItem(hiddenRowsPlugin) { return { key: 'hidden_rows_hide', name() { const selection = this.getSelectedActive(); let pluralForm = 0; if (Array.isArray(selection)) { const [fromRow,, toRow] = selection; if (fromRow - toRow !== 0) { pluralForm = 1; } } return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_HIDE_ROW, pluralForm); }, callback() { const { from, to } = this.getSelectedRangeActive(); const start = Math.max(Math.min(from.row, to.row), 0); const end = Math.max(from.row, to.row); const rowsToHide = []; for (let visualRow = start; visualRow <= end; visualRow += 1) { rowsToHide.push(visualRow); } hiddenRowsPlugin.hideRows(rowsToHide); const lastHiddenRow = rowsToHide[rowsToHide.length - 1]; const rowToSelect = this.rowIndexMapper.getNearestNotHiddenIndex(lastHiddenRow, 1, true); if (Number.isInteger(rowToSelect) && rowToSelect >= 0) { this.selectRows(rowToSelect); } else { this.deselectCell(); } this.view.adjustElementsSize(); this.render(); }, disabled: false, hidden() { return !(this.selection.isSelectedByRowHeader() || this.selection.isSelectedByCorner()); } }; }