UNPKG

carbon-components-angular

Version:
213 lines (209 loc) 6.54 kB
/** * * carbon-angular v0.0.0 | table-adapter.class.d.ts * * Copyright 2014, 2024 IBM * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * An abstract class that represents a cell in a table */ export declare abstract class TableCellAdapter { /** * The index of the cell in the table */ cellIndex: number; /** * The number of columns spanned by this cell */ colSpan: number; /** * The number of rows spanned by this cell */ rowSpan: number; } /** * An abstract class that represents a row in a table */ export declare abstract class TableRowAdapter { /** * The index of the row in the table */ rowIndex: number; /** * An array (or `HTMLCollection`) of `TableCellAdapter`s */ cells: HTMLCollection | TableCellAdapter[]; } /** * An abstract representation of a table that provides * a standard interface to query 2d tables for cell and row information. */ export declare abstract class TableAdapter { /** * The last accessible column in the table */ get lastColumnIndex(): number; /** * The last accessible row in the table */ get lastRowIndex(): number; /** * Returns a cell from the table * * @param row index of the row * @param column index of the column */ getCell(row: number, column: number): TableCellAdapter; /** * Returns a row from the table * * @param column index of the column */ getColumn(column: number): TableCellAdapter[]; /** * Returns a row from the table * * @param row index of the row */ getRow(row: number): TableRowAdapter; /** * Finds the column index of a given cell * * @param cell the cell to search for */ findColumnIndex(cell: TableCellAdapter): number; /** * Finds the row index of a given cell * * @param cell the cell to search for */ findRowIndex(cell: TableCellAdapter): number; /** * Finds the row and column index of a given cell * * @param cell the cell to search for * @returns a tuple that follows the `[row, column]` convention */ findIndex(cell: TableCellAdapter): [number, number]; } declare enum TableDomSpanDirection { colSpan = "colSpan", rowSpan = "rowSpan" } /** * A concrete implementation of `TableAdapter` * * Provides standard and consistent access to table cells and rows */ export declare class TableDomAdapter implements TableAdapter { tableElement: HTMLTableElement; /** * The last accessible column in the table */ get lastColumnIndex(): number; /** * The last accessible row in the table */ get lastRowIndex(): number; /** * `TableDomAdapter` works on a normal HTML table structure. * Custom tables that don't follow the standard structure should use a custom implementation of `TableAdapter`. * * The standard structure allows us to directly query rows for cells and indexes - though we do have to handle colspans specially. * * @param tableElement the root HTML table element. */ constructor(tableElement: HTMLTableElement); /** * Returns a cell from the table taking colspans in to account. * * @param row index of the row * @param column index of the column */ getCell(row: number, column: number): HTMLTableCellElement; /** * Returns a column from the table, using the `id` and `headers` attributes * * See here for more detail these attributes: https://www.w3.org/TR/WCAG20-TECHS/H43.html * * @param column the index of the column */ getColumn(column: number): HTMLTableCellElement[]; /** * Returns a row from the table * * @param row index of the row */ getRow(row: number): HTMLTableRowElement; /** * Finds the column index of a given cell * * @param cell the cell to search for */ findColumnIndex(cell: HTMLTableCellElement): number; /** * Finds the row index of a given cell * * @param cell the cell to search for */ findRowIndex(cell: HTMLTableCellElement): number; /** * Finds the row and column index of a given cell * * @param cell the cell to search for * @returns a tuple that follows the `[row, column]` convention */ findIndex(cell: HTMLTableCellElement): [number, number]; /** * Helper function that returns the "real" length of a row. * Only accurate with regard to colspans (though that's sufficient for it's uses here) * * TODO: Take rowSpan into account * * @param row the row to get the length of */ protected getRealRowLength(row: HTMLTableRowElement): number; /** * Finds a cell and it's real index given an array of cells, a target index, and the spanning direction * * @param cells An array of cells to search * @param targetIndex The index we think the cell is located at * @param spanDirection The direction of the cell spans. Should be `"colSpan"` for a row and `"rowSpan"` for a column */ protected findCell(cells: HTMLTableCellElement[], targetIndex: number, spanDirection: TableDomSpanDirection): { cell: HTMLTableCellElement; realIndex: number; }; /** * Helper method around `findCell`, searches based on a row of cells * * @param row the row of elements to search * @param index the index of the element */ protected findCellInRow(row: HTMLTableCellElement[], index: number): { cell: HTMLTableCellElement; realIndex: number; }; /** * Helper method around `findCell`, searches based on a column of cells * * @param col the column of elements to search * @param index the index of the element */ protected findCellInColumn(col: HTMLTableCellElement[], index: number): { cell: HTMLTableCellElement; realIndex: number; }; } export {};