Skip to content

Commit

Permalink
Separate jupyter widgets manager extension
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Oct 14, 2024
1 parent f1722f4 commit 7d13a63
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 209 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- name: Browser check
run: |
npx playwright install
python -m jupyterlab.browser_check
- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ share/jupyter/voila/templates/base/static/*.LICENSE.txt

lib

voila/labextension
voila/labextensions
tsconfig.tsbuildinfo

ui-tests/playwright-report
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyterlab-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build:prod": "jlpm run build:lib && jlpm run build:labextension",
"build:test": "tsc --build tsconfig.test.json",
"clean": "jlpm run clean:lib && jlpm run clean:labextension",
"clean:labextension": "rimraf ../../voila/labextension",
"clean:labextension": "rimraf ../../voila/labextensions/jupyterlab-preview",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"test": "jest",
"watch": "run-p watch:src watch:labextension",
Expand Down Expand Up @@ -75,7 +75,7 @@
"jupyterlab": {
"extension": true,
"schemaDir": "schema",
"outputDir": "../../voila/labextension",
"outputDir": "../../voila/labextensions/jupyterlab-preview",
"discovery": {
"server": {
"managers": [
Expand Down
4 changes: 2 additions & 2 deletions packages/voila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"browserslist": ">0.8%, not ie 11, not op_mini all, not dead",
"dependencies": {
"@jupyter-widgets/base": "^6.0.10",
"@jupyter-widgets/jupyterlab-manager": "^5.0.13",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
Expand All @@ -22,7 +21,7 @@
"@jupyterlab/docregistry": "^4.0.0",
"@jupyterlab/javascript-extension": "^4.0.0",
"@jupyterlab/json-extension": "^4.0.0",
"@jupyterlab/logconsole": "^4.0.0",
"@jupyterlab/logconsole": "^4.0.5",
"@jupyterlab/mainmenu": "^4.0.0",
"@jupyterlab/markedparser-extension": "^4.0.0",
"@jupyterlab/mathjax-extension": "^4.0.0",
Expand All @@ -47,6 +46,7 @@
"@lumino/domutils": "^2.0.0",
"@lumino/dragdrop": "^2.0.0",
"@lumino/messaging": "^2.0.0",
"@lumino/polling": "^2.0.0",
"@lumino/properties": "^2.0.0",
"@lumino/signaling": "^2.0.0",
"@lumino/virtualdom": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/voila/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

export * from './app';
export * from './shell';
export * from './voilaplugins';
export * from './plugins';
export * from './tools';
export * from './plugins/tree/browser';
export * from './plugins/tree/listing';
export * from './plugins/themes/thememanager';
export * from './plugins/widget/renderedcells';
export * from './plugins/renderedcells';
5 changes: 3 additions & 2 deletions packages/voila/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './sharedscope';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';

import { VoilaApp } from './app';
import plugins from './voilaplugins';
import plugins from './plugins';
import { VoilaServiceManager } from './services/servicemanager';
import { VoilaShell } from './shell';
import {
Expand All @@ -24,7 +24,7 @@ import {
shouldUseMathJax2
} from './tools';

//Inspired by: https://github.com/jupyterlab/jupyterlab/blob/master/dev_mode/index.js
// Inspired by: https://github.com/jupyterlab/jupyterlab/blob/master/dev_mode/index.js

/**
* The main function
Expand Down Expand Up @@ -140,6 +140,7 @@ async function main() {
});
app.registerPluginModules(mods);
await app.start();

window.jupyterapp = app;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
****************************************************************************/

import { JupyterFrontEndPlugin } from '@jupyterlab/application';
import { pathsPlugin } from './plugins/path';
import { translatorPlugin } from './plugins/translator';
import { renderOutputsPlugin, widgetManager } from './plugins/widget';
import { themePlugin, themesManagerPlugin } from './plugins/themes';
import { pathsPlugin } from './path';
import { translatorPlugin } from './translator';
import { renderOutputsPlugin } from './outputs_rendering';
import { themePlugin, themesManagerPlugin } from './themes';

/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
pathsPlugin,
translatorPlugin,
widgetManager,
renderOutputsPlugin,
themesManagerPlugin,
themePlugin
Expand All @@ -30,7 +29,6 @@ export default plugins;
export {
pathsPlugin,
translatorPlugin,
widgetManager,
renderOutputsPlugin,
themesManagerPlugin,
themePlugin
Expand Down
83 changes: 83 additions & 0 deletions packages/voila/src/plugins/outputs_rendering.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/***************************************************************************
* Copyright (c) 2018, Voilà contributors *
* Copyright (c) 2018, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import { Widget } from '@lumino/widgets';
import { RenderedCells } from './renderedcells';

/**
* The plugin that renders outputs.
*/
export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = {
id: '@voila-dashboards/voila:render-outputs',
autoStart: true,
requires: [IRenderMimeRegistry],
activate: (app: JupyterFrontEnd, rendermime: IRenderMimeRegistry): void => {
// This "app.started.then" is a trick to make sure we render the output only when all plugins are loaded
// Not using await here because we want this function to return immediately
// Otherwise it prevents the application to start and resolve the "started" promise...
app.started.then(async () => {
// TODO: Typeset a fake element to get MathJax loaded, remove this hack once
// MathJax 2 is removed.
await rendermime.latexTypesetter?.typeset(document.createElement('div'));

// Render latex in markdown cells
const mdOutput = document.body.querySelectorAll('div.jp-MarkdownOutput');
mdOutput.forEach((md) => {
rendermime.latexTypesetter?.typeset(md as HTMLElement);
});
// Render outputs
const cellOutputs = document.body.querySelectorAll(
'script[type="application/vnd.voila.cell-output+json"]'
);
cellOutputs.forEach(async (cellOutput) => {
const model = JSON.parse(cellOutput.innerHTML);

const mimeType = rendermime.preferredMimeType(model.data, 'any');

if (!mimeType) {
return null;
}
const output = rendermime.createRenderer(mimeType);
output.renderModel(model).catch((error) => {
// Manually append error message to output
const pre = document.createElement('pre');
pre.textContent = `Javascript Error: ${error.message}`;
output.node.appendChild(pre);

// Remove mime-type-specific CSS classes
pre.className = 'lm-Widget jp-RenderedText';
pre.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr');
});

output.addClass('jp-OutputArea-output');

if (cellOutput.parentElement) {
const container = cellOutput.parentElement;

container.removeChild(cellOutput);

// Attach output
Widget.attach(output, container);
}
});
const node = document.getElementById('rendered_cells');
if (node) {
const cells = new RenderedCells({ node });
app.shell.add(cells, 'main');
}
});
}
};
File renamed without changes.
166 changes: 0 additions & 166 deletions packages/voila/src/plugins/widget/index.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/voila/src/sharedscope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import '@jupyterlab/application';
import '@jupyterlab/coreutils';
import '@jupyterlab/rendermime';
import '@jupyterlab/services';
import '@jupyterlab/statedb';
import '@jupyterlab/notebook';
import '@jupyterlab/mainmenu';
import '@jupyterlab/logconsole';
import '@lumino/algorithm';
import '@lumino/application';
import '@lumino/coreutils';
Expand Down
Loading

0 comments on commit 7d13a63

Please sign in to comment.