import { IDocumentManager } from '@jupyterlab/docmanager'; const notebookPath = '/path/to/notebook.ipynb'; await manager.services.contents.get(notebookPath, { type: 'file' }) .then(async (model) => { const notebook = await manager.open(model.path); console.log(`Opened notebook "${notebook.context.path}"`); });
const activeNotebook = app.shell.currentWidget; if (activeNotebook instanceof NotebookPanel && activeNotebook.context.isDirty) { await activeNotebook.context.save(); console.log(`Saved changes to notebook "${activeNotebook.context.path}"`); }
const activeDocument = app.shell.currentWidget; if (activeDocument && activeDocument.isDisposed === false) { await manager.saveAndClose(activeDocument.context); console.log(`Closed document "${activeDocument.context.path}"`); }Overall, the `@jupyterlab/docmanager` package provides useful functionality for managing notebooks and documents in JupyterLab and the `IDocumentManager` interface serves as a helpful tool for developers working with JupyterLab.