handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
65 lines (63 loc) • 2.59 kB
JavaScript
"use strict";
exports.__esModule = true;
exports.default = readOnlyItem;
var _utils = require("../utils");
var _array = require("../../../helpers/array");
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 = 'make_read_only';
/**
* @returns {object}
*/
function readOnlyItem() {
return {
key: KEY,
checkable: true,
ariaChecked() {
const atLeastOneReadOnly = (0, _utils.checkSelectionConsistency)(this.getSelectedRange(), (row, col) => this.getCellMeta(row, col).readOnly);
return atLeastOneReadOnly;
},
ariaLabel() {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_READ_ONLY);
},
name() {
let label = this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_READ_ONLY);
const atLeastOneReadOnly = (0, _utils.checkSelectionConsistency)(this.getSelectedRange(), (row, col) => this.getCellMeta(row, col).readOnly);
if (atLeastOneReadOnly) {
label = (0, _utils.markLabelAsSelected)(label);
}
return label;
},
callback() {
const ranges = this.getSelectedRange();
const atLeastOneReadOnly = (0, _utils.checkSelectionConsistency)(ranges, (row, col) => this.getCellMeta(row, col).readOnly);
(0, _array.arrayEach)(ranges, range => {
range.forAll((row, col) => {
if (row >= 0 && col >= 0) {
this.setCellMeta(row, col, 'readOnly', !atLeastOneReadOnly);
}
});
});
this.render();
},
disabled() {
const range = this.getSelectedRangeActive();
if (!range) {
return true;
}
if (range.isSingleHeader()) {
return true;
}
if (this.selection.isSelectedByCorner()) {
return true;
}
if (this.countRows() === 0 || this.countCols() === 0) {
return true;
}
if (!this.getSelectedRange() || this.getSelectedRange().length === 0) {
return true;
}
return false;
}
};
}