columnLeft.js 965 B

12345678910111213141516171819202122232425262728293031
  1. import { getValidSelection } from './../utils';
  2. export var KEY = 'col_left';
  3. export default function columnLeftItem() {
  4. return {
  5. key: KEY,
  6. name: 'Insert column on the left',
  7. callback: function callback(key, selection) {
  8. this.alter('insert_col', selection.start.col, 1, 'ContextMenu.columnLeft');
  9. },
  10. disabled: function disabled() {
  11. var selected = getValidSelection(this);
  12. if (!selected) {
  13. return true;
  14. }
  15. if (!this.isColumnModificationAllowed()) {
  16. return true;
  17. }
  18. var entireRowSelection = [selected[0], 0, selected[0], this.countCols() - 1];
  19. var rowSelected = entireRowSelection.join(',') == selected.join(',');
  20. var onlyOneColumn = this.countCols() === 1;
  21. return selected[1] < 0 || this.countCols() >= this.getSettings().maxCols || !onlyOneColumn && rowSelected;
  22. },
  23. hidden: function hidden() {
  24. return !this.getSettings().allowInsertColumn;
  25. }
  26. };
  27. }