@datalayer/jupyter-react 1.1.9 → 1.2.1

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.
Files changed (353) hide show
  1. package/README.md +74 -1
  2. package/lib/app/tabs/components/CellComponent.js +4 -2
  3. package/lib/app/tabs/components/CellComponent.js.map +1 -1
  4. package/lib/app/tabs/components/NotebookComponent.js +2 -2
  5. package/lib/app/tabs/components/NotebookComponent.js.map +1 -1
  6. package/lib/app/tabs/components/ViewerComponent.js +1 -1
  7. package/lib/app/tabs/components/ViewerComponent.js.map +1 -1
  8. package/lib/components/cell/Cell.d.ts +3 -3
  9. package/lib/components/cell/Cell.js +5 -12
  10. package/lib/components/cell/Cell.js.map +1 -1
  11. package/lib/components/cell/CellAdapter.d.ts +0 -2
  12. package/lib/components/cell/CellAdapter.js +5 -17
  13. package/lib/components/cell/CellAdapter.js.map +1 -1
  14. package/lib/components/jupyterlab/JupyterLabApp.js +6 -0
  15. package/lib/components/jupyterlab/JupyterLabApp.js.map +1 -1
  16. package/lib/components/kernel/{Kernelndicator.d.ts → KernelIndicator.d.ts} +1 -0
  17. package/lib/components/kernel/{Kernelndicator.js → KernelIndicator.js} +13 -5
  18. package/lib/components/kernel/KernelIndicator.js.map +1 -0
  19. package/lib/components/kernel/index.d.ts +1 -1
  20. package/lib/components/kernel/index.js +1 -1
  21. package/lib/components/kernel/index.js.map +1 -1
  22. package/lib/components/notebook/Notebook2.d.ts +6 -2
  23. package/lib/components/notebook/Notebook2.js +3 -2
  24. package/lib/components/notebook/Notebook2.js.map +1 -1
  25. package/lib/components/notebook/Notebook2Adapter.d.ts +10 -0
  26. package/lib/components/notebook/Notebook2Adapter.js +12 -0
  27. package/lib/components/notebook/Notebook2Adapter.js.map +1 -1
  28. package/lib/components/notebook/Notebook2Base.d.ts +7 -3
  29. package/lib/components/notebook/Notebook2Base.js +78 -48
  30. package/lib/components/notebook/Notebook2Base.js.map +1 -1
  31. package/lib/components/notebook/Notebook2State.d.ts +1 -0
  32. package/lib/components/notebook/Notebook2State.js +3 -0
  33. package/lib/components/notebook/Notebook2State.js.map +1 -1
  34. package/lib/components/notebook/NotebookAdapter.d.ts +1 -0
  35. package/lib/components/notebook/NotebookAdapter.js +7 -3
  36. package/lib/components/notebook/NotebookAdapter.js.map +1 -1
  37. package/lib/components/notebook/NotebookCommands.d.ts +25 -2
  38. package/lib/components/notebook/NotebookCommands.js +89 -10
  39. package/lib/components/notebook/NotebookCommands.js.map +1 -1
  40. package/lib/components/terminal/Terminal.js +1 -1
  41. package/lib/components/terminal/Terminal.js.map +1 -1
  42. package/lib/examples/Bokeh.js +2 -2
  43. package/lib/examples/Bokeh.js.map +1 -1
  44. package/lib/examples/Bqplot.js +2 -2
  45. package/lib/examples/Bqplot.js.map +1 -1
  46. package/lib/examples/Cell.js +4 -4
  47. package/lib/examples/Cell.js.map +1 -1
  48. package/lib/examples/CellLite.js +16 -4
  49. package/lib/examples/CellLite.js.map +1 -1
  50. package/lib/examples/Cells.js +9 -6
  51. package/lib/examples/Cells.js.map +1 -1
  52. package/lib/examples/CellsExecute.js +13 -9
  53. package/lib/examples/CellsExecute.js.map +1 -1
  54. package/lib/examples/Console.js +2 -2
  55. package/lib/examples/Console.js.map +1 -1
  56. package/lib/examples/ConsoleLite.js +3 -3
  57. package/lib/examples/ConsoleLite.js.map +1 -1
  58. package/lib/examples/Dashboard.js +2 -2
  59. package/lib/examples/Dashboard.js.map +1 -1
  60. package/lib/examples/Deno.js +2 -2
  61. package/lib/examples/Deno.js.map +1 -1
  62. package/lib/examples/Examples.d.ts +23 -0
  63. package/lib/examples/Examples.js +342 -0
  64. package/lib/examples/Examples.js.map +1 -0
  65. package/lib/examples/FileBrowser.js +4 -4
  66. package/lib/examples/FileBrowser.js.map +1 -1
  67. package/lib/examples/GeoJson.js +2 -2
  68. package/lib/examples/GeoJson.js.map +1 -1
  69. package/lib/examples/IPyLeaflet.js +3 -3
  70. package/lib/examples/IPyLeaflet.js.map +1 -1
  71. package/lib/examples/IPyReact.js +3 -3
  72. package/lib/examples/IPyReact.js.map +1 -1
  73. package/lib/examples/IPyWidgets.js +3 -3
  74. package/lib/examples/IPyWidgets.js.map +1 -1
  75. package/lib/examples/IPyWidgetsState.js +3 -3
  76. package/lib/examples/IPyWidgetsState.js.map +1 -1
  77. package/lib/examples/JupyterContext.js +2 -2
  78. package/lib/examples/JupyterContext.js.map +1 -1
  79. package/lib/examples/JupyterLabAppHeadless.js +2 -2
  80. package/lib/examples/JupyterLabAppHeadless.js.map +1 -1
  81. package/lib/examples/JupyterLabAppHeadlessServerless.js +2 -2
  82. package/lib/examples/JupyterLabAppHeadlessServerless.js.map +1 -1
  83. package/lib/examples/JupyterLabAppServerless.js +2 -2
  84. package/lib/examples/JupyterLabAppServerless.js.map +1 -1
  85. package/lib/examples/JupyterLabAppServiceManager.js +2 -2
  86. package/lib/examples/JupyterLabAppServiceManager.js.map +1 -1
  87. package/lib/examples/JupyterLabTheme.js +2 -2
  88. package/lib/examples/JupyterLabTheme.js.map +1 -1
  89. package/lib/examples/KernelExecute.d.ts +1 -1
  90. package/lib/examples/KernelExecute.js +9 -11
  91. package/lib/examples/KernelExecute.js.map +1 -1
  92. package/lib/examples/KernelExecuteLite.d.ts +1 -0
  93. package/lib/examples/KernelExecuteLite.js +51 -0
  94. package/lib/examples/KernelExecuteLite.js.map +1 -0
  95. package/lib/examples/KernelExecutor.js +10 -9
  96. package/lib/examples/KernelExecutor.js.map +1 -1
  97. package/lib/examples/KernelExecutorLite.js +63 -0
  98. package/lib/examples/KernelExecutorLite.js.map +1 -0
  99. package/lib/examples/Kernels.js +6 -5
  100. package/lib/examples/Kernels.js.map +1 -1
  101. package/lib/examples/Lumino.js +2 -2
  102. package/lib/examples/Lumino.js.map +1 -1
  103. package/lib/examples/Matplotlib.js +10 -6
  104. package/lib/examples/Matplotlib.js.map +1 -1
  105. package/lib/examples/Notebook.js +3 -2
  106. package/lib/examples/Notebook.js.map +1 -1
  107. package/lib/examples/Notebook2.js +9 -6
  108. package/lib/examples/Notebook2.js.map +1 -1
  109. package/lib/examples/Notebook2Actions.js +8 -6
  110. package/lib/examples/Notebook2Actions.js.map +1 -1
  111. package/lib/examples/Notebook2Collaborative.js +2 -2
  112. package/lib/examples/Notebook2Collaborative.js.map +1 -1
  113. package/lib/examples/Notebook2Lite.js +19 -14
  114. package/lib/examples/Notebook2Lite.js.map +1 -1
  115. package/lib/examples/NotebookCellSidebar.js +3 -3
  116. package/lib/examples/NotebookCellSidebar.js.map +1 -1
  117. package/lib/examples/NotebookCellToolbar.js +4 -4
  118. package/lib/examples/NotebookCellToolbar.js.map +1 -1
  119. package/lib/examples/NotebookCollaborative.js +2 -2
  120. package/lib/examples/NotebookCollaborative.js.map +1 -1
  121. package/lib/examples/NotebookColormode.js +15 -10
  122. package/lib/examples/NotebookColormode.js.map +1 -1
  123. package/lib/examples/NotebookExtension.js +4 -4
  124. package/lib/examples/NotebookExtension.js.map +1 -1
  125. package/lib/examples/NotebookExternalContent.js +18 -13
  126. package/lib/examples/NotebookExternalContent.js.map +1 -1
  127. package/lib/examples/NotebookInit.js +10 -9
  128. package/lib/examples/NotebookInit.js.map +1 -1
  129. package/lib/examples/NotebookKernel.js +4 -4
  130. package/lib/examples/NotebookKernel.js.map +1 -1
  131. package/lib/examples/NotebookKernelChange.js +2 -2
  132. package/lib/examples/NotebookKernelChange.js.map +1 -1
  133. package/lib/examples/NotebookLess.js +4 -4
  134. package/lib/examples/NotebookLess.js.map +1 -1
  135. package/lib/examples/NotebookLite.js +10 -6
  136. package/lib/examples/NotebookLite.js.map +1 -1
  137. package/lib/examples/NotebookLiteContext.js +10 -5
  138. package/lib/examples/NotebookLiteContext.js.map +1 -1
  139. package/lib/examples/NotebookLocalServer.js +3 -3
  140. package/lib/examples/NotebookLocalServer.js.map +1 -1
  141. package/lib/examples/NotebookNbformat.js +7 -5
  142. package/lib/examples/NotebookNbformat.js.map +1 -1
  143. package/lib/examples/NotebookNbformatChange.js +12 -6
  144. package/lib/examples/NotebookNbformatChange.js.map +1 -1
  145. package/lib/examples/NotebookNoContext.js +4 -3
  146. package/lib/examples/NotebookNoContext.js.map +1 -1
  147. package/lib/examples/NotebookNoPrimer.js +3 -2
  148. package/lib/examples/NotebookNoPrimer.js.map +1 -1
  149. package/lib/examples/NotebookOnSessionConnection.js +5 -5
  150. package/lib/examples/NotebookOnSessionConnection.js.map +1 -1
  151. package/lib/examples/NotebookPath.js +2 -2
  152. package/lib/examples/NotebookPath.js.map +1 -1
  153. package/lib/examples/NotebookPathChange.js +5 -4
  154. package/lib/examples/NotebookPathChange.js.map +1 -1
  155. package/lib/examples/NotebookReadonly.js +4 -4
  156. package/lib/examples/NotebookReadonly.js.map +1 -1
  157. package/lib/examples/NotebookServiceManager.js +4 -4
  158. package/lib/examples/NotebookServiceManager.js.map +1 -1
  159. package/lib/examples/NotebookSkeleton.js +3 -2
  160. package/lib/examples/NotebookSkeleton.js.map +1 -1
  161. package/lib/examples/NotebookTOC.d.ts +1 -0
  162. package/lib/examples/{NotebookToc.js → NotebookTOC.js} +12 -6
  163. package/lib/examples/NotebookTOC.js.map +1 -0
  164. package/lib/examples/NotebookTheme.js +10 -5
  165. package/lib/examples/NotebookTheme.js.map +1 -1
  166. package/lib/examples/NotebookThemeColormode.js +4 -4
  167. package/lib/examples/NotebookThemeColormode.js.map +1 -1
  168. package/lib/examples/NotebookURL.js +3 -2
  169. package/lib/examples/NotebookURL.js.map +1 -1
  170. package/lib/examples/NotebookUnmount.js +13 -7
  171. package/lib/examples/NotebookUnmount.js.map +1 -1
  172. package/lib/examples/ObservableHQ.js +2 -2
  173. package/lib/examples/ObservableHQ.js.map +1 -1
  174. package/lib/examples/OutputIPyWidgets.js +3 -3
  175. package/lib/examples/OutputIPyWidgets.js.map +1 -1
  176. package/lib/examples/OutputWithMonitoring.js +3 -2
  177. package/lib/examples/OutputWithMonitoring.js.map +1 -1
  178. package/lib/examples/Outputs.js +8 -8
  179. package/lib/examples/Outputs.js.map +1 -1
  180. package/lib/examples/OutputsIpynb.js +4 -4
  181. package/lib/examples/OutputsIpynb.js.map +1 -1
  182. package/lib/examples/Panel.js +2 -2
  183. package/lib/examples/Panel.js.map +1 -1
  184. package/lib/examples/Plotly.js +2 -2
  185. package/lib/examples/Plotly.js.map +1 -1
  186. package/lib/examples/PyGWalker.js +4 -4
  187. package/lib/examples/PyGWalker.js.map +1 -1
  188. package/lib/examples/Terminal.js +4 -3
  189. package/lib/examples/Terminal.js.map +1 -1
  190. package/lib/examples/Vega.js +2 -2
  191. package/lib/examples/Vega.js.map +1 -1
  192. package/lib/examples/Viewer.js +5 -4
  193. package/lib/examples/Viewer.js.map +1 -1
  194. package/lib/jupyter/JupyterConfig.js +6 -4
  195. package/lib/jupyter/JupyterConfig.js.map +1 -1
  196. package/lib/jupyter/collaboration/ICollaborationProvider.js.map +1 -1
  197. package/lib/jupyter/kernel/Kernel.js +21 -15
  198. package/lib/jupyter/kernel/Kernel.js.map +1 -1
  199. package/lib/jupyter/kernel/KernelState.d.ts +1 -1
  200. package/lib/jupyter/lite/Lite.d.ts +1 -1
  201. package/lib/jupyter/lite/LiteServer.d.ts +1 -1
  202. package/lib/jupyter/lite/LiteServer.js +20 -5
  203. package/lib/jupyter/lite/LiteServer.js.map +1 -1
  204. package/lib/jupyter/lite/contents/broadcast.d.ts +27 -0
  205. package/lib/jupyter/lite/contents/broadcast.js +60 -0
  206. package/lib/jupyter/lite/contents/broadcast.js.map +1 -0
  207. package/lib/jupyter/lite/contents/contents.d.ts +228 -0
  208. package/lib/jupyter/lite/contents/contents.js +774 -0
  209. package/lib/jupyter/lite/contents/contents.js.map +1 -0
  210. package/lib/jupyter/lite/contents/drivecontents.d.ts +92 -0
  211. package/lib/jupyter/lite/contents/drivecontents.js +133 -0
  212. package/lib/jupyter/lite/contents/drivecontents.js.map +1 -0
  213. package/lib/jupyter/lite/contents/drivefs.d.ts +193 -0
  214. package/lib/jupyter/lite/contents/drivefs.js +432 -0
  215. package/lib/jupyter/lite/contents/drivefs.js.map +1 -0
  216. package/lib/jupyter/lite/contents/emscripten.d.ts +89 -0
  217. package/lib/jupyter/lite/contents/emscripten.js +11 -0
  218. package/lib/jupyter/lite/contents/emscripten.js.map +1 -0
  219. package/lib/jupyter/lite/contents/index.d.ts +6 -0
  220. package/lib/jupyter/lite/contents/index.js +9 -0
  221. package/lib/jupyter/lite/contents/index.js.map +1 -0
  222. package/lib/jupyter/lite/contents/tokens.d.ts +136 -0
  223. package/lib/jupyter/lite/contents/tokens.js +66 -0
  224. package/lib/jupyter/lite/contents/tokens.js.map +1 -0
  225. package/lib/jupyter/lite/kernel/index.d.ts +4 -0
  226. package/lib/jupyter/lite/kernel/index.js +7 -0
  227. package/lib/jupyter/lite/kernel/index.js.map +1 -0
  228. package/lib/jupyter/lite/kernel/kernel.d.ts +245 -0
  229. package/lib/jupyter/lite/kernel/kernel.js +453 -0
  230. package/lib/jupyter/lite/kernel/kernel.js.map +1 -0
  231. package/lib/jupyter/lite/kernel/kernels.d.ts +85 -0
  232. package/lib/jupyter/lite/kernel/kernels.js +218 -0
  233. package/lib/jupyter/lite/kernel/kernels.js.map +1 -0
  234. package/lib/jupyter/lite/kernel/kernelspecs.d.ts +53 -0
  235. package/lib/jupyter/lite/kernel/kernelspecs.js +50 -0
  236. package/lib/jupyter/lite/kernel/kernelspecs.js.map +1 -0
  237. package/lib/jupyter/lite/kernel/tokens.d.ts +171 -0
  238. package/lib/jupyter/lite/kernel/tokens.js +16 -0
  239. package/lib/jupyter/lite/kernel/tokens.js.map +1 -0
  240. package/lib/jupyter/lite/licenses/index.d.ts +2 -0
  241. package/lib/jupyter/lite/licenses/index.js +5 -0
  242. package/lib/jupyter/lite/licenses/index.js.map +1 -0
  243. package/lib/jupyter/lite/licenses/licenses.d.ts +35 -0
  244. package/lib/jupyter/lite/licenses/licenses.js +95 -0
  245. package/lib/jupyter/lite/licenses/licenses.js.map +1 -0
  246. package/lib/jupyter/lite/licenses/tokens.d.ts +74 -0
  247. package/lib/jupyter/lite/licenses/tokens.js +13 -0
  248. package/lib/jupyter/lite/licenses/tokens.js.map +1 -0
  249. package/lib/jupyter/lite/localforage/index.d.ts +2 -0
  250. package/lib/jupyter/lite/localforage/index.js +5 -0
  251. package/lib/jupyter/lite/localforage/index.js.map +1 -0
  252. package/lib/jupyter/lite/localforage/memory.d.ts +5 -0
  253. package/lib/jupyter/lite/localforage/memory.js +10 -0
  254. package/lib/jupyter/lite/localforage/memory.js.map +1 -0
  255. package/lib/jupyter/lite/localforage/tokens.d.ts +12 -0
  256. package/lib/jupyter/lite/localforage/tokens.js +8 -0
  257. package/lib/jupyter/lite/localforage/tokens.js.map +1 -0
  258. package/lib/jupyter/lite/pyodide-kernel/_pypi.d.ts +18 -0
  259. package/lib/jupyter/lite/pyodide-kernel/_pypi.js +85 -0
  260. package/lib/jupyter/lite/pyodide-kernel/_pypi.js.map +1 -0
  261. package/lib/jupyter/lite/pyodide-kernel/coincident.worker.d.ts +15 -0
  262. package/lib/jupyter/lite/pyodide-kernel/coincident.worker.js +63 -0
  263. package/lib/jupyter/lite/pyodide-kernel/coincident.worker.js.map +1 -0
  264. package/lib/jupyter/lite/pyodide-kernel/comlink.worker.d.ts +9 -0
  265. package/lib/jupyter/lite/pyodide-kernel/comlink.worker.js +50 -0
  266. package/lib/jupyter/lite/pyodide-kernel/comlink.worker.js.map +1 -0
  267. package/lib/jupyter/lite/pyodide-kernel/index.d.ts +6 -0
  268. package/lib/jupyter/lite/pyodide-kernel/index.js +9 -0
  269. package/lib/jupyter/lite/pyodide-kernel/index.js.map +1 -0
  270. package/lib/jupyter/lite/pyodide-kernel/kernel.d.ts +157 -0
  271. package/lib/jupyter/lite/pyodide-kernel/kernel.js +294 -0
  272. package/lib/jupyter/lite/pyodide-kernel/kernel.js.map +1 -0
  273. package/lib/jupyter/lite/pyodide-kernel/pypi/all-local.json +128 -0
  274. package/lib/jupyter/lite/pyodide-kernel/pypi/all.json +128 -0
  275. package/lib/jupyter/lite/pyodide-kernel/schema/piplite.v0.schema.json +113 -0
  276. package/lib/jupyter/lite/pyodide-kernel/tokens.d.ts +82 -0
  277. package/lib/jupyter/lite/pyodide-kernel/tokens.js +8 -0
  278. package/lib/jupyter/lite/pyodide-kernel/tokens.js.map +1 -0
  279. package/lib/jupyter/lite/pyodide-kernel/worker.d.ts +138 -0
  280. package/lib/jupyter/lite/pyodide-kernel/worker.js +426 -0
  281. package/lib/jupyter/lite/pyodide-kernel/worker.js.map +1 -0
  282. package/lib/jupyter/lite/pyodide-kernel-extension/index.d.ts +4 -0
  283. package/lib/jupyter/lite/pyodide-kernel-extension/index.js +88 -0
  284. package/lib/jupyter/lite/pyodide-kernel-extension/index.js.map +1 -0
  285. package/lib/jupyter/lite/server/app.d.ts +87 -0
  286. package/lib/jupyter/lite/server/app.js +157 -0
  287. package/lib/jupyter/lite/server/app.js.map +1 -0
  288. package/lib/jupyter/lite/server/index.d.ts +4 -0
  289. package/lib/jupyter/lite/server/index.js +7 -0
  290. package/lib/jupyter/lite/server/index.js.map +1 -0
  291. package/lib/jupyter/lite/server/router.d.ts +99 -0
  292. package/lib/jupyter/lite/server/router.js +109 -0
  293. package/lib/jupyter/lite/server/router.js.map +1 -0
  294. package/lib/jupyter/lite/server/service-manager.d.ts +21 -0
  295. package/lib/jupyter/lite/server/service-manager.js +102 -0
  296. package/lib/jupyter/lite/server/service-manager.js.map +1 -0
  297. package/lib/jupyter/lite/server/service-worker.d.ts +58 -0
  298. package/lib/jupyter/lite/server/service-worker.js +145 -0
  299. package/lib/jupyter/lite/server/service-worker.js.map +1 -0
  300. package/lib/jupyter/lite/server/status.d.ts +18 -0
  301. package/lib/jupyter/lite/server/status.js +21 -0
  302. package/lib/jupyter/lite/server/status.js.map +1 -0
  303. package/lib/jupyter/lite/server/tokens.d.ts +38 -0
  304. package/lib/jupyter/lite/server/tokens.js +8 -0
  305. package/lib/jupyter/lite/server/tokens.js.map +1 -0
  306. package/lib/jupyter/lite/server-extension/index.d.ts +3 -0
  307. package/lib/jupyter/lite/server-extension/index.js +500 -0
  308. package/lib/jupyter/lite/server-extension/index.js.map +1 -0
  309. package/lib/jupyter/lite/session/index.d.ts +2 -0
  310. package/lib/jupyter/lite/session/index.js +5 -0
  311. package/lib/jupyter/lite/session/index.js.map +1 -0
  312. package/lib/jupyter/lite/session/sessions.d.ts +68 -0
  313. package/lib/jupyter/lite/session/sessions.js +185 -0
  314. package/lib/jupyter/lite/session/sessions.js.map +1 -0
  315. package/lib/jupyter/lite/session/tokens.d.ts +40 -0
  316. package/lib/jupyter/lite/session/tokens.js +6 -0
  317. package/lib/jupyter/lite/session/tokens.js.map +1 -0
  318. package/lib/jupyter/lite/settings/index.d.ts +2 -0
  319. package/lib/jupyter/lite/settings/index.js +5 -0
  320. package/lib/jupyter/lite/settings/index.js.map +1 -0
  321. package/lib/jupyter/lite/settings/settings.d.ts +75 -0
  322. package/lib/jupyter/lite/settings/settings.js +155 -0
  323. package/lib/jupyter/lite/settings/settings.js.map +1 -0
  324. package/lib/jupyter/lite/settings/tokens.d.ts +65 -0
  325. package/lib/jupyter/lite/settings/tokens.js +6 -0
  326. package/lib/jupyter/lite/settings/tokens.js.map +1 -0
  327. package/lib/jupyter/lite/translation/index.d.ts +2 -0
  328. package/lib/jupyter/lite/translation/index.js +5 -0
  329. package/lib/jupyter/lite/translation/index.js.map +1 -0
  330. package/lib/jupyter/lite/translation/tokens.d.ts +17 -0
  331. package/lib/jupyter/lite/translation/tokens.js +6 -0
  332. package/lib/jupyter/lite/translation/tokens.js.map +1 -0
  333. package/lib/jupyter/lite/translation/translation.d.ts +13 -0
  334. package/lib/jupyter/lite/translation/translation.js +52 -0
  335. package/lib/jupyter/lite/translation/translation.js.map +1 -0
  336. package/lib/jupyter/lite/types/index.d.ts +1 -0
  337. package/lib/jupyter/lite/types/index.js +4 -0
  338. package/lib/jupyter/lite/types/index.js.map +1 -0
  339. package/lib/jupyter/lite/types/tokens.d.ts +27 -0
  340. package/lib/jupyter/lite/types/tokens.js +4 -0
  341. package/lib/jupyter/lite/types/tokens.js.map +1 -0
  342. package/lib/jupyter/services/ServiceManagerLite.js +15 -6
  343. package/lib/jupyter/services/ServiceManagerLite.js.map +1 -1
  344. package/lib/state/JupyterReactState.js +7 -8
  345. package/lib/state/JupyterReactState.js.map +1 -1
  346. package/lib/theme/JupyterLabCss.js +4 -2
  347. package/lib/theme/JupyterLabCss.js.map +1 -1
  348. package/package.json +23 -16
  349. package/schema/kernel.v0.schema.json +42 -0
  350. package/style/icons/pyodide.svg +17 -0
  351. package/lib/components/kernel/Kernelndicator.js.map +0 -1
  352. package/lib/examples/NotebookToc.js.map +0 -1
  353. /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