Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Oct 15, 2024
1 parent a660d6f commit c092f4a
Show file tree
Hide file tree
Showing 20 changed files with 473 additions and 97 deletions.
12 changes: 5 additions & 7 deletions packages/voila/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { PageConfig } from '@jupyterlab/coreutils';

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

import { VoilaWidgetManager } from './plugins/widget';

import { IShell, VoilaShell } from './shell';

const PACKAGE = require('../package.json');
Expand Down Expand Up @@ -121,23 +119,23 @@ export class VoilaApp extends JupyterFrontEnd<IShell> {
/**
* A promise that resolves when the Voila Widget Manager is created
*/
get widgetManagerPromise(): PromiseDelegate<VoilaWidgetManager> {
get widgetManagerPromise(): PromiseDelegate<any> {
return this._widgetManagerPromise;
}

set widgetManager(manager: VoilaWidgetManager | null) {
set widgetManager(manager: any) {
this._widgetManager = manager;
if (this._widgetManager) {
this._widgetManagerPromise.resolve(this._widgetManager);
}
}

get widgetManager(): VoilaWidgetManager | null {
get widgetManager(): any {
return this._widgetManager;
}

protected _widgetManager: VoilaWidgetManager | null = null;
protected _widgetManagerPromise = new PromiseDelegate<VoilaWidgetManager>();
protected _widgetManager: any = null;
protected _widgetManagerPromise = new PromiseDelegate<any>();
}

/**
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 @@ -14,4 +14,4 @@ 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/outputs/renderedcells';
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { VoilaWidgetManager } from './manager';
import {
widgetManager,
renderOutputsPlugin,
renderOutputsProgressivelyPlugin
} from './plugins';

export {
VoilaWidgetManager,
widgetManager,
renderOutputsPlugin,
renderOutputsProgressivelyPlugin
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
import {
IJupyterWidgetRegistry,
IWidgetRegistryData
} from '@jupyter-widgets/base';
import { WidgetRenderer } from '@jupyter-widgets/jupyterlab-manager';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { PageConfig } from '@jupyterlab/coreutils';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { KernelAPI, ServerConnection } from '@jupyterlab/services';
import { KernelConnection } from '@jupyterlab/services/lib/kernel/default';
import { Widget } from '@lumino/widgets';

import { VoilaApp } from '../../app';
import { VoilaWidgetManager } from './manager';
import { RenderedCells } from './renderedcells';
import {
createSkeleton,
Expand All @@ -32,80 +24,13 @@ import {
IReceivedWidgetModel
} from './tools';

const WIDGET_MIMETYPE = 'application/vnd.jupyter.widget-view+json';

/**
* The Voila widgets manager plugin.
*/
export const widgetManager: JupyterFrontEndPlugin<IJupyterWidgetRegistry> = {
id: '@voila-dashboards/voila:widget-manager',
autoStart: true,
requires: [IRenderMimeRegistry],
provides: IJupyterWidgetRegistry,
activate: async (
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry
): Promise<IJupyterWidgetRegistry> => {
if (!(app instanceof VoilaApp)) {
throw Error(
'The Voila Widget Manager plugin must be activated in a VoilaApp'
);
}
const baseUrl = PageConfig.getBaseUrl();
const kernelId = PageConfig.getOption('kernelId');
const serverSettings = ServerConnection.makeSettings({ baseUrl });

const model = await KernelAPI.getKernelModel(kernelId, serverSettings);
if (!model) {
return {
registerWidget(data: IWidgetRegistryData): void {
throw Error(`The model for kernel id ${kernelId} does not exist`);
}
};
}
const kernel = new KernelConnection({ model, serverSettings });
const manager = new VoilaWidgetManager(kernel, rendermime);
app.widgetManager = manager;

rendermime.removeMimeType(WIDGET_MIMETYPE);
rendermime.addFactory(
{
safe: false,
mimeTypes: [WIDGET_MIMETYPE],
createRenderer: (options) => new WidgetRenderer(options, manager)
},
-10
);
window.addEventListener('beforeunload', (e) => {
const data = new FormData();
// it seems if we attach this to early, it will not be called
const matches = document.cookie.match('\\b_xsrf=([^;]*)\\b');
const xsrfToken = (matches && matches[1]) || '';
data.append('_xsrf', xsrfToken);
window.navigator.sendBeacon(
`${baseUrl}voila/api/shutdown/${kernel.id}`,
data
);
kernel.dispose();
});

return {
registerWidget: async (data: IWidgetRegistryData) => {
const manager = await app.widgetManagerPromise.promise;

manager.register(data);
}
};
}
};

/**
* The plugin that renders outputs.
*/
export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = {
id: '@voila-dashboards/voila:render-outputs',
autoStart: true,
requires: [IRenderMimeRegistry, IJupyterWidgetRegistry],
requires: [IRenderMimeRegistry],
activate: async (
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry
Expand Down Expand Up @@ -169,7 +94,7 @@ export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = {
export const renderOutputsProgressivelyPlugin: JupyterFrontEndPlugin<void> = {
id: '@voila-dashboards/voila:render-outputs-progressively',
autoStart: true,
requires: [IRenderMimeRegistry, IJupyterWidgetRegistry],
requires: [IRenderMimeRegistry],
activate: async (
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry
Expand All @@ -191,7 +116,7 @@ export const renderOutputsProgressivelyPlugin: JupyterFrontEndPlugin<void> = {
const kernelId = widgetManager.kernel.id;

const receivedWidgetModel: IReceivedWidgetModel = {};
const modelRegisteredHandler = (_: VoilaWidgetManager, modelId: string) => {
const modelRegisteredHandler = (_: any, modelId: string) => {
if (receivedWidgetModel[modelId]) {
const { outputModel, executionModel } = receivedWidgetModel[modelId];
outputModel.add(executionModel);
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/voila/src/sharedscope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import '@jupyterlab/application';
import '@jupyterlab/coreutils';
import '@jupyterlab/console';
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
4 changes: 1 addition & 3 deletions packages/voila/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {
pathsPlugin,
themePlugin,
themesManagerPlugin,
translatorPlugin,
widgetManager
translatorPlugin
} from './voilaplugins';

/**
Expand All @@ -37,7 +36,6 @@ async function main() {
pathsPlugin,
translatorPlugin,
themePlugin,
widgetManager,
themesManagerPlugin,
treeWidgetPlugin
];
Expand Down
4 changes: 2 additions & 2 deletions packages/voila/src/voilaplugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
import { pathsPlugin } from './plugins/path';
import { translatorPlugin } from './plugins/translator';
import { renderOutputsPlugin, widgetManager } from './plugins/widget';
import { renderOutputsPlugin, widgetManager } from './plugins/outputs';
import { themePlugin, themesManagerPlugin } from './plugins/themes';
import { renderOutputsProgressivelyPlugin } from './plugins/widget/index';
import { renderOutputsProgressivelyPlugin } from './plugins/outputs/index';

/**
* Export the plugins as default.
Expand Down
3 changes: 3 additions & 0 deletions packages/widgets_manager7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @voila-dashboards/widgets-manager7

The Jupyter-widgets manager for Voilà and ipywidgets 7.
73 changes: 73 additions & 0 deletions packages/widgets_manager7/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"name": "@voila-dashboards/widgets-manager7",
"version": "0.5.7",
"description": "The Voilà jupyter-widgets manager for ipywidgets 7 support",
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension"
],
"homepage": "https://github.com/voila-dashboards/voila",
"bugs": {
"url": "https://github.com/voila-dashboards/voila/issues"
},
"license": "BSD-3-Clause",
"author": "Voilà contributors",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/voila-dashboards/voila.git"
},
"scripts": {
"build": "jlpm run build:lib && jlpm run build:labextension:dev",
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "jupyter labextension build --development True .",
"build:lib": "tsc",
"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/labextensions/widgets-manager7",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"test": "jest",
"watch": "run-p watch:src watch:labextension",
"watch:labextension": "jupyter labextension watch .",
"watch:src": "tsc -w"
},
"dependencies": {
"@jupyter-widgets/base": "^4.1.6",
"@jupyter-widgets/controls": "^3.1.6",
"@jupyter-widgets/jupyterlab-manager": "^3.1.10",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/coreutils": "^6.0.5",
"@jupyterlab/rendermime": "^4.0.0",
"@jupyterlab/services": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"npm-run-all": "^4.1.5",
"rimraf": "^2.6.1",
"source-map-loader": "~1.0.2",
"typescript": "~5.0.2"
},
"jupyterlab": {
"extension": true,
"outputDir": "../../voila/labextensions/widgets-manager7",
"sharedPackages": {
"@jupyter-widgets/base": {
"bundled": true,
"singleton": true
},
"@jupyter-widgets/jupyterlab-manager": {
"bundled": true,
"singleton": true
}
}
}
}
Loading

0 comments on commit c092f4a

Please sign in to comment.