import { CellGroup, DataModel, MutableDataModel } from '@lumino/datagrid'; import { ReadonlyJSONValue } from '@lumino/coreutils'; import { ISignal, Signal } from '@lumino/signaling'; import { Transform } from './transform'; import { View } from './view'; import { TransformStateManager } from './transformStateManager'; import { DataSource } from '../datasource'; /** * A view based data model implementation for in-memory JSON data. */ export declare class ViewBasedJSONModel extends MutableDataModel { /** * Create a data model with static JSON data. * * @param options - The options for creating the data model. */ constructor(options: ViewBasedJSONModel.IOptions); /** * Sets the dataset for this model. * * @param options - The options for creating the model */ updateDataset(options: ViewBasedJSONModel.IOptions): void; /** * Updates the primary key map, which provides a mapping from primary key * value to row in the full dataset. */ protected _updatePrimaryKeyMap(): void; areCellsMerged(cell1: number[], cell2: number[]): boolean; /** * Returns a list of [row, column] cells indices forming a merged cell group * @param row row index * @param column column index */ getMergedSiblingCells(cell: number[]): any[]; /** * Get the row count for a region in the data model. * * @param region - The row region of interest. * * @returns - The row count for the region. */ rowCount(region: DataModel.RowRegion): number; /** * Get the column count for a region in the data model. * * @param region - The column region of interest. * * @returns - The column count for the region. */ columnCount(region: DataModel.ColumnRegion): number; /** * Get the group count for each region * @param region * @returns */ groupCount(region: DataModel.RowRegion): number; /** * Specify merged cell groups for each region * @param region * @param groupIndex * @returns */ group(region: DataModel.CellRegion, groupIndex: number): CellGroup | null; /** * Get the metadata for a cell in the data model. * * @param region - The cell region of interest. * * @param row - The index of the row of interest. * * @param column - The index of the column of interest. * * @returns The metadata for the cell. */ metadata(region: DataModel.CellRegion, row: number, column: number): DataModel.Metadata; /** * Get the data value for a cell in the data model. * * @param region - The cell region of interest. * * @param row - The row index of the cell of interest. * * @param column - The column index of the cell of interest. * * @param returns - The data value for the specified cell. */ data(region: DataModel.CellRegion, row: number, column: number): any; /** * Updates the cell value of the currently displayed View. * * @param region - The cell region of interest. * * @param row - The row index of the cell of interest. * * @param column - The column index of the cell of interest. * * @param value - The new value to update the indicated cell with. * */ setData(region: DataModel.CellRegion, row: number, column: number, value: any): boolean; /** * Updates the cell value of the currently displayed View. * * @param region - The cell region of interest. * * @param row - The row index of the cell of interest. * * @param column - The column index of the cell of interest. * * @param value - The new value to update the indicated cell with. * */ setModelData(region: DataModel.CellRegion, row: number, column: number, value: any): boolean; /** * Updates the row value of the currently displayed View. * * @param row - The row index of the cell of interest. * * @param value - The new value to update the indicated row with. * */ setRowData(row: number, value: any): boolean; columnNameToIndex(name: string): number; columnIndexToName(index: number, region: DataModel.ColumnRegion): string; columnNameToRegion(name: string): DataModel.ColumnRegion; /** * Get the current View for the model. */ get currentView(): View; /** * Sets the provided View as the current View, then emits a changed signal. */ set currentView(view: View); /** * Add a new transform to the currently active transforms. * * @param transform - The transform to be added. */ addTransform(transform: Transform.TransformSpec): void; /** * Removes the provided transformation from the active state. * * @param column - The column state to be removed. * * @param transformType - The type of the transform to be removed from state. */ removeTransform(column: string, transformType: string): void; /** * Apply an array of transformations to the dataset and update the current * View. The provided transforms will replace any existing ones. * * @param transforms - Array of transformations to apply to the dataset */ replaceTransforms(transforms: Transform.TransformSpec[]): void; /** * Removes all active transforms. */ clearTransforms(): void; /** * Returns the transform metadata for the provided column. * * @param column - The column of the metadata to be retrieved. */ transformMetadata(column: string): TransformStateManager.IColumn | undefined; /** * Returns a Promise that resolves to an array of unique values contained in * the provided column index. * * @param region - The CellRegion to retrieve unique values for. * @param column - The column to retrieve unique values for. */ uniqueValues(region: DataModel.CellRegion, column: string): Promise; /** * Returns a Promise that resolves to an array of unique values contained in * the provided column index after all transforms have been applied. * * @param region - The CellRegion to retrieve unique values for. * @param column - The column to retrieve unique values for. */ uniqueValuesVisible(region: DataModel.CellRegion, column: string): Promise; get transformStateChanged(): ISignal; /** * Returns the active transforms for the current model */ get activeTransforms(): Transform.TransformSpec[]; getFilterTransform(column: string): Transform.TransformSpec | undefined; /** * Updates the indicated value in the dataset. * * Note: provided row/column values should correspond to the currently * active View, not the full dataset. * Note: Currently, only updating `body` cells is supported. * * @param options - The options for this method. */ getDatasetRowFromView(region: DataModel.CellRegion, row: number): number; /** * Updates a value in the full dataset of the model. * * @param options - The options for this function. */ updateCellValue(options: ViewBasedJSONModel.IUpdateCellValuesOptions): void; /** * Updates a row in the full dataset of the model. * * @param options - The options for this function. */ updateRowValue(options: ViewBasedJSONModel.IUpdateRowValuesOptions): void; /** * A signal emitted when the data model has changes to sync to the kernel. */ get dataSync(): Signal; /** * Returns the current full dataset. */ get dataset(): DataSource; /** * Returns the index in the schema that relates to the index by region. * * @param region - The `CellRegion` of interest. * * @param index - The column index to look up. */ getSchemaIndex(region: DataModel.CellRegion, index: number): number; /** * Handler for transformState.changed events. * * @param sender - TransformStateManager * * @param value - Event. */ protected _transformStateChangedHandler(sender: TransformStateManager, value: TransformStateManager.IEvent): void; protected _currentView: View; protected _transformSignal: Signal; private _dataSyncSignal; private _primaryKeyMap; protected _dataset: DataSource; protected readonly _transformState: TransformStateManager; private _mergedColumnCellLocations; private _mergedRowCellLocations; private _rowCellGroups; private _columnCellGroups; } /** * The namespace for the `ViewBasedJSONModel` class statics. */ export declare namespace ViewBasedJSONModel { interface IOptions { /** * The `DataSource` for the model. */ datasource: DataSource; } interface IUpdateCellValuesOptions { /** * The `CellRegion` of the cell to be updated. */ region: DataModel.CellRegion; /** * The index of the target row in the current view. */ column: number; /** * The index of the target row in the current view. */ row: number; /** * The new value to replace the old one. */ value: any; } interface IUpdateRowValuesOptions { /** * The index of the target row in the current view. */ row: number; /** * The new value to replace the old one. */ value: any[]; } type IDataSyncEvent = ISyncRowIndices | ICellEditEvent; interface ISyncRowIndices { /** * The discriminated type of the args object. */ type: 'row-indices-updated'; /** * An list of the rows in the untransformed dataset that are currently * represented in the `View`. */ indices: number[]; } interface ICellEditEvent { /** * The discriminated type of the args object. */ type: 'cell-edit-event'; /** * The CellRegion associated with this change. */ region: DataModel.CellRegion; /** * The row number associated with this change. */ row: number; /** * The column name associated with this change. */ column: string; /** * TODO Deprecate this * The column index associated with this change. */ columnIndex: number; /** * The new data value */ value: ReadonlyJSONValue; } }