UNPKG

@mescius/dspdfviewer

Version:
204 lines (202 loc) 8.69 kB
import GcPdfViewer from "../GcPdfViewer"; import { TableDefClientModel, TableDefRectangleClientModel } from "../SupportApi/types"; /// <reference path="../vendor/i18next.d.ts" /> //@ts-ignore import { i18n } from 'i18next'; /** * ExtractedTableEditor allows users to edit extracted table data in a UI. * It supports resizing rows and columns, updating cell content, and adding/removing rows. * Pointer events are used for interactions to ensure compatibility across devices. */ export declare class ExtractedTableEditor { viewer: GcPdfViewer; resizeSpotWidth: number; resizeSpotHeight: number; dragSpotSize: number; isDraggingTable: boolean; currentOperation: "resize-column" | "resize-row" | "resize-both" | "drag-table" | "none"; private pageIndex; private tableData; private container; private parentElement; private _onChangeCallback?; private _onDeactivateCallback?; private _resizingCell; private resizeData; private _pageChangedHandler?; private _activated; private _selectionPdfBounds; isResizingColumn: boolean; isResizingRow: boolean; private _activeCellData; private _initialCellDimensions; private _operationActive; private _startScrollPos?; constructor(viewer: GcPdfViewer); get isActive(): boolean; activate(tableData: TableDefClientModel | undefined, pageIndex: number, selectionPdfBounds: number[], parentElement: HTMLElement, onChange?: (data: TableDefClientModel) => void, onDeactivate?: (args: { cancelled: boolean; }) => void): void; deactivate(cancelled?: boolean): void; getEmptyTableData(bounds?: number[]): { cells: never[]; cols: never[]; rows: never[]; bounds: { x: number; y: number; width: number; height: number; }; }; get enableAutoScroll(): boolean; private get resizingCell(); private set resizingCell(value); get viewPortScale(): number; get clientBounds(): TableDefRectangleClientModel; get selectionClientBounds(): TableDefRectangleClientModel; addStyles(): void; removeStyles(): void; removeDom(): void; onChange(data: TableDefClientModel): void; get in17n(): i18n; render(): void; applyViewScale(val: number): number; updateCellText(row: number, col: number, text: string): void; _updateTitlesState(): void; /** * Adds a new row to the table. * If the table already has rows, the new row will be cloned from the last row. * If the table is empty, a default row with one cell will be created. * After adding the row, the table is re-rendered and the onChange callback is triggered. */ addRow(): void; /** * Merges the specified row with the row below it by removing the row and adjusting the height of the next row. * If the removed row is the last row, the table bounds and column heights are adjusted accordingly. * * @param {number} rowIndex - The index of the row to merge down. Must be within the bounds of the table rows. * @returns {void} * * @example * // Merges the second row (index 1) with the third row * mergeRowDown(1); */ mergeRowDown(rowIndex: number): void; /** * Removes a row from the table and shifts remaining rows upward, adjusting the table height. * If the removed row is not the first, the previous row's height is extended. * If the first row is removed, all remaining columns and table bounds are adjusted. * * @param {number} rowIndex - The index of the row to remove. */ removeRow(rowIndex: number): void; /** * Adds a new column to the table. * If the table already has columns, the new column will be cloned from the last column. * If the table is empty, a default column with one cell will be created. * After adding the column, the table is re-rendered and the onChange callback is triggered. */ addCol(): void; /** * Removes a column from the table by its index. * If the column is not the first column, its width is added to the previous column. * If the column is the first column, the width of all rows and the table bounds are adjusted. * After removing the column, the table is re-rendered and the onChange callback is triggered. * * @param {number} colIndex - The index of the column to remove. * @throws Will throw an error if the colIndex is out of bounds. */ mergeColRight(colIndex: number): void; /** * Removes a column from the table and shifts the remaining columns to the left. * The table's width is reduced by the width of the removed column. * Updates all relevant cells, columns, and table dimensions accordingly. * * @param {number} colIndex - The index of the column to be removed. * @throws Will log an error if the column index is out of bounds. */ removeCol(colIndex: number): void; ensureResizeClass(event: PointerEvent, cell: HTMLElement, rowIndex: number, colIndex: number): void; dragData?: { startX: number; startY: number; originalX: number; originalY: number; deltaX: number; deltaY: number; } | null; getScrollPos(): { scrollLeft: number; scrollTop: number; }; private onCellPointerDown; private _cacheInitialCellDimensions; private _getInitialCellDimensions; adjustForScrollOffset(deltaX: number, deltaY: number): { deltaX: number; deltaY: number; }; private dragTableMove; private resizeCellMove; /** * Handles the pointer move event for resizing a column. * Updates cell widths and positions based on the current delta. * @param event - The pointer event triggered by moving the column divider. */ private resizeColMove; /** * Handles the pointer move event for resizing a row. * Updates cell heights and positions based on the current delta. * @param event - The pointer event triggered by moving the row divider. */ private resizeRowMove; get tableElement(): HTMLElement; get addColButtonElement(): HTMLElement; get addRowButtonElement(): HTMLElement; onOperationStart(): void; onOperationStop(): void; private stopDragTable; private stopResize; private stopResizeColumn; private stopResizeRow; /** * Moves the entire table by the specified delta values. * The method updates the positions of all cells, columns, and rows, * as well as the overall table position. * * @param {number} deltaX - The change in horizontal position (in pixels). * @param {number} deltaY - The change in vertical position (in pixels). */ moveTable(deltaX: number, deltaY: number): void; /** * Ensures the existence of a cell by creating a new one if not present. * @param {number} col - Column index. * @param {number} row - Row index. * @param {ExtractedTableData} tableData - The table data object. */ private ensureCell; /** * Resizes a column and adjusts related cells and table bounds. * @param colIndex - The index of the column to resize. * @param deltaX - The horizontal change in size (positive for expansion, negative for reduction). */ private resizeCol; /** * Resizes a row and adjusts related cells and table bounds. * @param rowIndex - The index of the row to resize. * @param deltaY - The vertical change in size (positive for expansion, negative for reduction). */ private resizeRow; /** * Resizes a cell by the specified delta values and updates the sizes of adjacent cells and the table. * The method adjusts the width and height of the cell, as well as the sizes of neighboring cells in the same row and column. * It also updates the overall table dimensions to reflect the changes. * * @param {number} col - The column index of the cell to resize. * @param {number} row - The row index of the cell to resize. * @param {number} deltaX - The change in width (in pixels) to apply to the cell. * @param {number} deltaY - The change in height (in pixels) to apply to the cell. * @throws Will throw an error if the cell is not found or if the resizing would result in invalid dimensions. */ resizeCell(col: number, row: number, deltaX: number, deltaY: number): void; }