import { BehaviorSubject, Subject, ReplaySubject } from 'rxjs'; import { OutputsView } from './cell-views'; import { AnyVirtualDOM } from '@youwol/rx-vdom'; import { InterpreterCellView, JsCellView, MdCellView, PyCellView } from '.'; import { Router } from '../router'; import type { MdParsingOptions } from '../markdown'; import { DisplayFactory } from './display-utils'; import { WorkerCellView } from './worker-cell-view'; export type CellStatus = 'unready' | 'ready' | 'success' | 'error' | 'pending' | 'executing'; /** * Represents the scope of a cell. * * This is a work in progress: at least functions and classes are missing. */ export type Scope = { /** * The `let` variables: keyed by their name and mapped to their values. */ let: { [k: string]: unknown; }; /** * The `const` variables: keyed by their name and mapped to their values. */ const: { [k: string]: unknown; }; /** * The exported globals of python runtime. */ python: { [k: string]: unknown; }; }; /** * Type of the outputs generated by a cell. * * The type `undefined` is a signal to clear the outputs displayed. */ export type Output = AnyVirtualDOM | undefined; /** * Arguments used to execute a cell, see {@link CellTrait.execute}. */ export type ExecArgs = { /** * Cell ID. */ cellId: string; /** * Source to execute. */ src: string; /** * The function used to load a submodule from a notebook page. * * @param path Navigation path of the submodule. * @returns The exported symbols. */ load: (path: string) => Promise<{ [k: string]: unknown; }>; /** * Subject in which output (*e.g.* when using ̀display` in a {@link JsCellView}) are sent. */ output$: Subject; /** * The factory used to pick up the right mapping between variable and view when `display` is called. */ displayFactory: DisplayFactory; /** * Owning state of the cell. */ owningState: State; /** * Entering scope of the cell. */ scope: Scope; }; /** * Trait for a Cell within a {@link NotebookPage}. */ export interface CellTrait { /** * Cell unique ID. */ cellId: string; /** * Observable over the source content of the cell. */ content$: BehaviorSubject; /** * Define the implementation of cell execution. */ execute: (args: ExecArgs) => Promise; } /** * Represents the state of a {@link NotebookPage}. */ export declare class State { /** * Observables over the cell's entering scopes keyed by the cell's ID. */ readonly scopes$: { [k: string]: BehaviorSubject; }; /** * The factory used to pick up the right mapping between variable and view when `display` is called. */ readonly displayFactory: DisplayFactory; /** * Observable that emits the ID of invalidated cells. */ readonly invalidated$: Subject; /** * Observables over the cell's output keyed by the cell's ID. */ readonly outputs$: { [k: string]: ReplaySubject; }; /** * Observables over the cell's source keyed by the cell's ID. */ readonly src$: { [k: string]: BehaviorSubject; }; /** * Observables over the cell's status keyed by the cell's ID. */ readonly cellsStatus$: { [k: string]: BehaviorSubject; }; /** * Observables over the cell IDs included in the associated {@link NotebookPage}. */ readonly cellIds$: BehaviorSubject; /** * Observables over whether the cell is currently executing keyed by the cell's ID. */ readonly executing$: { [k: string]: BehaviorSubject; }; /** * The deported output views as a list of their associated cell ID. */ readonly deportedOutputsViews: string[]; /** * List of the cell IDs in the page. */ readonly ids: string[]; /** * List of the cells in the page. */ readonly cells: CellTrait[]; /** * The initial scope (provided to the first cell when executed). */ readonly initialScope: Scope; /** * Optional related parent state (*e.g.* {@link MdCellView} own their own executing state created upon execution). */ readonly parent?: { state: State; cellId: string; }; /** * The application router, used to import modules from other notebook pages. */ readonly router: Router; readonly modules: { [k: string]: { state: State; exports: Scope; }; }; /** * Pyodide execution should be namespaced by notebook page, * this variable holds the symbols. * * This is a python dictionary initialized with `pyodide.globals.get("dict")()` * when the notebook page is loaded and reused across python cells. */ private pyNamespace; constructor(params: { initialScope?: Partial; router: Router; displayFactory?: DisplayFactory; parent?: { state: State; cellId: string; }; }); getPyNamespace(pyodide: any): { get: (key: string) => unknown; }; appendCell(cell: CellTrait): void; createJsCell(elem: HTMLElement): JsCellView; createPyCell(elem: HTMLElement): PyCellView; createMdCell(elem: HTMLElement, parserOptions: MdParsingOptions): MdCellView; createInterpreterCell(elem: HTMLElement): InterpreterCellView; createWorkerCell(elem: HTMLElement): WorkerCellView; createDeportedOutputsView(elem: HTMLElement): OutputsView; updateSrc({ cellId, src }: { cellId: string; src: string; }): void; execute(id: string, rootExecution?: boolean): Promise; private invalidateCells; private dispose; unreadyCells({ afterCellId }: { afterCellId: string; }): void; private loadModule; }