@datalayer/jupyter-react 1.1.8 → 1.2.0
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/README.md +74 -1
- package/lib/app/tabs/components/CellComponent.js +4 -2
- package/lib/app/tabs/components/CellComponent.js.map +1 -1
- package/lib/app/tabs/components/NotebookComponent.js +2 -2
- package/lib/app/tabs/components/NotebookComponent.js.map +1 -1
- package/lib/app/tabs/components/ViewerComponent.js +1 -1
- package/lib/app/tabs/components/ViewerComponent.js.map +1 -1
- package/lib/components/cell/Cell.d.ts +5 -8
- package/lib/components/cell/Cell.js +6 -22
- package/lib/components/cell/Cell.js.map +1 -1
- package/lib/components/cell/CellAdapter.d.ts +1 -3
- package/lib/components/cell/CellAdapter.js +5 -17
- package/lib/components/cell/CellAdapter.js.map +1 -1
- package/lib/components/codemirror/CodeMirrorOutputToolbar.d.ts +2 -2
- package/lib/components/codemirror/CodeMirrorOutputToolbar.js.map +1 -1
- package/lib/components/console/ConsoleAdapter.d.ts +1 -1
- package/lib/components/console/ConsoleAdapter.js +1 -1
- package/lib/components/console/ConsoleAdapter.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabApp.d.ts +16 -19
- package/lib/components/jupyterlab/JupyterLabApp.js +27 -21
- package/lib/components/jupyterlab/JupyterLabApp.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabAppAdapter.d.ts +4 -4
- package/lib/components/jupyterlab/JupyterLabAppAdapter.js +1 -1
- package/lib/components/jupyterlab/JupyterLabAppAdapter.js.map +1 -1
- package/lib/components/jupyterlab/JupyterLabAppCss.d.ts +1 -4
- package/lib/components/jupyterlab/JupyterLabAppCss.js +1 -5
- package/lib/components/jupyterlab/JupyterLabAppCss.js.map +1 -1
- package/lib/components/kernel/KernelActionMenu.d.ts +2 -2
- package/lib/components/kernel/KernelActionMenu.js.map +1 -1
- package/lib/components/kernel/KernelDetective.d.ts +1 -1
- package/lib/components/kernel/{Kernelndicator.d.ts → KernelIndicator.d.ts} +2 -1
- package/lib/components/kernel/{Kernelndicator.js → KernelIndicator.js} +13 -5
- package/lib/components/kernel/KernelIndicator.js.map +1 -0
- package/lib/components/kernel/KernelInspector.d.ts +2 -2
- package/lib/components/kernel/KernelInspector.js.map +1 -1
- package/lib/components/kernel/KernelSelector.d.ts +2 -2
- package/lib/components/kernel/KernelSelector.js.map +1 -1
- package/lib/components/kernel/KernelUsage.d.ts +2 -2
- package/lib/components/kernel/KernelUsage.js.map +1 -1
- package/lib/components/kernel/KernelVariables.d.ts +2 -2
- package/lib/components/kernel/KernelVariables.js.map +1 -1
- package/lib/components/kernel/index.d.ts +1 -1
- package/lib/components/kernel/index.js +1 -1
- package/lib/components/kernel/index.js.map +1 -1
- package/lib/components/kernel/variables/kernelconnector.d.ts +2 -2
- package/lib/components/kernel/variables/kernelconnector.js +2 -2
- package/lib/components/kernel/variables/widget.d.ts +4 -2
- package/lib/components/kernel/variables/widget.js.map +1 -1
- package/lib/components/lumino/Lumino.d.ts +1 -1
- package/lib/components/lumino/LuminoBox.d.ts +3 -9
- package/lib/components/lumino/LuminoBox.js +1 -6
- package/lib/components/lumino/LuminoBox.js.map +1 -1
- package/lib/components/lumino/ReactPortalWidget.d.ts +1 -2
- package/lib/components/notebook/Notebook.d.ts +4 -6
- package/lib/components/notebook/Notebook.js +11 -26
- package/lib/components/notebook/Notebook.js.map +1 -1
- package/lib/components/notebook/Notebook2.d.ts +6 -2
- package/lib/components/notebook/Notebook2.js +3 -2
- package/lib/components/notebook/Notebook2.js.map +1 -1
- package/lib/components/notebook/Notebook2Adapter.d.ts +189 -0
- package/lib/components/notebook/Notebook2Adapter.js +554 -10
- package/lib/components/notebook/Notebook2Adapter.js.map +1 -1
- package/lib/components/notebook/Notebook2Base.d.ts +15 -9
- package/lib/components/notebook/Notebook2Base.js +89 -50
- package/lib/components/notebook/Notebook2Base.js.map +1 -1
- package/lib/components/notebook/Notebook2State.d.ts +35 -8
- package/lib/components/notebook/Notebook2State.js +74 -45
- package/lib/components/notebook/Notebook2State.js.map +1 -1
- package/lib/components/notebook/NotebookAdapter.d.ts +1 -0
- package/lib/components/notebook/NotebookAdapter.js +13 -8
- package/lib/components/notebook/NotebookAdapter.js.map +1 -1
- package/lib/components/notebook/NotebookCommands.d.ts +25 -2
- package/lib/components/notebook/NotebookCommands.js +89 -10
- package/lib/components/notebook/NotebookCommands.js.map +1 -1
- package/lib/components/notebook/NotebookState.d.ts +11 -11
- package/lib/components/notebook/cell/sidebar/CellSidebarButton.js +1 -1
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.d.ts +2 -4
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.js +1 -3
- package/lib/components/notebook/cell/sidebar/CellSidebarExtension.js.map +1 -1
- package/lib/components/notebook/index.d.ts +1 -0
- package/lib/components/notebook/index.js +1 -0
- package/lib/components/notebook/index.js.map +1 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.d.ts +28 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.js +15 -1
- package/lib/components/notebook/model/JupyterReactNotebookModelFactory.js.map +1 -1
- package/lib/components/output/Output.d.ts +11 -13
- package/lib/components/output/Output.js +19 -30
- package/lib/components/output/Output.js.map +1 -1
- package/lib/components/output/OutputIPyWidgets.d.ts +2 -2
- package/lib/components/output/OutputIPyWidgets.js.map +1 -1
- package/lib/components/output/OutputRenderer.d.ts +2 -2
- package/lib/components/output/OutputRenderer.js.map +1 -1
- package/lib/components/terminal/Terminal.d.ts +1 -4
- package/lib/components/terminal/Terminal.js +5 -8
- package/lib/components/terminal/Terminal.js.map +1 -1
- package/lib/components/viewer/Viewer.d.ts +1 -1
- package/lib/components/viewer/output/OutputViewer.d.ts +3 -6
- package/lib/components/viewer/output/OutputViewer.js +1 -5
- package/lib/components/viewer/output/OutputViewer.js.map +1 -1
- package/lib/examples/Bokeh.js +2 -2
- package/lib/examples/Bokeh.js.map +1 -1
- package/lib/examples/Bqplot.js +2 -2
- package/lib/examples/Bqplot.js.map +1 -1
- package/lib/examples/Cell.js +4 -4
- package/lib/examples/Cell.js.map +1 -1
- package/lib/examples/CellLite.js +16 -4
- package/lib/examples/CellLite.js.map +1 -1
- package/lib/examples/Cells.js +9 -6
- package/lib/examples/Cells.js.map +1 -1
- package/lib/examples/CellsExecute.js +13 -9
- package/lib/examples/CellsExecute.js.map +1 -1
- package/lib/examples/Console.js +2 -2
- package/lib/examples/Console.js.map +1 -1
- package/lib/examples/ConsoleLite.js +3 -3
- package/lib/examples/ConsoleLite.js.map +1 -1
- package/lib/examples/Dashboard.js +2 -2
- package/lib/examples/Dashboard.js.map +1 -1
- package/lib/examples/Deno.js +2 -2
- package/lib/examples/Deno.js.map +1 -1
- package/lib/examples/Examples.d.ts +23 -0
- package/lib/examples/Examples.js +342 -0
- package/lib/examples/Examples.js.map +1 -0
- package/lib/examples/FileBrowser.js +2 -2
- package/lib/examples/FileBrowser.js.map +1 -1
- package/lib/examples/GeoJson.js +2 -2
- package/lib/examples/GeoJson.js.map +1 -1
- package/lib/examples/IPyLeaflet.js +3 -3
- package/lib/examples/IPyLeaflet.js.map +1 -1
- package/lib/examples/IPyReact.js +3 -3
- package/lib/examples/IPyReact.js.map +1 -1
- package/lib/examples/IPyWidgets.js +3 -3
- package/lib/examples/IPyWidgets.js.map +1 -1
- package/lib/examples/IPyWidgetsState.js +3 -3
- package/lib/examples/IPyWidgetsState.js.map +1 -1
- package/lib/examples/JupyterContext.js +2 -2
- package/lib/examples/JupyterContext.js.map +1 -1
- package/lib/examples/JupyterLabAppHeadless.js +2 -2
- package/lib/examples/JupyterLabAppHeadless.js.map +1 -1
- package/lib/examples/JupyterLabAppHeadlessServerless.js +2 -2
- package/lib/examples/JupyterLabAppHeadlessServerless.js.map +1 -1
- package/lib/examples/JupyterLabAppServerless.js +2 -2
- package/lib/examples/JupyterLabAppServerless.js.map +1 -1
- package/lib/examples/JupyterLabAppServiceManager.js +2 -2
- package/lib/examples/JupyterLabAppServiceManager.js.map +1 -1
- package/lib/examples/JupyterLabTheme.js +2 -2
- package/lib/examples/JupyterLabTheme.js.map +1 -1
- package/lib/examples/KernelExecute.d.ts +1 -1
- package/lib/examples/KernelExecute.js +9 -11
- package/lib/examples/KernelExecute.js.map +1 -1
- package/lib/examples/KernelExecuteLite.d.ts +1 -0
- package/lib/examples/KernelExecuteLite.js +51 -0
- package/lib/examples/KernelExecuteLite.js.map +1 -0
- package/lib/examples/KernelExecutor.js +10 -9
- package/lib/examples/KernelExecutor.js.map +1 -1
- package/lib/examples/KernelExecutorLite.js +63 -0
- package/lib/examples/KernelExecutorLite.js.map +1 -0
- package/lib/examples/Kernels.js +6 -5
- package/lib/examples/Kernels.js.map +1 -1
- package/lib/examples/Lumino.js +2 -2
- package/lib/examples/Lumino.js.map +1 -1
- package/lib/examples/Matplotlib.js +10 -6
- package/lib/examples/Matplotlib.js.map +1 -1
- package/lib/examples/Notebook.js +3 -2
- package/lib/examples/Notebook.js.map +1 -1
- package/lib/examples/Notebook2.js +9 -6
- package/lib/examples/Notebook2.js.map +1 -1
- package/lib/examples/Notebook2Actions.js +8 -6
- package/lib/examples/Notebook2Actions.js.map +1 -1
- package/lib/examples/Notebook2Collaborative.js +2 -2
- package/lib/examples/Notebook2Collaborative.js.map +1 -1
- package/lib/examples/Notebook2Lite.js +19 -14
- package/lib/examples/Notebook2Lite.js.map +1 -1
- package/lib/examples/NotebookCellSidebar.js +3 -3
- package/lib/examples/NotebookCellSidebar.js.map +1 -1
- package/lib/examples/NotebookCellToolbar.js +4 -4
- package/lib/examples/NotebookCellToolbar.js.map +1 -1
- package/lib/examples/NotebookCollaborative.js +2 -2
- package/lib/examples/NotebookCollaborative.js.map +1 -1
- package/lib/examples/NotebookColormode.js +15 -10
- package/lib/examples/NotebookColormode.js.map +1 -1
- package/lib/examples/NotebookExtension.js +4 -4
- package/lib/examples/NotebookExtension.js.map +1 -1
- package/lib/examples/NotebookExternalContent.js +18 -13
- package/lib/examples/NotebookExternalContent.js.map +1 -1
- package/lib/examples/NotebookInit.js +10 -9
- package/lib/examples/NotebookInit.js.map +1 -1
- package/lib/examples/NotebookKernel.js +4 -4
- package/lib/examples/NotebookKernel.js.map +1 -1
- package/lib/examples/NotebookKernelChange.js +2 -2
- package/lib/examples/NotebookKernelChange.js.map +1 -1
- package/lib/examples/NotebookLess.js +4 -4
- package/lib/examples/NotebookLess.js.map +1 -1
- package/lib/examples/NotebookLite.js +10 -6
- package/lib/examples/NotebookLite.js.map +1 -1
- package/lib/examples/NotebookLiteContext.js +10 -5
- package/lib/examples/NotebookLiteContext.js.map +1 -1
- package/lib/examples/NotebookLocalServer.js +3 -3
- package/lib/examples/NotebookLocalServer.js.map +1 -1
- package/lib/examples/NotebookNbformat.js +7 -5
- package/lib/examples/NotebookNbformat.js.map +1 -1
- package/lib/examples/NotebookNbformatChange.js +12 -6
- package/lib/examples/NotebookNbformatChange.js.map +1 -1
- package/lib/examples/NotebookNoContext.js +4 -3
- package/lib/examples/NotebookNoContext.js.map +1 -1
- package/lib/examples/NotebookNoPrimer.js +3 -2
- package/lib/examples/NotebookNoPrimer.js.map +1 -1
- package/lib/examples/NotebookOnSessionConnection.js +5 -5
- package/lib/examples/NotebookOnSessionConnection.js.map +1 -1
- package/lib/examples/NotebookPath.js +2 -2
- package/lib/examples/NotebookPath.js.map +1 -1
- package/lib/examples/NotebookPathChange.js +5 -4
- package/lib/examples/NotebookPathChange.js.map +1 -1
- package/lib/examples/NotebookReadonly.js +4 -4
- package/lib/examples/NotebookReadonly.js.map +1 -1
- package/lib/examples/NotebookServiceManager.js +4 -4
- package/lib/examples/NotebookServiceManager.js.map +1 -1
- package/lib/examples/NotebookSkeleton.js +3 -2
- package/lib/examples/NotebookSkeleton.js.map +1 -1
- package/lib/examples/NotebookTOC.d.ts +1 -0
- package/lib/examples/{NotebookToc.js → NotebookTOC.js} +12 -6
- package/lib/examples/NotebookTOC.js.map +1 -0
- package/lib/examples/NotebookTheme.js +10 -5
- package/lib/examples/NotebookTheme.js.map +1 -1
- package/lib/examples/NotebookThemeColormode.js +4 -4
- package/lib/examples/NotebookThemeColormode.js.map +1 -1
- package/lib/examples/NotebookURL.js +3 -2
- package/lib/examples/NotebookURL.js.map +1 -1
- package/lib/examples/NotebookUnmount.js +13 -7
- package/lib/examples/NotebookUnmount.js.map +1 -1
- package/lib/examples/ObservableHQ.js +2 -2
- package/lib/examples/ObservableHQ.js.map +1 -1
- package/lib/examples/OutputIPyWidgets.js +3 -3
- package/lib/examples/OutputIPyWidgets.js.map +1 -1
- package/lib/examples/OutputWithMonitoring.js +3 -2
- package/lib/examples/OutputWithMonitoring.js.map +1 -1
- package/lib/examples/Outputs.js +8 -8
- package/lib/examples/Outputs.js.map +1 -1
- package/lib/examples/OutputsIpynb.js +4 -4
- package/lib/examples/OutputsIpynb.js.map +1 -1
- package/lib/examples/Panel.js +2 -2
- package/lib/examples/Panel.js.map +1 -1
- package/lib/examples/Plotly.js +2 -2
- package/lib/examples/Plotly.js.map +1 -1
- package/lib/examples/PyGWalker.js +4 -4
- package/lib/examples/PyGWalker.js.map +1 -1
- package/lib/examples/Terminal.js +4 -3
- package/lib/examples/Terminal.js.map +1 -1
- package/lib/examples/Vega.js +2 -2
- package/lib/examples/Vega.js.map +1 -1
- package/lib/examples/Viewer.js +5 -4
- package/lib/examples/Viewer.js.map +1 -1
- package/lib/examples/extensions/celltoolbar/CellToolbarComponent.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/jupyter/Jupyter.d.ts +1 -74
- package/lib/jupyter/Jupyter.js +2 -9
- package/lib/jupyter/Jupyter.js.map +1 -1
- package/lib/jupyter/JupyterConfig.js +7 -5
- package/lib/jupyter/JupyterConfig.js.map +1 -1
- package/lib/jupyter/JupyterContext.d.ts +2 -2
- package/lib/jupyter/collaboration/ICollaborationProvider.js.map +1 -1
- package/lib/jupyter/ipywidgets/classic/htmlmanager.d.ts +6 -0
- package/lib/jupyter/ipywidgets/classic/htmlmanager.js +8 -0
- package/lib/jupyter/ipywidgets/classic/htmlmanager.js.map +1 -1
- package/lib/jupyter/ipywidgets/lab/manager.d.ts +6 -0
- package/lib/jupyter/ipywidgets/lab/manager.js +8 -0
- package/lib/jupyter/ipywidgets/lab/manager.js.map +1 -1
- package/lib/jupyter/ipywidgets/libembed-amd.d.ts +1 -1
- package/lib/jupyter/ipywidgets/libembed-amd.js +1 -1
- package/lib/jupyter/kernel/Kernel.js +21 -15
- package/lib/jupyter/kernel/Kernel.js.map +1 -1
- package/lib/jupyter/kernel/KernelState.d.ts +1 -1
- package/lib/jupyter/lite/Lite.d.ts +1 -1
- package/lib/jupyter/lite/LiteServer.d.ts +2 -2
- package/lib/jupyter/lite/LiteServer.js +21 -6
- package/lib/jupyter/lite/LiteServer.js.map +1 -1
- package/lib/jupyter/lite/contents/broadcast.d.ts +27 -0
- package/lib/jupyter/lite/contents/broadcast.js +60 -0
- package/lib/jupyter/lite/contents/broadcast.js.map +1 -0
- package/lib/jupyter/lite/contents/contents.d.ts +228 -0
- package/lib/jupyter/lite/contents/contents.js +774 -0
- package/lib/jupyter/lite/contents/contents.js.map +1 -0
- package/lib/jupyter/lite/contents/drivecontents.d.ts +92 -0
- package/lib/jupyter/lite/contents/drivecontents.js +133 -0
- package/lib/jupyter/lite/contents/drivecontents.js.map +1 -0
- package/lib/jupyter/lite/contents/drivefs.d.ts +193 -0
- package/lib/jupyter/lite/contents/drivefs.js +432 -0
- package/lib/jupyter/lite/contents/drivefs.js.map +1 -0
- package/lib/jupyter/lite/contents/emscripten.d.ts +89 -0
- package/lib/jupyter/lite/contents/emscripten.js +11 -0
- package/lib/jupyter/lite/contents/emscripten.js.map +1 -0
- package/lib/jupyter/lite/contents/index.d.ts +6 -0
- package/lib/jupyter/lite/contents/index.js +9 -0
- package/lib/jupyter/lite/contents/index.js.map +1 -0
- package/lib/jupyter/lite/contents/tokens.d.ts +136 -0
- package/lib/jupyter/lite/contents/tokens.js +66 -0
- package/lib/jupyter/lite/contents/tokens.js.map +1 -0
- package/lib/jupyter/lite/kernel/index.d.ts +4 -0
- package/lib/jupyter/lite/kernel/index.js +7 -0
- package/lib/jupyter/lite/kernel/index.js.map +1 -0
- package/lib/jupyter/lite/kernel/kernel.d.ts +245 -0
- package/lib/jupyter/lite/kernel/kernel.js +453 -0
- package/lib/jupyter/lite/kernel/kernel.js.map +1 -0
- package/lib/jupyter/lite/kernel/kernels.d.ts +85 -0
- package/lib/jupyter/lite/kernel/kernels.js +218 -0
- package/lib/jupyter/lite/kernel/kernels.js.map +1 -0
- package/lib/jupyter/lite/kernel/kernelspecs.d.ts +53 -0
- package/lib/jupyter/lite/kernel/kernelspecs.js +50 -0
- package/lib/jupyter/lite/kernel/kernelspecs.js.map +1 -0
- package/lib/jupyter/lite/kernel/tokens.d.ts +171 -0
- package/lib/jupyter/lite/kernel/tokens.js +16 -0
- package/lib/jupyter/lite/kernel/tokens.js.map +1 -0
- package/lib/jupyter/lite/licenses/index.d.ts +2 -0
- package/lib/jupyter/lite/licenses/index.js +5 -0
- package/lib/jupyter/lite/licenses/index.js.map +1 -0
- package/lib/jupyter/lite/licenses/licenses.d.ts +35 -0
- package/lib/jupyter/lite/licenses/licenses.js +95 -0
- package/lib/jupyter/lite/licenses/licenses.js.map +1 -0
- package/lib/jupyter/lite/licenses/tokens.d.ts +74 -0
- package/lib/jupyter/lite/licenses/tokens.js +13 -0
- package/lib/jupyter/lite/licenses/tokens.js.map +1 -0
- package/lib/jupyter/lite/localforage/index.d.ts +2 -0
- package/lib/jupyter/lite/localforage/index.js +5 -0
- package/lib/jupyter/lite/localforage/index.js.map +1 -0
- package/lib/jupyter/lite/localforage/memory.d.ts +5 -0
- package/lib/jupyter/lite/localforage/memory.js +10 -0
- package/lib/jupyter/lite/localforage/memory.js.map +1 -0
- package/lib/jupyter/lite/localforage/tokens.d.ts +12 -0
- package/lib/jupyter/lite/localforage/tokens.js +8 -0
- package/lib/jupyter/lite/localforage/tokens.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/_pypi.d.ts +18 -0
- package/lib/jupyter/lite/pyodide-kernel/_pypi.js +45 -0
- package/lib/jupyter/lite/pyodide-kernel/_pypi.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/coincident.worker.d.ts +15 -0
- package/lib/jupyter/lite/pyodide-kernel/coincident.worker.js +63 -0
- package/lib/jupyter/lite/pyodide-kernel/coincident.worker.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/comlink.worker.d.ts +9 -0
- package/lib/jupyter/lite/pyodide-kernel/comlink.worker.js +50 -0
- package/lib/jupyter/lite/pyodide-kernel/comlink.worker.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/index.d.ts +6 -0
- package/lib/jupyter/lite/pyodide-kernel/index.js +9 -0
- package/lib/jupyter/lite/pyodide-kernel/index.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/kernel.d.ts +157 -0
- package/lib/jupyter/lite/pyodide-kernel/kernel.js +294 -0
- package/lib/jupyter/lite/pyodide-kernel/kernel.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/pypi/all-local.json +128 -0
- package/lib/jupyter/lite/pyodide-kernel/pypi/all.json +128 -0
- package/lib/jupyter/lite/pyodide-kernel/schema/piplite.v0.schema.json +113 -0
- package/lib/jupyter/lite/pyodide-kernel/tokens.d.ts +82 -0
- package/lib/jupyter/lite/pyodide-kernel/tokens.js +8 -0
- package/lib/jupyter/lite/pyodide-kernel/tokens.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel/worker.d.ts +138 -0
- package/lib/jupyter/lite/pyodide-kernel/worker.js +426 -0
- package/lib/jupyter/lite/pyodide-kernel/worker.js.map +1 -0
- package/lib/jupyter/lite/pyodide-kernel-extension/index.d.ts +4 -0
- package/lib/jupyter/lite/pyodide-kernel-extension/index.js +88 -0
- package/lib/jupyter/lite/pyodide-kernel-extension/index.js.map +1 -0
- package/lib/jupyter/lite/server/app.d.ts +87 -0
- package/lib/jupyter/lite/server/app.js +157 -0
- package/lib/jupyter/lite/server/app.js.map +1 -0
- package/lib/jupyter/lite/server/index.d.ts +4 -0
- package/lib/jupyter/lite/server/index.js +7 -0
- package/lib/jupyter/lite/server/index.js.map +1 -0
- package/lib/jupyter/lite/server/router.d.ts +99 -0
- package/lib/jupyter/lite/server/router.js +109 -0
- package/lib/jupyter/lite/server/router.js.map +1 -0
- package/lib/jupyter/lite/server/service-manager.d.ts +21 -0
- package/lib/jupyter/lite/server/service-manager.js +102 -0
- package/lib/jupyter/lite/server/service-manager.js.map +1 -0
- package/lib/jupyter/lite/server/service-worker.d.ts +58 -0
- package/lib/jupyter/lite/server/service-worker.js +145 -0
- package/lib/jupyter/lite/server/service-worker.js.map +1 -0
- package/lib/jupyter/lite/server/status.d.ts +18 -0
- package/lib/jupyter/lite/server/status.js +21 -0
- package/lib/jupyter/lite/server/status.js.map +1 -0
- package/lib/jupyter/lite/server/tokens.d.ts +38 -0
- package/lib/jupyter/lite/server/tokens.js +8 -0
- package/lib/jupyter/lite/server/tokens.js.map +1 -0
- package/lib/jupyter/lite/server-extension/index.d.ts +3 -0
- package/lib/jupyter/lite/server-extension/index.js +500 -0
- package/lib/jupyter/lite/server-extension/index.js.map +1 -0
- package/lib/jupyter/lite/session/index.d.ts +2 -0
- package/lib/jupyter/lite/session/index.js +5 -0
- package/lib/jupyter/lite/session/index.js.map +1 -0
- package/lib/jupyter/lite/session/sessions.d.ts +68 -0
- package/lib/jupyter/lite/session/sessions.js +185 -0
- package/lib/jupyter/lite/session/sessions.js.map +1 -0
- package/lib/jupyter/lite/session/tokens.d.ts +40 -0
- package/lib/jupyter/lite/session/tokens.js +6 -0
- package/lib/jupyter/lite/session/tokens.js.map +1 -0
- package/lib/jupyter/lite/settings/index.d.ts +2 -0
- package/lib/jupyter/lite/settings/index.js +5 -0
- package/lib/jupyter/lite/settings/index.js.map +1 -0
- package/lib/jupyter/lite/settings/settings.d.ts +75 -0
- package/lib/jupyter/lite/settings/settings.js +155 -0
- package/lib/jupyter/lite/settings/settings.js.map +1 -0
- package/lib/jupyter/lite/settings/tokens.d.ts +65 -0
- package/lib/jupyter/lite/settings/tokens.js +6 -0
- package/lib/jupyter/lite/settings/tokens.js.map +1 -0
- package/lib/jupyter/lite/translation/index.d.ts +2 -0
- package/lib/jupyter/lite/translation/index.js +5 -0
- package/lib/jupyter/lite/translation/index.js.map +1 -0
- package/lib/jupyter/lite/translation/tokens.d.ts +17 -0
- package/lib/jupyter/lite/translation/tokens.js +6 -0
- package/lib/jupyter/lite/translation/tokens.js.map +1 -0
- package/lib/jupyter/lite/translation/translation.d.ts +13 -0
- package/lib/jupyter/lite/translation/translation.js +52 -0
- package/lib/jupyter/lite/translation/translation.js.map +1 -0
- package/lib/jupyter/lite/types/index.d.ts +1 -0
- package/lib/jupyter/lite/types/index.js +4 -0
- package/lib/jupyter/lite/types/index.js.map +1 -0
- package/lib/jupyter/lite/types/tokens.d.ts +27 -0
- package/lib/jupyter/lite/types/tokens.js +4 -0
- package/lib/jupyter/lite/types/tokens.js.map +1 -0
- package/lib/jupyter/services/ServiceManagerLite.js +15 -6
- package/lib/jupyter/services/ServiceManagerLite.js.map +1 -1
- package/lib/state/JupyterReactState.js +7 -8
- package/lib/state/JupyterReactState.js.map +1 -1
- package/lib/theme/JupyterLabCss.d.ts +1 -1
- package/lib/theme/JupyterLabCss.js +4 -2
- package/lib/theme/JupyterLabCss.js.map +1 -1
- package/lib/theme/JupyterReactTheme.d.ts +1 -1
- package/lib/tools/__tests__/operationRunner.test.d.ts +1 -0
- package/lib/tools/__tests__/operationRunner.test.js +193 -0
- package/lib/tools/__tests__/operationRunner.test.js.map +1 -0
- package/lib/tools/core/executor.d.ts +46 -0
- package/lib/tools/core/executor.js +55 -0
- package/lib/tools/core/executor.js.map +1 -0
- package/lib/tools/core/formatter.d.ts +20 -0
- package/lib/tools/core/formatter.js +41 -0
- package/lib/tools/core/formatter.js.map +1 -0
- package/lib/tools/core/index.d.ts +18 -0
- package/lib/tools/core/index.js +24 -0
- package/lib/tools/core/index.js.map +1 -0
- package/lib/tools/core/interfaces.d.ts +38 -0
- package/lib/tools/core/interfaces.js +7 -0
- package/lib/tools/core/interfaces.js.map +1 -0
- package/lib/tools/core/operationRunner.d.ts +27 -0
- package/lib/tools/core/operationRunner.js +33 -0
- package/lib/tools/core/operationRunner.js.map +1 -0
- package/lib/tools/core/schema.d.ts +47 -0
- package/lib/tools/core/schema.js +7 -0
- package/lib/tools/core/schema.js.map +1 -0
- package/lib/tools/core/types.d.ts +36 -0
- package/lib/tools/core/types.js +7 -0
- package/lib/tools/core/types.js.map +1 -0
- package/lib/tools/core/zodUtils.d.ts +56 -0
- package/lib/tools/core/zodUtils.js +179 -0
- package/lib/tools/core/zodUtils.js.map +1 -0
- package/lib/tools/definitions/deleteCell.d.ts +7 -0
- package/lib/tools/definitions/deleteCell.js +25 -0
- package/lib/tools/definitions/deleteCell.js.map +1 -0
- package/lib/tools/definitions/executeCode.d.ts +7 -0
- package/lib/tools/definitions/executeCode.js +33 -0
- package/lib/tools/definitions/executeCode.js.map +1 -0
- package/lib/tools/definitions/index.d.ts +12 -0
- package/lib/tools/definitions/index.js +18 -0
- package/lib/tools/definitions/index.js.map +1 -0
- package/lib/tools/definitions/insertCell.d.ts +7 -0
- package/lib/tools/definitions/insertCell.js +24 -0
- package/lib/tools/definitions/insertCell.js.map +1 -0
- package/lib/tools/definitions/readAllCells.d.ts +7 -0
- package/lib/tools/definitions/readAllCells.js +24 -0
- package/lib/tools/definitions/readAllCells.js.map +1 -0
- package/lib/tools/definitions/readCell.d.ts +7 -0
- package/lib/tools/definitions/readCell.js +24 -0
- package/lib/tools/definitions/readCell.js.map +1 -0
- package/lib/tools/definitions/runCell.d.ts +7 -0
- package/lib/tools/definitions/runCell.js +31 -0
- package/lib/tools/definitions/runCell.js.map +1 -0
- package/lib/tools/definitions/updateCell.d.ts +7 -0
- package/lib/tools/definitions/updateCell.js +24 -0
- package/lib/tools/definitions/updateCell.js.map +1 -0
- package/lib/tools/index.d.ts +20 -0
- package/lib/tools/index.js +62 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/tools/operations/deleteCell.d.ts +49 -0
- package/lib/tools/operations/deleteCell.js +103 -0
- package/lib/tools/operations/deleteCell.js.map +1 -0
- package/lib/tools/operations/executeCode.d.ts +33 -0
- package/lib/tools/operations/executeCode.js +45 -0
- package/lib/tools/operations/executeCode.js.map +1 -0
- package/lib/tools/operations/insertCell.d.ts +27 -0
- package/lib/tools/operations/insertCell.js +56 -0
- package/lib/tools/operations/insertCell.js.map +1 -0
- package/lib/tools/operations/readAllCells.d.ts +21 -0
- package/lib/tools/operations/readAllCells.js +45 -0
- package/lib/tools/operations/readAllCells.js.map +1 -0
- package/lib/tools/operations/readCell.d.ts +39 -0
- package/lib/tools/operations/readCell.js +90 -0
- package/lib/tools/operations/readCell.js.map +1 -0
- package/lib/tools/operations/runCell.d.ts +24 -0
- package/lib/tools/operations/runCell.js +124 -0
- package/lib/tools/operations/runCell.js.map +1 -0
- package/lib/tools/operations/updateCell.d.ts +27 -0
- package/lib/tools/operations/updateCell.js +53 -0
- package/lib/tools/operations/updateCell.js.map +1 -0
- package/lib/tools/schemas/deleteCell.d.ts +20 -0
- package/lib/tools/schemas/deleteCell.js +24 -0
- package/lib/tools/schemas/deleteCell.js.map +1 -0
- package/lib/tools/schemas/executeCode.d.ts +19 -0
- package/lib/tools/schemas/executeCode.js +28 -0
- package/lib/tools/schemas/executeCode.js.map +1 -0
- package/lib/tools/schemas/index.d.ts +12 -0
- package/lib/tools/schemas/index.js +18 -0
- package/lib/tools/schemas/index.js.map +1 -0
- package/lib/tools/schemas/insertCell.d.ts +24 -0
- package/lib/tools/schemas/insertCell.js +29 -0
- package/lib/tools/schemas/insertCell.js.map +1 -0
- package/lib/tools/schemas/readAllCells.d.ts +19 -0
- package/lib/tools/schemas/readAllCells.js +18 -0
- package/lib/tools/schemas/readAllCells.js.map +1 -0
- package/lib/tools/schemas/readCell.d.ts +19 -0
- package/lib/tools/schemas/readCell.js +24 -0
- package/lib/tools/schemas/readCell.js.map +1 -0
- package/lib/tools/schemas/runCell.d.ts +21 -0
- package/lib/tools/schemas/runCell.js +39 -0
- package/lib/tools/schemas/runCell.js.map +1 -0
- package/lib/tools/schemas/updateCell.d.ts +19 -0
- package/lib/tools/schemas/updateCell.js +21 -0
- package/lib/tools/schemas/updateCell.js.map +1 -0
- package/package.json +40 -28
- package/schema/kernel.v0.schema.json +42 -0
- package/style/icons/pyodide.svg +17 -0
- package/lib/components/kernel/Kernelndicator.js.map +0 -1
- package/lib/examples/NotebookToc.js.map +0 -1
- /package/lib/examples/{NotebookToc.d.ts → KernelExecutorLite.d.ts} +0 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
2
|
+
import { PathExt } from '@jupyterlab/coreutils';
|
|
3
|
+
import { MIME, FILE } from './tokens';
|
|
4
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
5
|
+
/**
|
|
6
|
+
* The name of the local storage.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_STORAGE_NAME = 'JupyterLite Storage';
|
|
9
|
+
/**
|
|
10
|
+
* The number of checkpoints to save.
|
|
11
|
+
*/
|
|
12
|
+
const N_CHECKPOINTS = 5;
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
const decoder = new TextDecoder('utf-8');
|
|
15
|
+
/**
|
|
16
|
+
* A class to handle requests to /api/contents
|
|
17
|
+
*/
|
|
18
|
+
export class Contents {
|
|
19
|
+
/**
|
|
20
|
+
* Construct a new localForage-powered contents provider
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this._localforage = options.localforage;
|
|
24
|
+
this._storageName = options.storageName || DEFAULT_STORAGE_NAME;
|
|
25
|
+
this._storageDrivers = options.storageDrivers || null;
|
|
26
|
+
this._ready = new PromiseDelegate();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Finish any initialization after server has started and all extensions are applied.
|
|
30
|
+
*/
|
|
31
|
+
async initialize() {
|
|
32
|
+
await this.initStorage();
|
|
33
|
+
this._ready.resolve(void 0);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Initialize all storage instances
|
|
37
|
+
*/
|
|
38
|
+
async initStorage() {
|
|
39
|
+
this._storage = this.createDefaultStorage();
|
|
40
|
+
this._counters = this.createDefaultCounters();
|
|
41
|
+
this._checkpoints = this.createDefaultCheckpoints();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A promise that resolves once all storage is fully initialized.
|
|
45
|
+
*/
|
|
46
|
+
get ready() {
|
|
47
|
+
return this._ready.promise;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A lazy reference to the underlying storage.
|
|
51
|
+
*/
|
|
52
|
+
get storage() {
|
|
53
|
+
return this.ready.then(() => this._storage);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A lazy reference to the underlying counters.
|
|
57
|
+
*/
|
|
58
|
+
get counters() {
|
|
59
|
+
return this.ready.then(() => this._counters);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A lazy reference to the underlying checkpoints.
|
|
63
|
+
*/
|
|
64
|
+
get checkpoints() {
|
|
65
|
+
return this.ready.then(() => this._checkpoints);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get default options for localForage instances
|
|
69
|
+
*/
|
|
70
|
+
get defaultStorageOptions() {
|
|
71
|
+
const driver = this._storageDrivers && this._storageDrivers.length
|
|
72
|
+
? this._storageDrivers
|
|
73
|
+
: null;
|
|
74
|
+
return {
|
|
75
|
+
version: 1,
|
|
76
|
+
name: this._storageName,
|
|
77
|
+
...(driver ? { driver } : {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Initialize the default storage for contents.
|
|
82
|
+
*/
|
|
83
|
+
createDefaultStorage() {
|
|
84
|
+
return this._localforage.createInstance({
|
|
85
|
+
description: 'Offline Storage for Notebooks and Files',
|
|
86
|
+
storeName: 'files',
|
|
87
|
+
...this.defaultStorageOptions,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Initialize the default storage for counting file suffixes.
|
|
92
|
+
*/
|
|
93
|
+
createDefaultCounters() {
|
|
94
|
+
return this._localforage.createInstance({
|
|
95
|
+
description: 'Store the current file suffix counters',
|
|
96
|
+
storeName: 'counters',
|
|
97
|
+
...this.defaultStorageOptions,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create the default checkpoint storage.
|
|
102
|
+
*/
|
|
103
|
+
createDefaultCheckpoints() {
|
|
104
|
+
return this._localforage.createInstance({
|
|
105
|
+
description: 'Offline Storage for Checkpoints',
|
|
106
|
+
storeName: 'checkpoints',
|
|
107
|
+
...this.defaultStorageOptions,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a new untitled file or directory in the specified directory path.
|
|
112
|
+
*
|
|
113
|
+
* @param options: The options used to create the file.
|
|
114
|
+
*
|
|
115
|
+
* @returns A promise which resolves with the created file content when the file is created.
|
|
116
|
+
*/
|
|
117
|
+
async newUntitled(options) {
|
|
118
|
+
const path = options?.path ?? '';
|
|
119
|
+
const type = options?.type ?? 'notebook';
|
|
120
|
+
const created = new Date().toISOString();
|
|
121
|
+
let dirname = PathExt.dirname(path);
|
|
122
|
+
const basename = PathExt.basename(path);
|
|
123
|
+
const extname = PathExt.extname(path);
|
|
124
|
+
const item = await this.get(dirname);
|
|
125
|
+
// handle the case of "Save As", where the path points to the new file
|
|
126
|
+
// to create, e.g. subfolder/example-copy.ipynb
|
|
127
|
+
let name = '';
|
|
128
|
+
if (path && !extname && item) {
|
|
129
|
+
// directory
|
|
130
|
+
dirname = `${path}/`;
|
|
131
|
+
name = '';
|
|
132
|
+
}
|
|
133
|
+
else if (dirname && basename) {
|
|
134
|
+
// file in a subfolder
|
|
135
|
+
dirname = `${dirname}/`;
|
|
136
|
+
name = basename;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// file at the top level
|
|
140
|
+
dirname = '';
|
|
141
|
+
name = path;
|
|
142
|
+
}
|
|
143
|
+
let file;
|
|
144
|
+
switch (type) {
|
|
145
|
+
case 'directory': {
|
|
146
|
+
const counter = await this._incrementCounter('directory');
|
|
147
|
+
name = `Untitled Folder${counter || ''}`;
|
|
148
|
+
file = {
|
|
149
|
+
name,
|
|
150
|
+
path: `${dirname}${name}`,
|
|
151
|
+
last_modified: created,
|
|
152
|
+
created,
|
|
153
|
+
format: 'json',
|
|
154
|
+
mimetype: '',
|
|
155
|
+
content: null,
|
|
156
|
+
size: 0,
|
|
157
|
+
writable: true,
|
|
158
|
+
type: 'directory',
|
|
159
|
+
};
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'notebook': {
|
|
163
|
+
const counter = await this._incrementCounter('notebook');
|
|
164
|
+
name = name || `Untitled${counter || ''}.ipynb`;
|
|
165
|
+
file = {
|
|
166
|
+
name,
|
|
167
|
+
path: `${dirname}${name}`,
|
|
168
|
+
last_modified: created,
|
|
169
|
+
created,
|
|
170
|
+
format: 'json',
|
|
171
|
+
mimetype: MIME.JSON,
|
|
172
|
+
content: Private.EMPTY_NB,
|
|
173
|
+
size: encoder.encode(JSON.stringify(Private.EMPTY_NB)).length,
|
|
174
|
+
writable: true,
|
|
175
|
+
type: 'notebook',
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
default: {
|
|
180
|
+
const ext = options?.ext ?? '.txt';
|
|
181
|
+
const counter = await this._incrementCounter('file');
|
|
182
|
+
const mimetype = FILE.getType(ext) || MIME.OCTET_STREAM;
|
|
183
|
+
let format;
|
|
184
|
+
if (FILE.hasFormat(ext, 'text') || mimetype.indexOf('text') !== -1) {
|
|
185
|
+
format = 'text';
|
|
186
|
+
}
|
|
187
|
+
else if (ext.indexOf('json') !== -1 || ext.indexOf('ipynb') !== -1) {
|
|
188
|
+
format = 'json';
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
format = 'base64';
|
|
192
|
+
}
|
|
193
|
+
name = name || `untitled${counter || ''}${ext}`;
|
|
194
|
+
file = {
|
|
195
|
+
name,
|
|
196
|
+
path: `${dirname}${name}`,
|
|
197
|
+
last_modified: created,
|
|
198
|
+
created,
|
|
199
|
+
format,
|
|
200
|
+
mimetype,
|
|
201
|
+
content: '',
|
|
202
|
+
size: 0,
|
|
203
|
+
writable: true,
|
|
204
|
+
type: 'file',
|
|
205
|
+
};
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const key = file.path;
|
|
210
|
+
await (await this.storage).setItem(key, file);
|
|
211
|
+
return file;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Copy a file into a given directory.
|
|
215
|
+
*
|
|
216
|
+
* @param path - The original file path.
|
|
217
|
+
* @param toDir - The destination directory path.
|
|
218
|
+
*
|
|
219
|
+
* @returns A promise which resolves with the new contents model when the
|
|
220
|
+
* file is copied.
|
|
221
|
+
*
|
|
222
|
+
* #### Notes
|
|
223
|
+
* The server will select the name of the copied file.
|
|
224
|
+
*/
|
|
225
|
+
async copy(path, toDir) {
|
|
226
|
+
let name = PathExt.basename(path);
|
|
227
|
+
toDir = toDir === '' ? '' : `${PathExt.removeSlash(toDir)}/`;
|
|
228
|
+
// TODO: better handle naming collisions with existing files
|
|
229
|
+
while (await this.get(`${toDir}${name}`, { content: true })) {
|
|
230
|
+
const ext = PathExt.extname(name);
|
|
231
|
+
const base = name.replace(ext, '');
|
|
232
|
+
name = `${base} (copy)${ext}`;
|
|
233
|
+
}
|
|
234
|
+
const toPath = `${toDir}${name}`;
|
|
235
|
+
let item = await this.get(path, { content: true });
|
|
236
|
+
if (!item) {
|
|
237
|
+
throw Error(`Could not find file with path ${path}`);
|
|
238
|
+
}
|
|
239
|
+
item = {
|
|
240
|
+
...item,
|
|
241
|
+
name,
|
|
242
|
+
path: toPath,
|
|
243
|
+
};
|
|
244
|
+
await (await this.storage).setItem(toPath, item);
|
|
245
|
+
return item;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get a file or directory.
|
|
249
|
+
*
|
|
250
|
+
* @param path: The path to the file.
|
|
251
|
+
* @param options: The options used to fetch the file.
|
|
252
|
+
*
|
|
253
|
+
* @returns A promise which resolves with the file content.
|
|
254
|
+
*/
|
|
255
|
+
async get(path, options) {
|
|
256
|
+
// remove leading slash
|
|
257
|
+
path = decodeURIComponent(path.replace(/^\//, ''));
|
|
258
|
+
if (path === '') {
|
|
259
|
+
return await this._getFolder(path);
|
|
260
|
+
}
|
|
261
|
+
const storage = await this.storage;
|
|
262
|
+
const item = await storage.getItem(path);
|
|
263
|
+
const serverItem = await this._getServerContents(path, options);
|
|
264
|
+
const model = (item || serverItem);
|
|
265
|
+
if (!model) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
if (!options?.content) {
|
|
269
|
+
return {
|
|
270
|
+
size: 0,
|
|
271
|
+
...model,
|
|
272
|
+
content: null,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// for directories, find all files with the path as the prefix
|
|
276
|
+
if (model.type === 'directory') {
|
|
277
|
+
const contentMap = new Map();
|
|
278
|
+
await storage.iterate((file, key) => {
|
|
279
|
+
// use an additional slash to not include the directory itself
|
|
280
|
+
if (key === `${path}/${file.name}`) {
|
|
281
|
+
contentMap.set(file.name, file);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
const serverContents = serverItem
|
|
285
|
+
? serverItem.content
|
|
286
|
+
: Array.from((await this._getServerDirectory(path)).values());
|
|
287
|
+
for (const file of serverContents) {
|
|
288
|
+
if (!contentMap.has(file.name)) {
|
|
289
|
+
contentMap.set(file.name, file);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const content = [...contentMap.values()];
|
|
293
|
+
return {
|
|
294
|
+
name: PathExt.basename(path),
|
|
295
|
+
path,
|
|
296
|
+
last_modified: model.last_modified,
|
|
297
|
+
created: model.created,
|
|
298
|
+
format: 'json',
|
|
299
|
+
mimetype: MIME.JSON,
|
|
300
|
+
content,
|
|
301
|
+
size: 0,
|
|
302
|
+
writable: true,
|
|
303
|
+
type: 'directory',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return model;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Rename a file or directory.
|
|
310
|
+
*
|
|
311
|
+
* @param oldLocalPath - The original file path.
|
|
312
|
+
* @param newLocalPath - The new file path.
|
|
313
|
+
*
|
|
314
|
+
* @returns A promise which resolves with the new file content model when the file is renamed.
|
|
315
|
+
*/
|
|
316
|
+
async rename(oldLocalPath, newLocalPath) {
|
|
317
|
+
const path = decodeURIComponent(oldLocalPath);
|
|
318
|
+
const file = await this.get(path, { content: true });
|
|
319
|
+
if (!file) {
|
|
320
|
+
throw Error(`Could not find file with path ${path}`);
|
|
321
|
+
}
|
|
322
|
+
const modified = new Date().toISOString();
|
|
323
|
+
const name = PathExt.basename(newLocalPath);
|
|
324
|
+
const newFile = {
|
|
325
|
+
...file,
|
|
326
|
+
name,
|
|
327
|
+
path: newLocalPath,
|
|
328
|
+
last_modified: modified,
|
|
329
|
+
};
|
|
330
|
+
const storage = await this.storage;
|
|
331
|
+
await storage.setItem(newLocalPath, newFile);
|
|
332
|
+
// remove the old file
|
|
333
|
+
await storage.removeItem(path);
|
|
334
|
+
// remove the corresponding checkpoint
|
|
335
|
+
await (await this.checkpoints).removeItem(path);
|
|
336
|
+
// if a directory, recurse through all children
|
|
337
|
+
if (file.type === 'directory') {
|
|
338
|
+
let child;
|
|
339
|
+
for (child of file.content) {
|
|
340
|
+
await this.rename(URLExt.join(oldLocalPath, child.name), URLExt.join(newLocalPath, child.name));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return newFile;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Save a file.
|
|
347
|
+
*
|
|
348
|
+
* @param path - The desired file path.
|
|
349
|
+
* @param options - Optional overrides to the model.
|
|
350
|
+
*
|
|
351
|
+
* @returns A promise which resolves with the file content model when the file is saved.
|
|
352
|
+
*/
|
|
353
|
+
async save(path, options = {}) {
|
|
354
|
+
path = decodeURIComponent(path);
|
|
355
|
+
// process the file if coming from an upload
|
|
356
|
+
const ext = PathExt.extname(options.name ?? '');
|
|
357
|
+
const chunk = options.chunk;
|
|
358
|
+
// retrieve the content if it is a later chunk or the last one
|
|
359
|
+
// the new content will then be appended to the existing one
|
|
360
|
+
const appendChunk = chunk ? chunk > 1 || chunk === -1 : false;
|
|
361
|
+
let item = await this.get(path, { content: appendChunk });
|
|
362
|
+
if (!item) {
|
|
363
|
+
item = await this.newUntitled({ path, ext, type: 'file' });
|
|
364
|
+
}
|
|
365
|
+
if (!item) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
// keep a reference to the original content
|
|
369
|
+
const originalContent = item.content;
|
|
370
|
+
const modified = new Date().toISOString();
|
|
371
|
+
// override with the new values
|
|
372
|
+
item = {
|
|
373
|
+
...item,
|
|
374
|
+
...options,
|
|
375
|
+
last_modified: modified,
|
|
376
|
+
};
|
|
377
|
+
if (options.content && options.format === 'base64') {
|
|
378
|
+
const lastChunk = chunk ? chunk === -1 : true;
|
|
379
|
+
const contentBinaryString = this._handleUploadChunk(options.content, originalContent, appendChunk);
|
|
380
|
+
if (ext === '.ipynb') {
|
|
381
|
+
const content = lastChunk
|
|
382
|
+
? JSON.parse(decoder.decode(this._binaryStringToBytes(contentBinaryString)))
|
|
383
|
+
: contentBinaryString;
|
|
384
|
+
item = {
|
|
385
|
+
...item,
|
|
386
|
+
content,
|
|
387
|
+
format: 'json',
|
|
388
|
+
type: 'notebook',
|
|
389
|
+
size: contentBinaryString.length,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
else if (FILE.hasFormat(ext, 'json')) {
|
|
393
|
+
const content = lastChunk
|
|
394
|
+
? JSON.parse(decoder.decode(this._binaryStringToBytes(contentBinaryString)))
|
|
395
|
+
: contentBinaryString;
|
|
396
|
+
item = {
|
|
397
|
+
...item,
|
|
398
|
+
content,
|
|
399
|
+
format: 'json',
|
|
400
|
+
type: 'file',
|
|
401
|
+
size: contentBinaryString.length,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
else if (FILE.hasFormat(ext, 'text')) {
|
|
405
|
+
const content = lastChunk
|
|
406
|
+
? decoder.decode(this._binaryStringToBytes(contentBinaryString))
|
|
407
|
+
: contentBinaryString;
|
|
408
|
+
item = {
|
|
409
|
+
...item,
|
|
410
|
+
content,
|
|
411
|
+
format: 'text',
|
|
412
|
+
type: 'file',
|
|
413
|
+
size: contentBinaryString.length,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
const content = lastChunk
|
|
418
|
+
? btoa(contentBinaryString)
|
|
419
|
+
: contentBinaryString;
|
|
420
|
+
item = {
|
|
421
|
+
...item,
|
|
422
|
+
content,
|
|
423
|
+
format: 'base64',
|
|
424
|
+
type: 'file',
|
|
425
|
+
size: contentBinaryString.length,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// fixup content sizes if necessary
|
|
430
|
+
if (item.content) {
|
|
431
|
+
switch (options.format) {
|
|
432
|
+
case 'json': {
|
|
433
|
+
item = {
|
|
434
|
+
...item,
|
|
435
|
+
size: encoder.encode(JSON.stringify(item.content)).length,
|
|
436
|
+
};
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case 'text': {
|
|
440
|
+
item = { ...item, size: encoder.encode(item.content).length };
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
// base64 save was already handled above
|
|
444
|
+
case 'base64': {
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
default: {
|
|
448
|
+
item = { ...item, size: 0 };
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
item = { ...item, size: 0 };
|
|
455
|
+
}
|
|
456
|
+
await (await this.storage).setItem(path, item);
|
|
457
|
+
return item;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Delete a file from browser storage.
|
|
461
|
+
*
|
|
462
|
+
* Has no effect on server-backed files, which will re-appear with their
|
|
463
|
+
* original timestamp.
|
|
464
|
+
*
|
|
465
|
+
* @param path - The path to the file.
|
|
466
|
+
*/
|
|
467
|
+
async delete(path) {
|
|
468
|
+
path = decodeURIComponent(path);
|
|
469
|
+
const slashed = `${path}/`;
|
|
470
|
+
const toDelete = (await (await this.storage).keys()).filter(key => key === path || key.startsWith(slashed));
|
|
471
|
+
await Promise.all(toDelete.map(this.forgetPath, this));
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Remove the localForage and checkpoints for a path.
|
|
475
|
+
*
|
|
476
|
+
* @param path - The path to the file
|
|
477
|
+
*/
|
|
478
|
+
async forgetPath(path) {
|
|
479
|
+
await Promise.all([
|
|
480
|
+
(await this.storage).removeItem(path),
|
|
481
|
+
(await this.checkpoints).removeItem(path),
|
|
482
|
+
]);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Create a checkpoint for a file.
|
|
486
|
+
*
|
|
487
|
+
* @param path - The path of the file.
|
|
488
|
+
*
|
|
489
|
+
* @returns A promise which resolves with the new checkpoint model when the
|
|
490
|
+
* checkpoint is created.
|
|
491
|
+
*/
|
|
492
|
+
async createCheckpoint(path) {
|
|
493
|
+
const checkpoints = await this.checkpoints;
|
|
494
|
+
path = decodeURIComponent(path);
|
|
495
|
+
const item = await this.get(path, { content: true });
|
|
496
|
+
if (!item) {
|
|
497
|
+
throw Error(`Could not find file with path ${path}`);
|
|
498
|
+
}
|
|
499
|
+
const copies = ((await checkpoints.getItem(path)) ?? []).filter(Boolean);
|
|
500
|
+
copies.push(item);
|
|
501
|
+
// keep only a certain amount of checkpoints per file
|
|
502
|
+
if (copies.length > N_CHECKPOINTS) {
|
|
503
|
+
copies.splice(0, copies.length - N_CHECKPOINTS);
|
|
504
|
+
}
|
|
505
|
+
await checkpoints.setItem(path, copies);
|
|
506
|
+
const id = `${copies.length - 1}`;
|
|
507
|
+
return { id, last_modified: item.last_modified };
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* List available checkpoints for a file.
|
|
511
|
+
*
|
|
512
|
+
* @param path - The path of the file.
|
|
513
|
+
*
|
|
514
|
+
* @returns A promise which resolves with a list of checkpoint models for
|
|
515
|
+
* the file.
|
|
516
|
+
*/
|
|
517
|
+
async listCheckpoints(path) {
|
|
518
|
+
const copies = (await (await this.checkpoints).getItem(path)) || [];
|
|
519
|
+
return copies.filter(Boolean).map(this.normalizeCheckpoint, this);
|
|
520
|
+
}
|
|
521
|
+
normalizeCheckpoint(model, id) {
|
|
522
|
+
return { id: id.toString(), last_modified: model.last_modified };
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Restore a file to a known checkpoint state.
|
|
526
|
+
*
|
|
527
|
+
* @param path - The path of the file.
|
|
528
|
+
* @param checkpointID - The id of the checkpoint to restore.
|
|
529
|
+
*
|
|
530
|
+
* @returns A promise which resolves when the checkpoint is restored.
|
|
531
|
+
*/
|
|
532
|
+
async restoreCheckpoint(path, checkpointID) {
|
|
533
|
+
path = decodeURIComponent(path);
|
|
534
|
+
const copies = ((await (await this.checkpoints).getItem(path)) ||
|
|
535
|
+
[]);
|
|
536
|
+
const id = parseInt(checkpointID);
|
|
537
|
+
const item = copies[id];
|
|
538
|
+
await (await this.storage).setItem(path, item);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Delete a checkpoint for a file.
|
|
542
|
+
*
|
|
543
|
+
* @param path - The path of the file.
|
|
544
|
+
* @param checkpointID - The id of the checkpoint to delete.
|
|
545
|
+
*
|
|
546
|
+
* @returns A promise which resolves when the checkpoint is deleted.
|
|
547
|
+
*/
|
|
548
|
+
async deleteCheckpoint(path, checkpointID) {
|
|
549
|
+
path = decodeURIComponent(path);
|
|
550
|
+
const copies = ((await (await this.checkpoints).getItem(path)) ||
|
|
551
|
+
[]);
|
|
552
|
+
const id = parseInt(checkpointID);
|
|
553
|
+
copies.splice(id, 1);
|
|
554
|
+
await (await this.checkpoints).setItem(path, copies);
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Handle an upload chunk for a file.
|
|
558
|
+
* each chunk is base64 encoded, so we need to decode it and append it to the
|
|
559
|
+
* original content.
|
|
560
|
+
* @param newContent the new content to process, base64 encoded
|
|
561
|
+
* @param originalContent the original content, must be null or a binary string if chunked is true
|
|
562
|
+
* @param appendChunk whether the chunk should be appended to the originalContent
|
|
563
|
+
*
|
|
564
|
+
*
|
|
565
|
+
* @returns the decoded binary string, appended to the original content if requested
|
|
566
|
+
* /
|
|
567
|
+
*/
|
|
568
|
+
_handleUploadChunk(newContent, originalContent, appendChunk) {
|
|
569
|
+
const newContentBinaryString = atob(newContent);
|
|
570
|
+
const contentBinaryString = appendChunk
|
|
571
|
+
? originalContent + newContentBinaryString
|
|
572
|
+
: newContentBinaryString;
|
|
573
|
+
return contentBinaryString;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Convert a binary string to an Uint8Array
|
|
577
|
+
* @param binaryString the binary string
|
|
578
|
+
* @returns the bytes of the binary string
|
|
579
|
+
*/
|
|
580
|
+
_binaryStringToBytes(binaryString) {
|
|
581
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
582
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
583
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
584
|
+
}
|
|
585
|
+
return bytes;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* retrieve the contents for this path from the union of local storage and
|
|
589
|
+
* `api/contents/{path}/all.json`.
|
|
590
|
+
*
|
|
591
|
+
* @param path - The contents path to retrieve
|
|
592
|
+
*
|
|
593
|
+
* @returns A promise which resolves with a Map of contents, keyed by local file name
|
|
594
|
+
*/
|
|
595
|
+
async _getFolder(path) {
|
|
596
|
+
const content = new Map();
|
|
597
|
+
const storage = await this.storage;
|
|
598
|
+
await storage.iterate((file, key) => {
|
|
599
|
+
if (key.includes('/')) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
content.set(file.path, file);
|
|
603
|
+
});
|
|
604
|
+
// layer in contents that don't have local overwrites
|
|
605
|
+
for (const file of (await this._getServerDirectory(path)).values()) {
|
|
606
|
+
if (!content.has(file.path)) {
|
|
607
|
+
content.set(file.path, file);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (path && content.size === 0) {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
name: '',
|
|
615
|
+
path,
|
|
616
|
+
last_modified: new Date(0).toISOString(),
|
|
617
|
+
created: new Date(0).toISOString(),
|
|
618
|
+
format: 'json',
|
|
619
|
+
mimetype: MIME.JSON,
|
|
620
|
+
content: Array.from(content.values()),
|
|
621
|
+
size: 0,
|
|
622
|
+
writable: true,
|
|
623
|
+
type: 'directory',
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Attempt to recover the model from `{:path}/__all__.json` file, fall back to
|
|
628
|
+
* deriving the model (including content) off the file in `/files/`. Otherwise
|
|
629
|
+
* return `null`.
|
|
630
|
+
*/
|
|
631
|
+
async _getServerContents(path, options) {
|
|
632
|
+
const name = PathExt.basename(path);
|
|
633
|
+
const parentContents = await this._getServerDirectory(URLExt.join(path, '..'));
|
|
634
|
+
let model = parentContents.get(name);
|
|
635
|
+
if (!model) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
model = model || {
|
|
639
|
+
name,
|
|
640
|
+
path,
|
|
641
|
+
last_modified: new Date(0).toISOString(),
|
|
642
|
+
created: new Date(0).toISOString(),
|
|
643
|
+
format: 'text',
|
|
644
|
+
mimetype: MIME.PLAIN_TEXT,
|
|
645
|
+
type: 'file',
|
|
646
|
+
writable: true,
|
|
647
|
+
size: 0,
|
|
648
|
+
content: '',
|
|
649
|
+
};
|
|
650
|
+
if (options?.content) {
|
|
651
|
+
if (model.type === 'directory') {
|
|
652
|
+
const serverContents = await this._getServerDirectory(path);
|
|
653
|
+
model = { ...model, content: Array.from(serverContents.values()) };
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
const fileUrl = URLExt.join(PageConfig.getBaseUrl(), 'files', path);
|
|
657
|
+
const response = await fetch(fileUrl);
|
|
658
|
+
if (!response.ok) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const mimetype = model.mimetype || response.headers.get('Content-Type');
|
|
662
|
+
const ext = PathExt.extname(name);
|
|
663
|
+
if (model.type === 'notebook' ||
|
|
664
|
+
FILE.hasFormat(ext, 'json') ||
|
|
665
|
+
mimetype?.indexOf('json') !== -1 ||
|
|
666
|
+
path.match(/\.(ipynb|[^/]*json[^/]*)$/)) {
|
|
667
|
+
const contentText = await response.text();
|
|
668
|
+
model = {
|
|
669
|
+
...model,
|
|
670
|
+
content: JSON.parse(contentText),
|
|
671
|
+
format: 'json',
|
|
672
|
+
mimetype: model.mimetype || MIME.JSON,
|
|
673
|
+
size: encoder.encode(contentText).length,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
else if (FILE.hasFormat(ext, 'text') ||
|
|
677
|
+
mimetype.indexOf('text') !== -1) {
|
|
678
|
+
const contentText = await response.text();
|
|
679
|
+
model = {
|
|
680
|
+
...model,
|
|
681
|
+
content: contentText,
|
|
682
|
+
format: 'text',
|
|
683
|
+
mimetype: mimetype || MIME.PLAIN_TEXT,
|
|
684
|
+
size: encoder.encode(contentText).length,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
const contentBuffer = await response.arrayBuffer();
|
|
689
|
+
const contentBytes = new Uint8Array(contentBuffer);
|
|
690
|
+
model = {
|
|
691
|
+
...model,
|
|
692
|
+
content: btoa(contentBytes.reduce(this.reduceBytesToString, '')),
|
|
693
|
+
format: 'base64',
|
|
694
|
+
mimetype: mimetype || MIME.OCTET_STREAM,
|
|
695
|
+
size: contentBytes.length,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return model;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* A reducer for turning arbitrary binary into a string
|
|
704
|
+
*/
|
|
705
|
+
reduceBytesToString = (data, byte) => {
|
|
706
|
+
return data + String.fromCharCode(byte);
|
|
707
|
+
};
|
|
708
|
+
/**
|
|
709
|
+
* retrieve the contents for this path from `__index__.json` in the appropriate
|
|
710
|
+
* folder.
|
|
711
|
+
*
|
|
712
|
+
* @param newLocalPath - The new file path.
|
|
713
|
+
*
|
|
714
|
+
* @returns A promise which resolves with a Map of contents, keyed by local file name
|
|
715
|
+
*/
|
|
716
|
+
async _getServerDirectory(path) {
|
|
717
|
+
const content = this._serverContents.get(path) || new Map();
|
|
718
|
+
if (!this._serverContents.has(path)) {
|
|
719
|
+
const apiURL = URLExt.join(PageConfig.getBaseUrl(), 'api/contents', path, 'all.json');
|
|
720
|
+
try {
|
|
721
|
+
const response = await fetch(apiURL);
|
|
722
|
+
const json = JSON.parse(await response.text());
|
|
723
|
+
for (const file of json['content']) {
|
|
724
|
+
content.set(file.name, file);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
catch (err) {
|
|
728
|
+
console.warn(`don't worry, about ${err}... nothing's broken. If there had been a
|
|
729
|
+
file at ${apiURL}, you might see some more files.`);
|
|
730
|
+
}
|
|
731
|
+
this._serverContents.set(path, content);
|
|
732
|
+
}
|
|
733
|
+
return content;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Increment the counter for a given file type.
|
|
737
|
+
* Used to avoid collisions when creating new untitled files.
|
|
738
|
+
*
|
|
739
|
+
* @param type The file type to increment the counter for.
|
|
740
|
+
*/
|
|
741
|
+
async _incrementCounter(type) {
|
|
742
|
+
const counters = await this.counters;
|
|
743
|
+
const current = (await counters.getItem(type)) ?? -1;
|
|
744
|
+
const counter = current + 1;
|
|
745
|
+
await counters.setItem(type, counter);
|
|
746
|
+
return counter;
|
|
747
|
+
}
|
|
748
|
+
_serverContents = new Map();
|
|
749
|
+
_storageName = DEFAULT_STORAGE_NAME;
|
|
750
|
+
_storageDrivers = null;
|
|
751
|
+
_ready;
|
|
752
|
+
_storage;
|
|
753
|
+
_counters;
|
|
754
|
+
_checkpoints;
|
|
755
|
+
_localforage;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* A namespace for private data.
|
|
759
|
+
*/
|
|
760
|
+
var Private;
|
|
761
|
+
(function (Private) {
|
|
762
|
+
/**
|
|
763
|
+
* The content for an empty notebook.
|
|
764
|
+
*/
|
|
765
|
+
Private.EMPTY_NB = {
|
|
766
|
+
metadata: {
|
|
767
|
+
orig_nbformat: 4,
|
|
768
|
+
},
|
|
769
|
+
nbformat_minor: 5,
|
|
770
|
+
nbformat: 4,
|
|
771
|
+
cells: [],
|
|
772
|
+
};
|
|
773
|
+
})(Private || (Private = {}));
|
|
774
|
+
//# sourceMappingURL=contents.js.map
|