import { nbformat } from '@jupyterlab/services'; import { DocumentModel, DocumentRegistry } from '../docregistry'; import { ICellModel, ICodeCellModel, IRawCellModel, IMarkdownCellModel, CodeCellModel, CellModel } from '../cells/model'; import { IObservableJSON } from '../common/observablejson'; import { IObservableUndoableVector } from '../common/undoablevector'; /** * The definition of a model object for a notebook widget. */ export interface INotebookModel extends DocumentRegistry.IModel { /** * The list of cells in the notebook. */ readonly cells: IObservableUndoableVector; /** * The cell model factory for the notebook. */ readonly contentFactory: NotebookModel.IContentFactory; /** * The major version number of the nbformat. */ readonly nbformat: number; /** * The minor version number of the nbformat. */ readonly nbformatMinor: number; /** * The metadata associated with the notebook. */ readonly metadata: IObservableJSON; } /** * An implementation of a notebook Model. */ export declare class NotebookModel extends DocumentModel implements INotebookModel { /** * Construct a new notebook model. */ constructor(options?: NotebookModel.IOptions); /** * The cell model factory for the notebook. */ readonly contentFactory: NotebookModel.IContentFactory; /** * The metadata associated with the notebook. */ readonly metadata: IObservableJSON; /** * Get the observable list of notebook cells. */ readonly cells: IObservableUndoableVector; /** * The major version number of the nbformat. */ readonly nbformat: number; /** * The minor version number of the nbformat. */ readonly nbformatMinor: number; /** * The default kernel name of the document. */ readonly defaultKernelName: string; /** * The default kernel language of the document. */ readonly defaultKernelLanguage: string; /** * Dispose of the resources held by the model. */ dispose(): void; /** * Serialize the model to a string. */ toString(): string; /** * Deserialize the model from a string. * * #### Notes * Should emit a [contentChanged] signal. */ fromString(value: string): void; /** * Serialize the model to JSON. */ toJSON(): nbformat.INotebookContent; /** * Deserialize the model from JSON. * * #### Notes * Should emit a [contentChanged] signal. */ fromJSON(value: nbformat.INotebookContent): void; /** * Handle a change in the cells list. */ private _onCellsChanged(list, change); /** * Make sure we have the required metadata fields. */ private _ensureMetadata(); private _cells; private _nbformat; private _nbformatMinor; private _metadata; } /** * The namespace for the `NotebookModel` class statics. */ export declare namespace NotebookModel { /** * An options object for initializing a notebook model. */ interface IOptions { /** * The language preference for the model. */ languagePreference?: string; /** * A factory for creating cell models. * * The default is a shared factory instance. */ contentFactory?: IContentFactory; } /** * A factory for creating notebook model content. */ interface IContentFactory { /** * The factory for output area models. */ readonly codeCellContentFactory: CodeCellModel.IContentFactory; /** * Create a new code cell. * * @param options - The options used to create the cell. * * @returns A new code cell. If a source cell is provided, the * new cell will be intialized with the data from the source. */ createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel; /** * Create a new markdown cell. * * @param options - The options used to create the cell. * * @returns A new markdown cell. If a source cell is provided, the * new cell will be intialized with the data from the source. */ createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel; /** * Create a new raw cell. * * @param options - The options used to create the cell. * * @returns A new raw cell. If a source cell is provided, the * new cell will be intialized with the data from the source. */ createRawCell(options: CellModel.IOptions): IRawCellModel; } /** * The default implementation of an `IContentFactory`. */ class ContentFactory { /** * Create a new cell model factory. */ constructor(options: IContentFactoryOptions); /** * The factory for code cell content. */ readonly codeCellContentFactory: CodeCellModel.IContentFactory; /** * Create a new code cell. * * @param source - The data to use for the original source data. * * @returns A new code cell. If a source cell is provided, the * new cell will be intialized with the data from the source. * If the contentFactory is not provided, the instance * `codeCellContentFactory` will be used. */ createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel; /** * Create a new markdown cell. * * @param source - The data to use for the original source data. * * @returns A new markdown cell. If a source cell is provided, the * new cell will be intialized with the data from the source. */ createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel; /** * Create a new raw cell. * * @param source - The data to use for the original source data. * * @returns A new raw cell. If a source cell is provided, the * new cell will be intialized with the data from the source. */ createRawCell(options: CellModel.IOptions): IRawCellModel; } /** * The options used to initialize a `ContentFactory`. */ interface IContentFactoryOptions { /** * The factory for code cell model content. */ codeCellContentFactory?: CodeCellModel.IContentFactory; } /** * The default `ContentFactory` instance. */ const defaultContentFactory: ContentFactory; }