import { Cell , CodeCell } from '@jupyterlab/cells' ; import { IObservableMap , ObservableMap } from '@jupyterlab/observables' ; import { Notebook , NotebookPanel } from '@jupyterlab/notebook' ; import { IDisposable } from '@lumino/disposable' ; import { Signal } from '@lumino/signaling' ; import { IDebugger } from '../tokens' ; import { EditorHandler } from './editor' ; /**
 * A handler for notebooks.
 */ export class NotebookHandler implements IDisposable { param options constructor ( options ) { this . _debuggerService = options . debuggerService ; this . _notebookPanel = options . widget ; this . _cellMap = new ObservableMap < EditorHandler > ( ) ; const notebook = this . _notebookPanel . content ; notebook . activeCellChanged . connect ( this . _onActiveCellChanged , this ) ; notebook . model . cells . changed . connect ( this . _onCellsChanged , this ) ; this . _onCellsChanged ( ) ; } /**
     * Whether the handler is disposed.
     */ isDisposed : boolean ; /**
     * Dispose the handler.
     */ dispose ( ) { if ( this . isDisposed ) { return ; } this . isDisposed = true ; this . _cellMap . values ( ) . forEach ( handler => handler . dispose ( ) ) ; this . _cellMap . dispose ( ) ; Signal . clearData ( this ) ; } /**
     * Handle a notebook cells changed event.
     */ private _onCellsChanged ( ) { this . _notebookPanel . content . widgets . forEach ( cell => this . _addEditorHandler ( cell ) ) ; } param cell private _addEditorHandler ( cell ) { const modelId = cell . model . id ; if ( cell . model . type !== 'code' || this . _cellMap . has ( modelId ) ) { return ; } const codeCell = cell as CodeCell ; const editorHandler = new EditorHandler ( { debuggerService : this . _debuggerService , editor : codeCell . editor } ) ; codeCell . disposed . connect ( ( ) => { this . _cellMap . delete ( modelId ) ; editorHandler . dispose ( ) ; } ) ; this . _cellMap . set ( cell . model . id , editorHandler ) ; } param notebook param cell private _onActiveCellChanged ( notebook , cell ) { if ( this . _notebookPanel . content !== notebook ) { return ; } this . _addEditorHandler ( cell ) ; } private _debuggerService : IDebugger ; private _notebookPanel : NotebookPanel ; private _cellMap : IObservableMap < EditorHandler > = null ; } /**
 * A namespace for NotebookHandler statics.
 */ export namespace NotebookHandler { /**
     * Instantiation options for `NotebookHandler`.
     */ export interface IOptions { /**
         * The debugger service.
         */ debuggerService : IDebugger ; /**
         * The widget to handle.
         */ widget : NotebookPanel ; } }