@jupyterlab/notebook 0.17.2 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../notebook/src/model.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,yDAA0E;AAE1E,6CAS2B;AAE3B,qDAAiD;AAEjD,mDAA2C;AAS3C,yCAAsC;AAgCtC;;GAEG;AACH,mBAA2B,SAAQ,2BAAa;IAC9C;;OAEG;IACH,YAAY,UAAkC,EAAE;QAC9C,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAiP7C,cAAS,GAAG,oBAAQ,CAAC,aAAa,CAAC;QACnC,mBAAc,GAAG,oBAAQ,CAAC,aAAa,CAAC;QAjP9C,IAAI,OAAO,GAAG,OAAO,CAAC,cAAc,IAAI,aAAa,CAAC,qBAAqB,CAAC;QAC5E,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9D,uCAAuC;QACvC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;SAC9C;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAExD,2BAA2B;QAC3B,IAAI,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;Q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AO,IAAI,cAAc,CAAC;gBACxB,OAAO,EAAE,OAAO;gBAChB,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;aACpD,CAAC,CAAC;QACL,CAAC;KACF;IAxFY,4BAAc,iBAwF1B,CAAA;IAsBD;;OAEG;IACU,mCAAqB,GAAG,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC,EA9LgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA8L7B","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { DocumentModel, DocumentRegistry } from '@jupyterlab/docregistry';\n\nimport {\n ICellModel,\n ICodeCellModel,\n IRawCellModel,\n IMarkdownCellModel,\n CodeCellModel,\n RawCellModel,\n MarkdownCellModel,\n CellModel\n} from '@jupyterlab/cells';\n\nimport { nbformat } from '@jupyterlab/coreutils';\n\nimport { UUID } from '@phosphor/coreutils';\n\nimport {\n IObservableJSON,\n IObservableUndoableList,\n IObservableList,\n IModelDB\n} from '@jupyterlab/observables';\n\nimport { CellList } from './celllist';\n\n/**\n * The definition of a model object for a notebook widget.\n */\nexport interface INotebookModel extends DocumentRegistry.IModel {\n /**\n * The list of cells in the notebook.\n */\n readonly cells: IObservableUndoableList<ICellModel>;\n\n /**\n * The cell model factory for the notebook.\n */\n readonly contentFactory: NotebookModel.IContentFactory;\n\n /**\n * The major version number of the nbformat.\n */\n readonly nbformat: number;\n\n /**\n * The minor version number of the nbformat.\n */\n readonly nbformatMinor: number;\n\n /**\n * The metadata associated with the notebook.\n */\n readonly metadata: IObservableJSON;\n}\n\n/**\n * An implementation of a notebook Model.\n */\nexport class NotebookModel extends DocumentModel implements INotebookModel {\n /**\n * Construct a new notebook model.\n */\n constructor(options: NotebookModel.IOptions = {}) {\n super(options.languagePreference, options.modelDB);\n let factory = options.contentFactory || NotebookModel.defaultContentFactory;\n this.contentFactory = factory.clone(this.modelDB.view('cells'));\n this._cells = new CellList(this.modelDB, this.contentFactory);\n // Add an initial code cell by default.\n if (!this._cells.length) {\n this._cells.push(factory.createCodeCell({}));\n }\n this._cells.changed.connect(this._onCellsChanged, this);\n\n // Handle initial metadata.\n let metadata = this.modelDB.createMap('metadata');\n if (!metadata.has('language_info')) {\n let name = options.languagePreference || '';\n metadata.set('language_info', { name });\n }\n this._ensureMetadata();\n metadata.changed.connect(this.triggerContentChange, this);\n }\n\n /**\n * The cell model factory for the notebook.\n */\n readonly contentFactory: NotebookModel.IContentFactory;\n\n /**\n * The metadata associated with the notebook.\n */\n get metadata(): IObservableJSON {\n return this.modelDB.get('metadata') as IObservableJSON;\n }\n\n /**\n * Get the observable list of notebook cells.\n */\n get cells(): IObservableUndoableList<ICellModel> {\n return this._cells;\n }\n\n /**\n * The major version number of the nbformat.\n */\n get nbformat(): number {\n return this._nbformat;\n }\n\n /**\n * The minor version number of the nbformat.\n */\n get nbformatMinor(): number {\n return this._nbformatMinor;\n }\n\n /**\n * The default kernel name of the document.\n */\n get defaultKernelName(): string {\n let spec = this.metadata.get('kernelspec') as nbformat.IKernelspecMetadata;\n return spec ? spec.name : '';\n }\n\n /**\n * The default kernel language of the document.\n */\n get defaultKernelLanguage(): string {\n let info = this.metadata.get(\n 'language_info'\n ) as nbformat.ILanguageInfoMetadata;\n return info ? info.name : '';\n }\n\n /**\n * Dispose of the resources held by the model.\n */\n dispose(): void {\n // Do nothing if already disposed.\n if (this.cells === null) {\n return;\n }\n let cells = this.cells;\n this._cells = null;\n cells.dispose();\n super.dispose();\n }\n\n /**\n * Serialize the model to a string.\n */\n toString(): string {\n return JSON.stringify(this.toJSON());\n }\n\n /**\n * Deserialize the model from a string.\n *\n * #### Notes\n * Should emit a [contentChanged] signal.\n */\n fromString(value: string): void {\n this.fromJSON(JSON.parse(value));\n }\n\n /**\n * Serialize the model to JSON.\n */\n toJSON(): nbformat.INotebookContent {\n let cells: nbformat.ICell[] = [];\n for (let i = 0; i < this.cells.length; i++) {\n let cell = this.cells.get(i);\n cells.push(cell.toJSON());\n }\n this._ensureMetadata();\n let metadata = Object.create(null) as nbformat.INotebookMetadata;\n for (let key of this.metadata.keys()) {\n metadata[key] = JSON.parse(JSON.stringify(this.metadata.get(key)));\n }\n return {\n metadata,\n nbformat_minor: this._nbformatMinor,\n nbformat: this._nbformat,\n cells\n };\n }\n\n /**\n * Deserialize the model from JSON.\n *\n * #### Notes\n * Should emit a [contentChanged] signal.\n */\n fromJSON(value: nbformat.INotebookContent): void {\n let cells: ICellModel[] = [];\n let factory = this.contentFactory;\n for (let cell of value.cells) {\n switch (cell.cell_type) {\n case 'code':\n cells.push(factory.createCodeCell({ cell }));\n break;\n case 'markdown':\n cells.push(factory.createMarkdownCell({ cell }));\n break;\n case 'raw':\n cells.push(factory.createRawCell({ cell }));\n break;\n default:\n continue;\n }\n }\n this.cells.beginCompoundOperation();\n this.cells.clear();\n this.cells.pushAll(cells);\n this.cells.endCompoundOperation();\n\n let oldValue = 0;\n let newValue = 0;\n this._nbformatMinor = nbformat.MINOR_VERSION;\n this._nbformat = nbformat.MAJOR_VERSION;\n\n if (value.nbformat !== this._nbformat) {\n oldValue = this._nbformat;\n this._nbformat = newValue = value.nbformat;\n this.triggerStateChange({ name: 'nbformat', oldValue, newValue });\n }\n if (value.nbformat_minor > this._nbformatMinor) {\n oldValue = this._nbformatMinor;\n this._nbformatMinor = newValue = value.nbformat_minor;\n this.triggerStateChange({ name: 'nbformatMinor', oldValue, newValue });\n }\n // Update the metadata.\n this.metadata.clear();\n let metadata = value.metadata;\n for (let key in metadata) {\n // orig_nbformat is not intended to be stored per spec.\n if (key === 'orig_nbformat') {\n continue;\n }\n this.metadata.set(key, metadata[key]);\n }\n this._ensureMetadata();\n this.dirty = true;\n }\n\n /**\n * Initialize the model with its current state.\n */\n initialize(): void {\n super.initialize();\n this.cells.clearUndo();\n }\n\n /**\n * Handle a change in the cells list.\n */\n private _onCellsChanged(\n list: IObservableList<ICellModel>,\n change: IObservableList.IChangedArgs<ICellModel>\n ): void {\n switch (change.type) {\n case 'add':\n change.newValues.forEach(cell => {\n cell.contentChanged.connect(this.triggerContentChange, this);\n });\n break;\n case 'remove':\n break;\n case 'set':\n change.newValues.forEach(cell => {\n cell.contentChanged.connect(this.triggerContentChange, this);\n });\n break;\n default:\n break;\n }\n let factory = this.contentFactory;\n // Add code cell if there are no cells remaining.\n if (!this.cells.length) {\n // Add the cell in a new context to avoid triggering another\n // cell changed event during the handling of this signal.\n requestAnimationFrame(() => {\n if (!this.isDisposed && !this.cells.length) {\n this.cells.push(factory.createCodeCell({}));\n }\n });\n }\n this.triggerContentChange();\n }\n\n /**\n * Make sure we have the required metadata fields.\n */\n private _ensureMetadata(): void {\n let metadata = this.metadata;\n if (!metadata.has('language_info')) {\n metadata.set('language_info', { name: '' });\n }\n if (!metadata.has('kernelspec')) {\n metadata.set('kernelspec', { name: '', display_name: '' });\n }\n }\n\n private _cells: CellList;\n private _nbformat = nbformat.MAJOR_VERSION;\n private _nbformatMinor = nbformat.MINOR_VERSION;\n}\n\n/**\n * The namespace for the `NotebookModel` class statics.\n */\nexport namespace NotebookModel {\n /**\n * An options object for initializing a notebook model.\n */\n export interface IOptions {\n /**\n * The language preference for the model.\n */\n languagePreference?: string;\n\n /**\n * A factory for creating cell models.\n *\n * The default is a shared factory instance.\n */\n contentFactory?: IContentFactory;\n\n /**\n * A modelDB for storing notebook data.\n */\n modelDB?: IModelDB;\n }\n\n /**\n * A factory for creating notebook model content.\n */\n export interface IContentFactory {\n /**\n * The factory for output area models.\n */\n readonly codeCellContentFactory: CodeCellModel.IContentFactory;\n\n /**\n * The IModelDB in which to put data for the notebook model.\n */\n modelDB: IModelDB;\n\n /**\n * Create a new code cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new code cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;\n\n /**\n * Create a new markdown cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new markdown cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;\n\n /**\n * Create a new raw cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new raw cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createRawCell(options: CellModel.IOptions): IRawCellModel;\n\n /**\n * Clone the content factory with a new IModelDB.\n */\n clone(modelDB: IModelDB): IContentFactory;\n }\n\n /**\n * The default implementation of an `IContentFactory`.\n */\n export class ContentFactory {\n /**\n * Create a new cell model factory.\n */\n constructor(options: ContentFactory.IOptions) {\n this.codeCellContentFactory =\n options.codeCellContentFactory || CodeCellModel.defaultContentFactory;\n this.modelDB = options.modelDB;\n }\n\n /**\n * The factory for code cell content.\n */\n readonly codeCellContentFactory: CodeCellModel.IContentFactory;\n\n /**\n * The IModelDB in which to put the notebook data.\n */\n readonly modelDB: IModelDB | undefined;\n\n /**\n * Create a new code cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new code cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n * If the contentFactory is not provided, the instance\n * `codeCellContentFactory` will be used.\n */\n createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel {\n if (options.contentFactory) {\n options.contentFactory = this.codeCellContentFactory;\n }\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new CodeCellModel(options);\n }\n\n /**\n * Create a new markdown cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new markdown cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel {\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new MarkdownCellModel(options);\n }\n\n /**\n * Create a new raw cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new raw cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createRawCell(options: CellModel.IOptions): IRawCellModel {\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new RawCellModel(options);\n }\n\n /**\n * Clone the content factory with a new IModelDB.\n */\n clone(modelDB: IModelDB): ContentFactory {\n return new ContentFactory({\n modelDB: modelDB,\n codeCellContentFactory: this.codeCellContentFactory\n });\n }\n }\n\n /**\n * A namespace for the notebook model content factory.\n */\n export namespace ContentFactory {\n /**\n * The options used to initialize a `ContentFactory`.\n */\n export interface IOptions {\n /**\n * The factory for code cell model content.\n */\n codeCellContentFactory?: CodeCellModel.IContentFactory;\n\n /**\n * The modelDB in which to place new content.\n */\n modelDB?: IModelDB;\n }\n }\n\n /**\n * The default `ContentFactory` instance.\n */\n export const defaultContentFactory = new ContentFactory({});\n}\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../notebook/src/model.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,yDAA0E;AAE1E,6CAS2B;AAE3B,qDAAiD;AAEjD,mDAA2C;AAS3C,yCAAsC;AAoCtC;;GAEG;AACH,mBAA2B,SAAQ,2BAAa;IAC9C;;OAEG;IACH,YAAY,UAAkC,EAAE;QAC9C,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAuP7C,cAAS,GAAG,oBAAQ,CAAC,aAAa,CAAC;QACnC,mBAAc,GAAG,oBAAQ,CAAC,aAAa,CAAC;QAvP9C,IAAI,OAAO,GAAG,OAAO,CAAC,cAAc,IAAI,aAAa,CAAC,qBAAqB,CAAC;QAC5E,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,c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OAAO,CAAC,EAAE,CAAC,CAAC;aACjD;YACD,OAAO,IAAI,yBAAiB,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;QAED;;;;;;;WAOG;QACH,aAAa,CAAC,OAA2B;YACvC,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;oBACf,OAAO,CAAC,EAAE,GAAG,gBAAI,CAAC,KAAK,EAAE,CAAC;iBAC3B;gBACD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;aACjD;YACD,OAAO,IAAI,oBAAY,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,OAAiB;YACrB,OAAO,IAAI,cAAc,CAAC;gBACxB,OAAO,EAAE,OAAO;gBAChB,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;aACpD,CAAC,CAAC;QACL,CAAC;KACF;IAxFY,4BAAc,iBAwF1B,CAAA;IAsBD;;OAEG;IACU,mCAAqB,GAAG,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC,EA9LgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA8L7B","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { DocumentModel, DocumentRegistry } from '@jupyterlab/docregistry';\n\nimport {\n ICellModel,\n ICodeCellModel,\n IRawCellModel,\n IMarkdownCellModel,\n CodeCellModel,\n RawCellModel,\n MarkdownCellModel,\n CellModel\n} from '@jupyterlab/cells';\n\nimport { nbformat } from '@jupyterlab/coreutils';\n\nimport { UUID } from '@phosphor/coreutils';\n\nimport {\n IObservableJSON,\n IObservableUndoableList,\n IObservableList,\n IModelDB\n} from '@jupyterlab/observables';\n\nimport { CellList } from './celllist';\n\n/**\n * The definition of a model object for a notebook widget.\n */\nexport interface INotebookModel extends DocumentRegistry.IModel {\n /**\n * The list of cells in the notebook.\n */\n readonly cells: IObservableUndoableList<ICellModel>;\n\n /**\n * The cell model factory for the notebook.\n */\n readonly contentFactory: NotebookModel.IContentFactory;\n\n /**\n * The major version number of the nbformat.\n */\n readonly nbformat: number;\n\n /**\n * The minor version number of the nbformat.\n */\n readonly nbformatMinor: number;\n\n /**\n * The metadata associated with the notebook.\n */\n readonly metadata: IObservableJSON;\n /**\n * The array of deleted cells since the notebook was last run.\n */\n readonly deletedCells: string[];\n}\n\n/**\n * An implementation of a notebook Model.\n */\nexport class NotebookModel extends DocumentModel implements INotebookModel {\n /**\n * Construct a new notebook model.\n */\n constructor(options: NotebookModel.IOptions = {}) {\n super(options.languagePreference, options.modelDB);\n let factory = options.contentFactory || NotebookModel.defaultContentFactory;\n this.contentFactory = factory.clone(this.modelDB.view('cells'));\n this._cells = new CellList(this.modelDB, this.contentFactory);\n // Add an initial code cell by default.\n if (!this._cells.length) {\n this._cells.push(factory.createCodeCell({}));\n }\n this._cells.changed.connect(this._onCellsChanged, this);\n\n // Handle initial metadata.\n let metadata = this.modelDB.createMap('metadata');\n if (!metadata.has('language_info')) {\n let name = options.languagePreference || '';\n metadata.set('language_info', { name });\n }\n this._ensureMetadata();\n metadata.changed.connect(this.triggerContentChange, this);\n this._deletedCells = [];\n }\n\n /**\n * The cell model factory for the notebook.\n */\n readonly contentFactory: NotebookModel.IContentFactory;\n\n /**\n * The metadata associated with the notebook.\n */\n get metadata(): IObservableJSON {\n return this.modelDB.get('metadata') as IObservableJSON;\n }\n\n /**\n * Get the observable list of notebook cells.\n */\n get cells(): IObservableUndoableList<ICellModel> {\n return this._cells;\n }\n\n /**\n * The major version number of the nbformat.\n */\n get nbformat(): number {\n return this._nbformat;\n }\n\n /**\n * The minor version number of the nbformat.\n */\n get nbformatMinor(): number {\n return this._nbformatMinor;\n }\n\n /**\n * The default kernel name of the document.\n */\n get defaultKernelName(): string {\n let spec = this.metadata.get('kernelspec') as nbformat.IKernelspecMetadata;\n return spec ? spec.name : '';\n }\n /**\n * The default kernel name of the document.\n */\n get deletedCells(): string[] {\n return this._deletedCells;\n }\n /**\n * The default kernel language of the document.\n */\n get defaultKernelLanguage(): string {\n let info = this.metadata.get(\n 'language_info'\n ) as nbformat.ILanguageInfoMetadata;\n return info ? info.name : '';\n }\n\n /**\n * Dispose of the resources held by the model.\n */\n dispose(): void {\n // Do nothing if already disposed.\n if (this.cells === null) {\n return;\n }\n let cells = this.cells;\n this._cells = null;\n cells.dispose();\n super.dispose();\n }\n\n /**\n * Serialize the model to a string.\n */\n toString(): string {\n return JSON.stringify(this.toJSON());\n }\n\n /**\n * Deserialize the model from a string.\n *\n * #### Notes\n * Should emit a [contentChanged] signal.\n */\n fromString(value: string): void {\n this.fromJSON(JSON.parse(value));\n }\n\n /**\n * Serialize the model to JSON.\n */\n toJSON(): nbformat.INotebookContent {\n let cells: nbformat.ICell[] = [];\n for (let i = 0; i < this.cells.length; i++) {\n let cell = this.cells.get(i);\n cells.push(cell.toJSON());\n }\n this._ensureMetadata();\n let metadata = Object.create(null) as nbformat.INotebookMetadata;\n for (let key of this.metadata.keys()) {\n metadata[key] = JSON.parse(JSON.stringify(this.metadata.get(key)));\n }\n return {\n metadata,\n nbformat_minor: this._nbformatMinor,\n nbformat: this._nbformat,\n cells\n };\n }\n\n /**\n * Deserialize the model from JSON.\n *\n * #### Notes\n * Should emit a [contentChanged] signal.\n */\n fromJSON(value: nbformat.INotebookContent): void {\n let cells: ICellModel[] = [];\n let factory = this.contentFactory;\n for (let cell of value.cells) {\n switch (cell.cell_type) {\n case 'code':\n cells.push(factory.createCodeCell({ cell }));\n break;\n case 'markdown':\n cells.push(factory.createMarkdownCell({ cell }));\n break;\n case 'raw':\n cells.push(factory.createRawCell({ cell }));\n break;\n default:\n continue;\n }\n }\n this.cells.beginCompoundOperation();\n this.cells.clear();\n this.cells.pushAll(cells);\n this.cells.endCompoundOperation();\n\n let oldValue = 0;\n let newValue = 0;\n this._nbformatMinor = nbformat.MINOR_VERSION;\n this._nbformat = nbformat.MAJOR_VERSION;\n\n if (value.nbformat !== this._nbformat) {\n oldValue = this._nbformat;\n this._nbformat = newValue = value.nbformat;\n this.triggerStateChange({ name: 'nbformat', oldValue, newValue });\n }\n if (value.nbformat_minor > this._nbformatMinor) {\n oldValue = this._nbformatMinor;\n this._nbformatMinor = newValue = value.nbformat_minor;\n this.triggerStateChange({ name: 'nbformatMinor', oldValue, newValue });\n }\n // Update the metadata.\n this.metadata.clear();\n let metadata = value.metadata;\n for (let key in metadata) {\n // orig_nbformat is not intended to be stored per spec.\n if (key === 'orig_nbformat') {\n continue;\n }\n this.metadata.set(key, metadata[key]);\n }\n this._ensureMetadata();\n this.dirty = true;\n }\n\n /**\n * Initialize the model with its current state.\n */\n initialize(): void {\n super.initialize();\n this.cells.clearUndo();\n }\n\n /**\n * Handle a change in the cells list.\n */\n private _onCellsChanged(\n list: IObservableList<ICellModel>,\n change: IObservableList.IChangedArgs<ICellModel>\n ): void {\n switch (change.type) {\n case 'add':\n change.newValues.forEach(cell => {\n cell.contentChanged.connect(this.triggerContentChange, this);\n });\n break;\n case 'remove':\n break;\n case 'set':\n change.newValues.forEach(cell => {\n cell.contentChanged.connect(this.triggerContentChange, this);\n });\n break;\n default:\n break;\n }\n let factory = this.contentFactory;\n // Add code cell if there are no cells remaining.\n if (!this.cells.length) {\n // Add the cell in a new context to avoid triggering another\n // cell changed event during the handling of this signal.\n requestAnimationFrame(() => {\n if (!this.isDisposed && !this.cells.length) {\n this.cells.push(factory.createCodeCell({}));\n }\n });\n }\n this.triggerContentChange();\n }\n\n /**\n * Make sure we have the required metadata fields.\n */\n private _ensureMetadata(): void {\n let metadata = this.metadata;\n if (!metadata.has('language_info')) {\n metadata.set('language_info', { name: '' });\n }\n if (!metadata.has('kernelspec')) {\n metadata.set('kernelspec', { name: '', display_name: '' });\n }\n }\n\n private _cells: CellList;\n private _nbformat = nbformat.MAJOR_VERSION;\n private _nbformatMinor = nbformat.MINOR_VERSION;\n private _deletedCells: string[];\n}\n\n/**\n * The namespace for the `NotebookModel` class statics.\n */\nexport namespace NotebookModel {\n /**\n * An options object for initializing a notebook model.\n */\n export interface IOptions {\n /**\n * The language preference for the model.\n */\n languagePreference?: string;\n\n /**\n * A factory for creating cell models.\n *\n * The default is a shared factory instance.\n */\n contentFactory?: IContentFactory;\n\n /**\n * A modelDB for storing notebook data.\n */\n modelDB?: IModelDB;\n }\n\n /**\n * A factory for creating notebook model content.\n */\n export interface IContentFactory {\n /**\n * The factory for output area models.\n */\n readonly codeCellContentFactory: CodeCellModel.IContentFactory;\n\n /**\n * The IModelDB in which to put data for the notebook model.\n */\n modelDB: IModelDB;\n\n /**\n * Create a new code cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new code cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel;\n\n /**\n * Create a new markdown cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new markdown cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;\n\n /**\n * Create a new raw cell.\n *\n * @param options - The options used to create the cell.\n *\n * @returns A new raw cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createRawCell(options: CellModel.IOptions): IRawCellModel;\n\n /**\n * Clone the content factory with a new IModelDB.\n */\n clone(modelDB: IModelDB): IContentFactory;\n }\n\n /**\n * The default implementation of an `IContentFactory`.\n */\n export class ContentFactory {\n /**\n * Create a new cell model factory.\n */\n constructor(options: ContentFactory.IOptions) {\n this.codeCellContentFactory =\n options.codeCellContentFactory || CodeCellModel.defaultContentFactory;\n this.modelDB = options.modelDB;\n }\n\n /**\n * The factory for code cell content.\n */\n readonly codeCellContentFactory: CodeCellModel.IContentFactory;\n\n /**\n * The IModelDB in which to put the notebook data.\n */\n readonly modelDB: IModelDB | undefined;\n\n /**\n * Create a new code cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new code cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n * If the contentFactory is not provided, the instance\n * `codeCellContentFactory` will be used.\n */\n createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel {\n if (options.contentFactory) {\n options.contentFactory = this.codeCellContentFactory;\n }\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new CodeCellModel(options);\n }\n\n /**\n * Create a new markdown cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new markdown cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel {\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new MarkdownCellModel(options);\n }\n\n /**\n * Create a new raw cell.\n *\n * @param source - The data to use for the original source data.\n *\n * @returns A new raw cell. If a source cell is provided, the\n * new cell will be initialized with the data from the source.\n */\n createRawCell(options: CellModel.IOptions): IRawCellModel {\n if (this.modelDB) {\n if (!options.id) {\n options.id = UUID.uuid4();\n }\n options.modelDB = this.modelDB.view(options.id);\n }\n return new RawCellModel(options);\n }\n\n /**\n * Clone the content factory with a new IModelDB.\n */\n clone(modelDB: IModelDB): ContentFactory {\n return new ContentFactory({\n modelDB: modelDB,\n codeCellContentFactory: this.codeCellContentFactory\n });\n }\n }\n\n /**\n * A namespace for the notebook model content factory.\n */\n export namespace ContentFactory {\n /**\n * The options used to initialize a `ContentFactory`.\n */\n export interface IOptions {\n /**\n * The factory for code cell model content.\n */\n codeCellContentFactory?: CodeCellModel.IContentFactory;\n\n /**\n * The modelDB in which to place new content.\n */\n modelDB?: IModelDB;\n }\n }\n\n /**\n * The default `ContentFactory` instance.\n */\n export const defaultContentFactory = new ContentFactory({});\n}\n"]}
package/lib/widget.d.ts CHANGED
@@ -313,9 +313,9 @@ export declare class Notebook extends StaticNotebook {
313
313
  * Get the active cell widget.
314
314
  *
315
315
  * #### Notes
316
- * This is a cell or undefined if there is no active cell.
316
+ * This is a cell or `null` if there is no active cell.
317
317
  */
318
- readonly activeCell: Cell | undefined;
318
+ readonly activeCell: Cell | null;
319
319
  /**
320
320
  * Dispose of the resources held by the widget.
321
321
  */
package/lib/widget.js CHANGED
@@ -517,7 +517,7 @@ class Notebook extends StaticNotebook {
517
517
  constructor(options) {
518
518
  super(Private.processNotebookOptions(options));
519
519
  this._activeCellIndex = -1;
520
- this._activeCell = undefined;
520
+ this._activeCell = null;
521
521
  this._mode = 'command';
522
522
  this._drag = null;
523
523
  this._dragData = null;
@@ -631,7 +631,7 @@ class Notebook extends StaticNotebook {
631
631
  * Get the active cell widget.
632
632
  *
633
633
  * #### Notes
634
- * This is a cell or undefined if there is no active cell.
634
+ * This is a cell or `null` if there is no active cell.
635
635
  */
636
636
  get activeCell() {
637
637
  return this._activeCell;
@@ -643,7 +643,7 @@ class Notebook extends StaticNotebook {
643
643
  if (this.isDisposed) {
644
644
  return;
645
645
  }
646
- this._activeCell = undefined;
646
+ this._activeCell = null;
647
647
  super.dispose();
648
648
  }
649
649
  /**
@@ -1678,7 +1678,7 @@ var Private;
1678
1678
  function createDragImage(count, promptNumber, cellContent) {
1679
1679
  if (count > 1) {
1680
1680
  if (promptNumber !== '') {
1681
- return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: DRAG_IMAGE_CLASS }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }, 'In [' + promptNumber + ']:'), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent)), virtualdom_1.h.div({ className: CELL_DRAG_MULTIPLE_BACK }, '')));
1681
+ return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: DRAG_IMAGE_CLASS }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }, '[' + promptNumber + ']:'), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent)), virtualdom_1.h.div({ className: CELL_DRAG_MULTIPLE_BACK }, '')));
1682
1682
  }
1683
1683
  else {
1684
1684
  return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: DRAG_IMAGE_CLASS }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent)), virtualdom_1.h.div({ className: CELL_DRAG_MULTIPLE_BACK }, '')));
@@ -1686,7 +1686,7 @@ var Private;
1686
1686
  }
1687
1687
  else {
1688
1688
  if (promptNumber !== '') {
1689
- return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: `${DRAG_IMAGE_CLASS} ${SINGLE_DRAG_IMAGE_CLASS}` }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }, 'In [' + promptNumber + ']:'), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent))));
1689
+ return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: `${DRAG_IMAGE_CLASS} ${SINGLE_DRAG_IMAGE_CLASS}` }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }, '[' + promptNumber + ']:'), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent))));
1690
1690
  }
1691
1691
  else {
1692
1692
  return virtualdom_1.VirtualDOM.realize(virtualdom_1.h.div(virtualdom_1.h.div({ className: `${DRAG_IMAGE_CLASS} ${SINGLE_DRAG_IMAGE_CLASS}` }, virtualdom_1.h.span({ className: CELL_DRAG_PROMPT_CLASS }), virtualdom_1.h.span({ className: CELL_DRAG_CONTENT_CLASS }, cellContent))));