<commit_before>/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.         IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable rulesdir/check_license_header */

import * as Common from '../../../../core/common/common.js';
import * as i18n from '../../../../core/i18n/i18n.js';
import * as Platform from '../../../../core/platform/platform.js';
import * as UI from '../../legacy.js';

const UIStrings = {
  /**
  *@description Accessible text label for expandible nodes in datagrids
  */
  expanded: 'expanded',
  /**
  *@description accessible name for expandible nodes in datagrids
  */
  collapsed: 'collapsed',
  /**
  *@description Accessible text for datagrid
  *@example {Coverage grid} PH1
  *@example {expanded} PH2
  */
  sRowS: '{PH1} Row {PH2}',
  /**
  *@description Number of rows in a grid
  *@example {1} PH1
  */
  rowsS: 'Rows: {PH1}',
  /**
  * @description Default Accessible Text for a Datagrid. This text is read to the user by a
  * screenreader when they navigate to a table structure. The placeholders tell the user something
  * brief about the table contents i.e. the topic and how much data is in it.
  * @example {Network} PH1
  * @example {Rows: 27} PH2
  */
  sSUseTheUpAndDownArrowKeysTo:
      '{PH1} {PH2}, use the up and down arrow keys to navigate and interact with the rows of the table; Use browse mode to read cell by cell.',
  /**
  *@description A context menu item in the Data Grid of a data grid
  */
  sortByString: 'Sort By',
  /**
  *@description A context menu item in data grids to reset the columns to their default weight
  */
  resetColumns: 'Reset Columns',
  /**
  *@description A context menu item in data grids to list header options.
  */
  headerOptions: 'Header Options',
  /**
  *@description Text to refresh the page
  */
  refresh: 'Refresh',
  /**
  *@description A context menu item in the Data Grid of a data grid
  */
  addNew: 'Add new',
  /**
  *@description A context menu item in the Data Grid of a data grid
  *@example {pattern} PH1
  */
  editS: 'Edit "{PH1}"',
  /**
  *@description Text to delete something
  */
  delete: 'Delete',
  /**
  *@description Depth of a node in the datagrid
  *@example {1} PH1
  */
  levelS: 'level {PH1}',
  /**
  *@description Text exposed to screen readers on checked items.
  */
  checked: 'checked',
  /**
   *@description Accessible text indicating an empty row is created.
   */
  emptyRowCreated: 'An empty table row has been created. You may double click or use context menu to edit.',
};
const str_ = i18n.i18n.registerUIStrings('ui/legacy/components/data_grid/DataGrid.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);

const elementToLongTextMap = new WeakMap<Element, string>();

const nodeToColumnIdMap = new WeakMap<Node, string>();

const elementToSortIconMap = new WeakMap<Element, UI.Icon.Icon>();

const elementToPreferedWidthMap = new WeakMap<Element, number>();

const elementToPositionMap = new WeakMap<Element, number>();

const elementToIndexMap = new WeakMap<Element, number>();

export class DataGridImpl<T> extends Common.ObjectWrapper.ObjectWrapper<EventTypes<T>> {
  element: HTMLDivElement;
  private displayName: string;
  private editCallback: ((arg0: any, arg1: string, arg2: any, arg3: any) => any)|undefined;
  private readonly deleteCallback: ((arg0: any) => any)|undefined;
  private readonly refreshCallback: (() => any)|undefined;
  private readonly headerTable: Element;
  private headerTableHeaders: {
    [x: string]: Element,
  };
  scrollContainerInternal: Element;
  private readonly dataTable: Element;
  protected inline: boolean;
  private columnsArray: ColumnDescriptor[];
  columns: {
    [x: string]: ColumnDescriptor,
  };
  visibleColumnsArray: ColumnDescriptor[];
  cellClass: string|null;
  private readonly headerTableColumnGroup: Element;
  private headerTableBodyInternal: HTMLTableSectionElement;
  private readonly headerRow: Element;
  private readonly dataTableColumnGroup: Element;
  dataTableBody: Element;
  topFillerRow: HTMLElement;
  private bottomFillerRow: HTMLElement;
  private editing: boolean;
  selectedNode: DataGridNode<T>|null;
  expandNodesWhenArrowing: boolean;
  indentWidth: number;
  private resizers: HTMLElement[];
  private columnWidthsInitialized: boolean;
  private cornerWidth: number;
  private resizeMethod: ResizeMethod;
  private headerContextMenuCallback: ((arg0: UI.ContextMenu.SubMenu) => void)|null;
  private rowContextMenuCallback: ((arg0: UI.ContextMenu.ContextMenu, arg1: DataGridNode<T>) => void)|null;
  elementToDataGridNode: WeakMap<Node, DataGridNode<T>>;
  disclosureColumnId?: string;
  private sortColumnCell?: Element;
  private rootNodeInternal?: DataGridNode<T>;
  private editingNode?: DataGridNode<T>|null;
  private columnWeightsSetting?: Common.Settings.Setting<any>;
  creationNode?: CreationDataGridNode<any>;
  private currentResizer?: EventTarget|null;
  private dataGridWidget?: any;

  constructor(dataGridParameters: Parameters) {
    super();
    const {displayName, columns: columnsArray, editCallback, deleteCallback, refreshCallback} = dataGridParameters;
    this.element = document.createElement('div');
    this.element.classList.add('data-grid');
    UI.Utils.appendStyle(this.element, 'ui/legacy/components/data_grid/dataGrid.css');
    this.element.tabIndex = 0;
    this.element.addEventListener('keydown', this.keyDown.bind(this), false);
    this.element.addEventListener('contextmenu', this.contextMenu.bind(this), true);
    this.element.addEventListener('focusin', event => {
      this.updateGridAccessibleNameOnFocus();
      event.consume(true);
    });
    this.element.addEventListener('focusout', event => {
      this.updateGridAccessibleName(/* text */ '');
      event.consume(true);
    });

    UI.ARIAUtils.markAsApplication(this.element);
    this.displayName = displayName;

    this.editCallback = editCallback;
    this.deleteCallback = deleteCallback;
    this.refreshCallback = refreshCallback;

    const headerContainer = this.element.createChild('div', 'header-container');
    this.headerTable = headerContainer.createChild('table', 'header');
    // Hide the header table from screen readers since titles are also added to data table.
    UI.ARIAUtils.markAsHidden(this.headerTable);
    this.headerTableHeaders = {};<commit_msg>[Accessibility]: Removing aria-hidden attribute from data grid header table<commit_after>/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.         IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable rulesdir/check_license_header */

import * as Common from '../../../../core/common/common.js';
import * as i18n from '../../../../core/i18n/i18n.js';
import * as Platform from '../../../../core/platform/platform.js';
import * as UI from '../../legacy.js';

const UIStrings = {
  /**
  *@description Accessible text label for expandible nodes in datagrids
  */
  expanded: 'expanded',
  /**
  *@description accessible name for expandible nodes in datagrids
  */
  collapsed: 'collapsed',
  /**
  *@description Accessible text for datagrid
  *@example {Coverage grid} PH1
  *@example {expanded} PH2
  */
  sRowS: '{PH1} Row {PH2}',
  /**
  *@description Number of rows in a grid
  *@example {1} PH1
  */
  rowsS: 'Rows: {PH1}',
  /**
  * @description Default Accessible Text for a Datagrid. This text is read to the user by a
  * screenreader when they navigate to a table structure. The placeholders tell the user something
  * brief about the table contents i.e. the topic and how much data is in it.
  * @example {Network} PH1
  * @example {Rows: 27} PH2
  */
  sSUseTheUpAndDownArrowKeysTo:
      '{PH1} {PH2}, use the up and down arrow keys to navigate and interact with the rows of the table; Use browse mode to read cell by cell.',
  /**
  *@description A context menu item in the Data Grid of a data grid
  */
  sortByString: 'Sort By',
  /**
  *@description A context menu item in data grids to reset the columns to their default weight
  */
  resetColumns: 'Reset Columns',
  /**
  *@description A context menu item in data grids to list header options.
  */
  headerOptions: 'Header Options',
  /**
  *@description Text to refresh the page
  */
  refresh: 'Refresh',
  /**
  *@description A context menu item in the Data Grid of a data grid
  */
  addNew: 'Add new',
  /**
  *@description A context menu item in the Data Grid of a data grid
  *@example {pattern} PH1
  */
  editS: 'Edit "{PH1}"',
  /**
  *@description Text to delete something
  */
  delete: 'Delete',
  /**
  *@description Depth of a node in the datagrid
  *@example {1} PH1
  */
  levelS: 'level {PH1}',
  /**
  *@description Text exposed to screen readers on checked items.
  */
  checked: 'checked',
  /**
   *@description Accessible text indicating an empty row is created.
   */
  emptyRowCreated: 'An empty table row has been created. You may double click or use context menu to edit.',
};
const str_ = i18n.i18n.registerUIStrings('ui/legacy/components/data_grid/DataGrid.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);

const elementToLongTextMap = new WeakMap<Element, string>();

const nodeToColumnIdMap = new WeakMap<Node, string>();

const elementToSortIconMap = new WeakMap<Element, UI.Icon.Icon>();

const elementToPreferedWidthMap = new WeakMap<Element, number>();

const elementToPositionMap = new WeakMap<Element, number>();

const elementToIndexMap = new WeakMap<Element, number>();

export class DataGridImpl<T> extends Common.ObjectWrapper.ObjectWrapper<EventTypes<T>> {
  element: HTMLDivElement;
  private displayName: string;
  private editCallback: ((arg0: any, arg1: string, arg2: any, arg3: any) => any)|undefined;
  private readonly deleteCallback: ((arg0: any) => any)|undefined;
  private readonly refreshCallback: (() => any)|undefined;
  private readonly headerTable: Element;
  private headerTableHeaders: {
    [x: string]: Element,
  };
  scrollContainerInternal: Element;
  private readonly dataTable: Element;
  protected inline: boolean;
  private columnsArray: ColumnDescriptor[];
  columns: {
    [x: string]: ColumnDescriptor,
  };
  visibleColumnsArray: ColumnDescriptor[];
  cellClass: string|null;
  private readonly headerTableColumnGroup: Element;
  private headerTableBodyInternal: HTMLTableSectionElement;
  private readonly headerRow: Element;
  private readonly dataTableColumnGroup: Element;
  dataTableBody: Element;
  topFillerRow: HTMLElement;
  private bottomFillerRow: HTMLElement;
  private editing: boolean;
  selectedNode: DataGridNode<T>|null;
  expandNodesWhenArrowing: boolean;
  indentWidth: number;
  private resizers: HTMLElement[];
  private columnWidthsInitialized: boolean;
  private cornerWidth: number;
  private resizeMethod: ResizeMethod;
  private headerContextMenuCallback: ((arg0: UI.ContextMenu.SubMenu) => void)|null;
  private rowContextMenuCallback: ((arg0: UI.ContextMenu.ContextMenu, arg1: DataGridNode<T>) => void)|null;
  elementToDataGridNode: WeakMap<Node, DataGridNode<T>>;
  disclosureColumnId?: string;
  private sortColumnCell?: Element;
  private rootNodeInternal?: DataGridNode<T>;
  private editingNode?: DataGridNode<T>|null;
  private columnWeightsSetting?: Common.Settings.Setting<any>;
  creationNode?: CreationDataGridNode<any>;
  private currentResizer?: EventTarget|null;
  private dataGridWidget?: any;

  constructor(dataGridParameters: Parameters) {
    super();
    const {displayName, columns: columnsArray, editCallback, deleteCallback, refreshCallback} = dataGridParameters;
    this.element = document.createElement('div');
    this.element.classList.add('data-grid');
    UI.Utils.appendStyle(this.element, 'ui/legacy/components/data_grid/dataGrid.css');
    this.element.tabIndex = 0;
    this.element.addEventListener('keydown', this.keyDown.bind(this), false);
    this.element.addEventListener('contextmenu', this.contextMenu.bind(this), true);
    this.element.addEventListener('focusin', event => {
      this.updateGridAccessibleNameOnFocus();
      event.consume(true);
    });
    this.element.addEventListener('focusout', event => {
      this.updateGridAccessibleName(/* text */ '');
      event.consume(true);
    });

    UI.ARIAUtils.markAsApplication(this.element);
    this.displayName = displayName;

    this.editCallback = editCallback;
    this.deleteCallback = deleteCallback;
    this.refreshCallback = refreshCallback;

    const headerContainer = this.element.createChild('div', 'header-container');
    this.headerTable = headerContainer.createChild('table', 'header');
    this.headerTableHeaders = {};
{'fraction_non_alphanumeric': 0.10776513906239726, 'fraction_numerical': 0.006443553159313564, 'mean_word_length': 4.253886010362694, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 51, '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': '2363419', 'n_tokens_mistral': 4396, 'n_tokens_neox': 4261, 'n_words': 1476}