import { Clipboard } from '@jupyterlab/apputils' ; import { Menu , Widget } from '@phosphor/widgets' ; import { IDisposable } from '@phosphor/disposable' ; import { CommandRegistry } from '@phosphor/commands' ; import { Table } from './Table' ; namespace CommandIds { export const copyToClipboard = 'copy-selection-to-clipboard' ; } export class ResultsTable implements IDisposable { constructor ( keys , data ) { const contextMenu = this . _createContextMenu ( ) ; this . _table = Table . fromKeysRows ( keys , data , { contextMenu } ) ; } get widget ( ) : Widget { return this . _table . widget ; } dispose ( ) { this . _table . dispose ( ) ; this . _isDisposed = true ; } get isDisposed ( ) : boolean { return this . _isDisposed ; } private _createContextMenu ( ) { const commands = new CommandRegistry ( ) ; commands . addCommand ( CommandIds . copyToClipboard , { label : 'Copy cell' , iconClass : 'jp-MaterialIcon jp-CopyIcon' , execute : ( ) => this . _copySelectionToClipboard ( ) } ) ; const menu = new Menu ( { commands } ) ; menu . addItem ( { command : CommandIds . copyToClipboard } ) ; return menu ; } private _copySelectionToClipboard ( ) { const selectionValue = this . _table . selectionValue ; if ( selectionValue !== null ) { Clipboard . copyToSystem ( selectionValue ) ; } } private readonly _table : Table ; private _isDisposed : boolean = false ; }