Skip to content

Commit

Permalink
Merge pull request #840 from jtpio/voila-frontend
Browse files Browse the repository at this point in the history
Update to newer packages for the voila frontend
  • Loading branch information
jtpio committed Feb 23, 2021
2 parents 3237781 + 0ba2776 commit d2fe750
Show file tree
Hide file tree
Showing 6 changed files with 1,339 additions and 1,962 deletions.
36 changes: 18 additions & 18 deletions packages/voila/package.json
Expand Up @@ -8,24 +8,24 @@
"main": "lib/index.js",
"browserslist": ">0.8%, not ie 11, not op_mini all, not dead",
"dependencies": {
"@jupyter-widgets/base": "^2.0.1",
"@jupyter-widgets/controls": "^1.5.0",
"@jupyter-widgets/jupyterlab-manager": "^1.0.0",
"@jupyter-widgets/output": "^2.0.0",
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/docregistry": "^1.0.0",
"@jupyterlab/notebook": "^1.0.0",
"@jupyterlab/outputarea": "^1.0.0",
"@jupyterlab/rendermime": "^1.0.0",
"@jupyterlab/services": "^4.0.0",
"@phosphor/algorithm": "^1.2.0",
"@phosphor/commands": "^1.7.2",
"@phosphor/domutils": "^1.1.4",
"@phosphor/signaling": "^1.3.1",
"@phosphor/virtualdom": "^1.2.0",
"@phosphor/widgets": "^1.5.0",
"core-js": "^3.1.0",
"font-awesome": "^4.7.0",
"@jupyter-widgets/base": "^4.0.0",
"@jupyter-widgets/controls": "^3.0.0",
"@jupyter-widgets/jupyterlab-manager": "^3.0.0",
"@jupyterlab/application": "^3.0.0",
"@jupyterlab/apputils": "^3.0.0",
"@jupyterlab/coreutils": "^5.0.0",
"@jupyterlab/docregistry": "^3.0.0",
"@jupyterlab/notebook": "^3.0.0",
"@jupyterlab/outputarea": "^3.0.0",
"@jupyterlab/rendermime": "^3.0.0",
"@jupyterlab/services": "^6.0.0",
"@lumino/algorithm": "^1.3.3",
"@lumino/commands": "^1.12.0",
"@lumino/domutils": "^1.2.3",
"@lumino/messaging": "^1.4.3",
"@lumino/signaling": "^1.4.3",
"@lumino/virtualdom": "^1.8.0",
"@lumino/widgets": "^1.18.0",
"mathjax-full": "^3.0.0"
},
"devDependencies": {
Expand Down
24 changes: 15 additions & 9 deletions packages/voila/src/kernel.ts
Expand Up @@ -7,18 +7,24 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

import { Kernel, ServerConnection } from '@jupyterlab/services';
import { PageConfig } from '@jupyterlab/coreutils';

import { Kernel, KernelAPI, ServerConnection } from '@jupyterlab/services';

import { KernelConnection } from '@jupyterlab/services/lib/kernel/default';

export async function connectKernel(
baseUrl: string,
kernelId: string
): Promise<Kernel.IKernel> {
baseUrl = baseUrl || PageConfig.getBaseUrl();
kernelId = kernelId || PageConfig.getOption('kernelId');
const connectionInfo = ServerConnection.makeSettings({ baseUrl });
baseUrl?: string,
kernelId?: string
): Promise<Kernel.IKernelConnection | undefined> {
baseUrl = baseUrl ?? PageConfig.getBaseUrl();
kernelId = kernelId ?? PageConfig.getOption('kernelId');
const serverSettings = ServerConnection.makeSettings({ baseUrl });

const model = await Kernel.findById(kernelId, connectionInfo);
const kernel = Kernel.connectTo(model, connectionInfo);
const model = await KernelAPI.getKernelModel(kernelId);
if (!model) {
return;
}
const kernel = new KernelConnection({ model, serverSettings });
return kernel;
}
4 changes: 2 additions & 2 deletions packages/voila/src/loader.ts
Expand Up @@ -14,7 +14,7 @@ const cdn = 'https://cdn.jsdelivr.net/npm/';
*
* @param pkg Package name or names to load
*/
const requirePromise = function(pkg: string[]) {
function requirePromise(pkg: string[]) {
return new Promise((resolve, reject) => {
const require = window.requirejs;
if (require === undefined) {
Expand All @@ -23,7 +23,7 @@ const requirePromise = function(pkg: string[]) {
require(pkg, resolve, reject);
}
});
};
}

function moduleNameToCDNUrl(moduleName: string, moduleVersion: string) {
let packageName = moduleName;
Expand Down
52 changes: 34 additions & 18 deletions packages/voila/src/manager.ts
Expand Up @@ -7,8 +7,11 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

import { WidgetManager as JupyterLabManager } from '@jupyter-widgets/jupyterlab-manager';
import { WidgetRenderer } from '@jupyter-widgets/jupyterlab-manager';
import {
WidgetManager as JupyterLabManager,
WidgetRenderer
} from '@jupyter-widgets/jupyterlab-manager';

import { output } from '@jupyter-widgets/jupyterlab-manager';

import * as base from '@jupyter-widgets/base';
Expand All @@ -19,22 +22,25 @@ import * as AppUtils from '@jupyterlab/apputils';
import * as CoreUtils from '@jupyterlab/coreutils';
import * as DocRegistry from '@jupyterlab/docregistry';
import * as OutputArea from '@jupyterlab/outputarea';

import { DocumentRegistry } from '@jupyterlab/docregistry';
import { INotebookModel } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import * as PhosphorWidget from '@phosphor/widgets';
import * as PhosphorSignaling from '@phosphor/signaling';
import * as PhosphorVirtualdom from '@phosphor/virtualdom';
import * as PhosphorAlgorithm from '@phosphor/algorithm';
import * as PhosphorCommands from '@phosphor/commands';
import * as PhosphorDomutils from '@phosphor/domutils';
import * as LuminoWidget from '@lumino/widgets';
import * as LuminoSignaling from '@lumino/signaling';
import * as LuminoVirtualdom from '@lumino/virtualdom';
import * as LuminoAlgorithm from '@lumino/algorithm';
import * as LuminoCommands from '@lumino/commands';
import * as LuminoDomutils from '@lumino/domutils';

import { MessageLoop } from '@lumino/messaging';

import { MessageLoop } from '@phosphor/messaging';
import { Widget } from '@lumino/widgets';

import { requireLoader } from './loader';

import { batchRateMap } from './utils';
import { Widget } from '@phosphor/widgets';

if (typeof window !== 'undefined' && typeof window.define !== 'undefined') {
window.define('@jupyter-widgets/base', base);
Expand All @@ -47,16 +53,26 @@ if (typeof window !== 'undefined' && typeof window.define !== 'undefined') {
window.define('@jupyterlab/docregistry', DocRegistry);
window.define('@jupyterlab/outputarea', OutputArea);

window.define('@phosphor/widgets', PhosphorWidget);
window.define('@phosphor/signaling', PhosphorSignaling);
window.define('@phosphor/virtualdom', PhosphorVirtualdom);
window.define('@phosphor/algorithm', PhosphorAlgorithm);
window.define('@phosphor/commands', PhosphorCommands);
window.define('@phosphor/domutils', PhosphorDomutils);
window.define('@phosphor/widgets', LuminoWidget);
window.define('@phosphor/signaling', LuminoSignaling);
window.define('@phosphor/virtualdom', LuminoVirtualdom);
window.define('@phosphor/algorithm', LuminoAlgorithm);
window.define('@phosphor/commands', LuminoCommands);
window.define('@phosphor/domutils', LuminoDomutils);

window.define('@lumino/widgets', LuminoWidget);
window.define('@lumino/signaling', LuminoSignaling);
window.define('@lumino/virtualdom', LuminoVirtualdom);
window.define('@lumino/algorithm', LuminoAlgorithm);
window.define('@lumino/commands', LuminoCommands);
window.define('@lumino/domutils', LuminoDomutils);
}

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

/**
* A custom widget manager to render widgets with Voila
*/
export class WidgetManager extends JupyterLabManager {
constructor(
context: DocumentRegistry.IContext<INotebookModel>,
Expand Down Expand Up @@ -111,14 +127,14 @@ export class WidgetManager extends JupyterLabManager {

async display_view(msg: any, view: any, options: any): Promise<Widget> {
if (options.el) {
PhosphorWidget.Widget.attach(view.pWidget, options.el);
LuminoWidget.Widget.attach(view.pWidget, options.el);
}
if (view.el) {
view.el.setAttribute('data-voila-jupyter-widget', '');
view.el.addEventListener('jupyterWidgetResize', (e: Event) => {
MessageLoop.postMessage(
view.pWidget,
PhosphorWidget.Widget.ResizeMessage.UnknownSize
LuminoWidget.Widget.ResizeMessage.UnknownSize
);
});
}
Expand Down
17 changes: 14 additions & 3 deletions share/jupyter/voila/templates/base/static/main.js
Expand Up @@ -11,14 +11,25 @@ require([window.voila_js_url || 'static/voila'], function(voila) {
// requirejs doesn't like to be passed an async function, so create one inside
(async function() {
var kernel = await voila.connectKernel()
if (!kernel) {
return;
}

const context = {
session: {
kernel,
sessionContext: {
session: {
kernel,
kernelChanged: {
connect: () => {}
},
},
statusChanged: {
connect: () => {}
},
kernelChanged: {
connect: () => {}
},
statusChanged: {
connectionStatusChanged: {
connect: () => {}
},
},
Expand Down

0 comments on commit d2fe750

Please sign in to comment.