Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate jupyter widgets manager extension #1394

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:

- name: Browser check
run: |
npx playwright install
python -m jupyterlab.browser_check

- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version: [3.8]
node-version: [16.x]
node-version: [17.x]
fail-fast: false

steps:
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 @@ -7,7 +7,6 @@
"main": "lib/index.js",
"browserslist": ">0.8%, not ie 11, not op_mini all, not dead",
"dependencies": {
"@jupyter-widgets/base": "^6.0.6",
"@jupyter-widgets/jupyterlab-manager": "^5.0.9",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
Expand All @@ -18,7 +17,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/markdownviewer-extension": "^4.0.0",
"@jupyterlab/markedparser-extension": "^4.0.0",
Expand All @@ -43,6 +42,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
2 changes: 1 addition & 1 deletion packages/voila/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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';
Expand Down
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 @@ -23,7 +23,7 @@ import {
loadComponent
} 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

const disabled = [
'@jupyter-widgets/jupyterlab-manager:plugin',
Expand Down Expand Up @@ -137,6 +137,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
73 changes: 73 additions & 0 deletions packages/voila/src/plugins/outputs_rendering.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/***************************************************************************
* 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';

/**
* 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(() => {
// 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 Widget({ node });
app.shell.add(cells, 'main');
}
});
}
};
157 changes: 0 additions & 157 deletions packages/voila/src/plugins/widget.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
6 changes: 2 additions & 4 deletions packages/voila/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import {
pathsPlugin,
themePlugin,
themesManagerPlugin,
translatorPlugin,
widgetManager
} from './voilaplugins';
translatorPlugin
} from './plugins';

export const TREE_DISABLED_EXTENSIONS = [
'@jupyter-widgets/jupyterlab-manager:plugin',
Expand All @@ -45,7 +44,6 @@ async function main() {
pathsPlugin,
translatorPlugin,
themePlugin,
widgetManager,
themesManagerPlugin,
treeWidgetPlugin
];
Expand Down
Loading
Loading