<commit_before>
import {objectEach, clone} from './../../helpers/object';
import {rangeEach} from './../../helpers/number';
import {align, getAlignmentClasses, getValidSelection, checkSelectionConsistency, markLabelAsSelected} from './utils';

export const ROW_ABOVE = 'row_above';
export const ROW_BELOW = 'row_below';
export const COLUMN_LEFT = 'col_left';
export const COLUMN_RIGHT = 'col_right';
export const CLEAR_COLUMN = 'clear_column';
export const REMOVE_ROW = 'remove_row';
export const REMOVE_COLUMN = 'remove_col';
export const UNDO = 'undo';
export const REDO = 'redo';
export const READ_ONLY = 'make_read_only';
export const ALIGNMENT = 'alignment';
export const SEPARATOR = '---------';
export const ITEMS = [
  ROW_ABOVE, ROW_BELOW, COLUMN_LEFT, COLUMN_RIGHT, CLEAR_COLUMN, REMOVE_ROW, REMOVE_COLUMN, UNDO, REDO, READ_ONLY,
  ALIGNMENT, SEPARATOR
];

/**
 * Gets new object with all predefined menu items.
 *
 * @returns {Object}
 */
export function predefinedItems() {
  const items = {};

  objectEach(_predefinedItems, (value, key) => items[key] = clone(value));

  return items;
}

const _predefinedItems = {
  [SEPARATOR]: {
    name: SEPARATOR
  },
  [ROW_ABOVE]: {
    key: ROW_ABOVE,
    name: 'Insert row above',

    callback: function(key, selection) {
      this.alter('insert_row', selection.start.row);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }
      let entireColumnSelection = [0, selected[1], this.countRows() - 1, selected[1]];

      return entireColumnSelection.join(',') === selected.join(',');
    },
    hidden: function() {
      return !this.getSettings().allowInsertRow;
    }
  },
  [ROW_BELOW]: {
    key: ROW_BELOW,
    name: 'Insert row below',

    callback: function(key, selection) {
      this.alter('insert_row', selection.end.row + 1);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }
      let entireColumnSelection = [0, selected[1], this.countRows() - 1, selected[1]];

      return entireColumnSelection.join(',') === selected.join(',');
    },
    hidden: function() {
      return !this.getSettings().allowInsertRow;
    }
  },
  [COLUMN_LEFT]: {
    key: COLUMN_LEFT,
    name: 'Insert column on the left',
    callback: function(key, selection) {
      this.alter('insert_col', selection.start.col);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }<commit_msg>Enable contextMenu's 'insert row' options for grids with only one row #1853<commit_after>
import {objectEach, clone} from './../../helpers/object';
import {rangeEach} from './../../helpers/number';
import {align, getAlignmentClasses, getValidSelection, checkSelectionConsistency, markLabelAsSelected} from './utils';

export const ROW_ABOVE = 'row_above';
export const ROW_BELOW = 'row_below';
export const COLUMN_LEFT = 'col_left';
export const COLUMN_RIGHT = 'col_right';
export const CLEAR_COLUMN = 'clear_column';
export const REMOVE_ROW = 'remove_row';
export const REMOVE_COLUMN = 'remove_col';
export const UNDO = 'undo';
export const REDO = 'redo';
export const READ_ONLY = 'make_read_only';
export const ALIGNMENT = 'alignment';
export const SEPARATOR = '---------';
export const ITEMS = [
  ROW_ABOVE, ROW_BELOW, COLUMN_LEFT, COLUMN_RIGHT, CLEAR_COLUMN, REMOVE_ROW, REMOVE_COLUMN, UNDO, REDO, READ_ONLY,
  ALIGNMENT, SEPARATOR
];

/**
 * Gets new object with all predefined menu items.
 *
 * @returns {Object}
 */
export function predefinedItems() {
  const items = {};

  objectEach(_predefinedItems, (value, key) => items[key] = clone(value));

  return items;
}

const _predefinedItems = {
  [SEPARATOR]: {
    name: SEPARATOR
  },
  [ROW_ABOVE]: {
    key: ROW_ABOVE,
    name: 'Insert row above',

    callback: function(key, selection) {
      this.alter('insert_row', selection.start.row);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }

      let rowCount = this.countRows();
      let entireColumnSelection = [0, selected[1], rowCount - 1, selected[1]];

      return (entireColumnSelection.join(',') === selected.join(',')) && rowCount > 1;
    },
    hidden: function() {
      return !this.getSettings().allowInsertRow;
    }
  },
  [ROW_BELOW]: {
    key: ROW_BELOW,
    name: 'Insert row below',

    callback: function(key, selection) {
      this.alter('insert_row', selection.end.row + 1);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }

      let rowCount = this.countRows();
      let entireColumnSelection = [0, selected[1], rowCount - 1, selected[1]];

      return (entireColumnSelection.join(',') === selected.join(',')) && rowCount > 1;
    },
    hidden: function() {
      return !this.getSettings().allowInsertRow;
    }
  },
  [COLUMN_LEFT]: {
    key: COLUMN_LEFT,
    name: 'Insert column on the left',
    callback: function(key, selection) {
      this.alter('insert_col', selection.start.col);
    },
    disabled: function() {
      let selected = getValidSelection(this);

      if (!selected) {
        return true;
      }
{'fraction_non_alphanumeric': 0.1432330827067669, 'fraction_numerical': 0.004511278195488722, 'mean_word_length': 3.4267886855241265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '516526', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1680, 'n_words': 423}