From 3177cd132fbf2f4ce5542778f08691af65aeeb50 Mon Sep 17 00:00:00 2001 From: Eric Charles Date: Wed, 9 Aug 2023 16:36:20 +0200 Subject: [PATCH] fix: jupyterlab layout --- examples/cra/package.json | 2 +- examples/lexical/package.json | 2 +- packages/lexical/package.json | 2 +- packages/react/package.json | 2 +- .../components/viewer/output/OutputAdapter.ts | 39 +++++++++++++++++++ .../components/viewer/output/OutputViewer.tsx | 4 +- .../src/jupyter/lab/notebook/classic/icon.ts | 8 ---- .../jupyter/lab/notebook/classic/plugin.ts | 4 +- .../jupyter/lab/notebook/dashboard/icon.ts | 8 ---- .../jupyter/lab/notebook/dashboard/plugin.ts | 10 ++--- packages/traitlets/package.json | 2 +- 11 files changed, 53 insertions(+), 30 deletions(-) create mode 100755 packages/react/src/components/viewer/output/OutputAdapter.ts delete mode 100644 packages/react/src/jupyter/lab/notebook/classic/icon.ts delete mode 100644 packages/react/src/jupyter/lab/notebook/dashboard/icon.ts diff --git a/examples/cra/package.json b/examples/cra/package.json index 4aa8613d..e47e46bc 100644 --- a/examples/cra/package.json +++ b/examples/cra/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@datalayer/jupyter-react": "0.5.2", - "@datalayer/primer-addons": "0.0.19", + "@datalayer/primer-addons": "0.0.20", "react": "18.2.0", "react-dom": "18.2.0", "web-vitals": "2.1.4" diff --git a/examples/lexical/package.json b/examples/lexical/package.json index abb500cf..6bfdfe3f 100644 --- a/examples/lexical/package.json +++ b/examples/lexical/package.json @@ -29,7 +29,7 @@ }, "dependencies": { "@datalayer/jupyter-lexical": "0.0.1", - "@datalayer/primer-addons": "0.0.19", + "@datalayer/primer-addons": "0.0.20", "react": "18.2.0", "react-dom": "18.2.0", "react-json-tree": "0.17.0" diff --git a/packages/lexical/package.json b/packages/lexical/package.json index e3dc62f6..e2c90884 100644 --- a/packages/lexical/package.json +++ b/packages/lexical/package.json @@ -58,7 +58,7 @@ }, "dependencies": { "@datalayer/jupyter-react": "0.5.2", - "@datalayer/primer-addons": "0.0.19", + "@datalayer/primer-addons": "0.0.20", "@jupyterlab/application": "4.0.3", "@jupyterlab/coreutils": "6.0.3", "@jupyterlab/services": "7.0.3", diff --git a/packages/react/package.json b/packages/react/package.json index f3c7f5ed..0c48b78b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -68,7 +68,7 @@ "@datalayer/jupyterlite-kernel": "0.1.0-beta.13", "@datalayer/jupyterlite-server": "0.1.0-beta.13", "@datalayer/jupyterlite-server-extension": "0.1.0-beta.13", - "@datalayer/primer-addons": "0.0.19", + "@datalayer/primer-addons": "0.0.20", "@datalayer/typescript-fsa-redux-observable": "0.18.0", "@jupyter-widgets/base": "6.0.5", "@jupyter-widgets/controls": "5.0.6", diff --git a/packages/react/src/components/viewer/output/OutputAdapter.ts b/packages/react/src/components/viewer/output/OutputAdapter.ts new file mode 100755 index 00000000..817174e4 --- /dev/null +++ b/packages/react/src/components/viewer/output/OutputAdapter.ts @@ -0,0 +1,39 @@ +import { IOutput } from '@jupyterlab/nbformat'; +import { OutputArea, OutputAreaModel } from '@jupyterlab/outputarea'; +import { IRenderMime, RenderMimeRegistry, standardRendererFactories } from '@jupyterlab/rendermime'; +import { rendererFactory as jsonRendererFactory } from '@jupyterlab/json-extension'; +import { rendererFactory as javascriptRendererFactory } from '@jupyterlab/javascript-extension'; + +export class OutputAdapter { + private _renderers: IRenderMime.IRendererFactory[]; + private _outputArea: OutputArea; + private _rendermime: RenderMimeRegistry; + + public constructor(outputs?: IOutput[]) { + this._renderers = standardRendererFactories.filter(factory => factory.mimeTypes[0] !== 'text/javascript'); + this._renderers.push(jsonRendererFactory); + this._renderers.push(javascriptRendererFactory); + this._rendermime = new RenderMimeRegistry({ + initialFactories: this._renderers, + }); + const outputAreaModel = new OutputAreaModel({ + trusted: true, + values: outputs, + }) + this._outputArea = new OutputArea({ + model: outputAreaModel, + rendermime: this._rendermime, + }); + } + + public clearOutput() { + this._outputArea.model.clear(); + } + + get outputArea(): OutputArea { + return this._outputArea; + } + +} + +export default OutputAdapter; diff --git a/packages/react/src/components/viewer/output/OutputViewer.tsx b/packages/react/src/components/viewer/output/OutputViewer.tsx index da628de8..eb80a998 100644 --- a/packages/react/src/components/viewer/output/OutputViewer.tsx +++ b/packages/react/src/components/viewer/output/OutputViewer.tsx @@ -1,6 +1,6 @@ import { ICell, IOutput } from '@jupyterlab/nbformat'; import Lumino from '../../../jupyter/lumino/Lumino'; -import OutputAdapter from '../../../components/output/OutputAdapter'; +import OutputAdapter from './OutputAdapter'; type Props = { cell: ICell, @@ -9,7 +9,7 @@ type Props = { const OutputViewer = (props: Props) => { const { cell } = props; const outputs = cell.outputs ? (cell.outputs as IOutput[]) : undefined; - const outputAdapter = new OutputAdapter(undefined, outputs); + const outputAdapter = new OutputAdapter(outputs); switch(cell.cell_type) { case 'code': { return ( diff --git a/packages/react/src/jupyter/lab/notebook/classic/icon.ts b/packages/react/src/jupyter/lab/notebook/classic/icon.ts deleted file mode 100644 index 42825512..00000000 --- a/packages/react/src/jupyter/lab/notebook/classic/icon.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { LabIcon } from '@jupyterlab/ui-components'; - -import classicSvgStr from '@datalayer/icons-react/data1/JupyterBaseIcon.svg'; - -export const notebookClassicIcon = new LabIcon({ - name: '@datalayer/jupyter-react:classic-render-icon', - svgstr: classicSvgStr, -}); diff --git a/packages/react/src/jupyter/lab/notebook/classic/plugin.ts b/packages/react/src/jupyter/lab/notebook/classic/plugin.ts index 40a7ed62..1d87c5cc 100644 --- a/packages/react/src/jupyter/lab/notebook/classic/plugin.ts +++ b/packages/react/src/jupyter/lab/notebook/classic/plugin.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '@lumino/commands'; import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { IDisposable } from '@lumino/disposable'; import { ClassicRender, IClassicRenderTracker, ClassicRenderFactory } from './classicRender'; -import { notebookClassicIcon } from './icon'; +import { jupiterIconLabIcon as notebookClassicIcon } from '@datalayer/icons-react/data2/JupiterIconLabIcon'; export namespace CommandIDs { export const classicRender = 'notebook:render-with-classic'; @@ -29,7 +29,7 @@ class ClassicRenderButton implements DocumentRegistry.IWidgetExtension { this._commands.execute(CommandIDs.classicRender); } }); panel.toolbar.insertAfter('cellType', 'classicRender', button); diff --git a/packages/react/src/jupyter/lab/notebook/dashboard/icon.ts b/packages/react/src/jupyter/lab/notebook/dashboard/icon.ts deleted file mode 100644 index b3ea8a52..00000000 --- a/packages/react/src/jupyter/lab/notebook/dashboard/icon.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { LabIcon } from '@jupyterlab/ui-components'; - -import dashboardSvgStr from '@datalayer/icons-react/data1/DashboardIcon.svg'; - -export const dashboardIcon = new LabIcon({ - name: '@datalayer/jupyter-react:notebook-dashboard-icon', - svgstr: dashboardSvgStr -}); diff --git a/packages/react/src/jupyter/lab/notebook/dashboard/plugin.ts b/packages/react/src/jupyter/lab/notebook/dashboard/plugin.ts index 10e534db..70a6f17c 100644 --- a/packages/react/src/jupyter/lab/notebook/dashboard/plugin.ts +++ b/packages/react/src/jupyter/lab/notebook/dashboard/plugin.ts @@ -1,14 +1,14 @@ +import { CommandRegistry } from '@lumino/commands'; +import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; +import { IDisposable } from '@lumino/disposable'; import { JupyterFrontEnd, JupyterFrontEndPlugin, ILayoutRestorer } from '@jupyterlab/application'; import { ICommandPalette, WidgetTracker, ToolbarButton } from '@jupyterlab/apputils'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { DocumentRegistry } from '@jupyterlab/docregistry'; import { IMainMenu } from '@jupyterlab/mainmenu'; import { INotebookTracker, NotebookPanel, INotebookModel } from '@jupyterlab/notebook'; -import { CommandRegistry } from '@lumino/commands'; -import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; -import { IDisposable } from '@lumino/disposable'; import { Dashboard, IDashboardTracker, DashboardFactory } from './dashboard'; -import { dashboardIcon } from './icon'; +import { academicCapIconLabIcon as dashboardIcon } from '@datalayer/icons-react/data1/AcademicCapIconLabIcon'; export namespace CommandIDs { export const dashboardRender = 'notebook:render-with-dashboard'; @@ -28,7 +28,7 @@ class DashboardButton implements DocumentRegistry.IWidgetExtension { this._commands.execute(CommandIDs.dashboardRender); } }); panel.toolbar.insertAfter('cellType', 'dashboardRender', button); diff --git a/packages/traitlets/package.json b/packages/traitlets/package.json index 2082a53b..a53db0ee 100644 --- a/packages/traitlets/package.json +++ b/packages/traitlets/package.json @@ -63,7 +63,7 @@ "kill": "make kill || true" }, "dependencies": { - "@datalayer/primer-addons": "0.0.19", + "@datalayer/primer-addons": "0.0.20", "@jupyterlab/application": "4.0.3", "@jupyterlab/coreutils": "6.0.3", "@jupyterlab/services": "7.0.3",