handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
41 lines (39 loc) • 1.86 kB
JavaScript
"use strict";
exports.__esModule = true;
exports.default = columnLeftItem;
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 = 'col_left';
/**
* @returns {object}
*/
function columnLeftItem() {
return {
key: KEY,
name() {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_INSERT_LEFT);
},
callback() {
const activeSelection = this.getSelectedRangeActive().getTopLeftCorner();
const alterAction = this.isRtl() ? 'insert_col_end' : 'insert_col_start';
this.alter(alterAction, activeSelection.col, 1, 'ContextMenu.columnLeft');
},
disabled() {
if (!this.isColumnModificationAllowed()) {
return true;
}
const range = this.getSelectedRangeActive();
if (!range || this.selection.isSelectedByRowHeader() || range.isSingleHeader() && range.highlight.col < 0 || this.countSourceCols() >= this.getSettings().maxCols) {
return true;
}
if (this.selection.isSelectedByCorner()) {
// Enable "Insert column left" only when there is at least one column.
return this.countCols() === 0;
}
return false;
},
hidden() {
return !this.getSettings().allowInsertColumn;
}
};
}