Skip to content

Commit

Permalink
Add lab-app based JS
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf committed Aug 6, 2019
1 parent f523a7e commit 006aa52
Show file tree
Hide file tree
Showing 11 changed files with 3,563 additions and 604 deletions.
9 changes: 5 additions & 4 deletions js/.babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ "presets": [
[
{
"presets": [[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
]}
]],
"plugins": ["@babel/plugin-syntax-dynamic-import"]
}
3,639 changes: 3,048 additions & 591 deletions js/package-lock.json

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,44 @@
"@jupyter-widgets/controls": "^1.5.0",
"@jupyter-widgets/jupyterlab-manager": "^1.0.0",
"@jupyter-widgets/output": "^2.0.0",
"@jupyterlab/application-extension": "^1.0.0",
"@jupyterlab/apputils-extension": "^1.0.0",
"@jupyterlab/codemirror-extension": "^1.0.0",
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/markdownviewer-extension": "^1.0.0",
"@jupyterlab/mathjax2-extension": "^1.0.0",
"@jupyterlab/outputarea": "^1.0.0",
"@jupyterlab/rendermime": "^1.0.0",
"@jupyterlab/rendermime-extension": "^1.0.0",
"@jupyterlab/services": "^4.0.0",
"@phosphor/signaling": "^1.2.2",
"@phosphor/widgets": "^1.5.0",
"@jupyterlab/shortcuts-extension": "^1.0.0",
"@jupyterlab/theme-dark-extension": "^1.0.0",
"@jupyterlab/theme-light-extension": "^1.0.0",
"@phosphor/signaling": "^1.2.3",
"@phosphor/widgets": "^1.7.0",
"core-js": "^3.1.0",
"font-awesome": "^4.7.0"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"babel-loader": "^8.0.5",
"css-loader": "^3.0.0",
"file-loader": "^4.0.0",
"npm-run-all": "^4.1.5",
"style-loader": "^0.23.1",
"url-loader": "^1.0.0",
"webpack": "^4.29.3",
"webpack": "^4.33.0",
"webpack-cli": "^3.2.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "npm run build:lib && webpack",
"prepublishOnly": "npm run build:all",
"build:lib": "babel src --out-dir lib",
"build:bundle": "webpack",
"build:all": "npm run build:lib && npm run build:bundle",
"watch": "npm-run-all -p watch:*",
"watch:lib": "babel src --out-dir lib --watch",
"watch:bundle": "webpack --watch --mode=development"
Expand Down
5 changes: 5 additions & 0 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
export { RenderMimeRegistry, standardRendererFactories } from '@jupyterlab/rendermime';

export { WidgetManager } from './manager';
import { WidgetManager } from './manager';
export { connectKernel } from './kernel'

export function createWidgetManager(kernel) {
return new WidgetManager(kernel);
}
122 changes: 122 additions & 0 deletions js/src/labindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.


import { PageConfig, URLExt } from '@jupyterlab/coreutils';
__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'voila/static/');

import { JupyterLab } from '@jupyterlab/application';

import {
IRenderMimeRegistry,
RenderMimeRegistry,
standardRendererFactories,
ILatexTypesetter
} from '@jupyterlab/rendermime';

import { PromiseDelegate } from '@phosphor/coreutils';

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

import * as base from '@jupyter-widgets/base';

export { connectKernel } from './kernel';

import { VoilaManager } from './labmanager';

export { VoilaManager } from './labmanager';


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


/**
* Activate the rendermine plugin.
*/
function activateRenderMime(app, latexTypesetter) {
return new RenderMimeRegistry({
initialFactories: standardRendererFactories,
latexTypesetter
});
}


export async function createWidgetManager(kernel, extensions) {

import('font-awesome/css/font-awesome.min.css');

const managerPromise = new PromiseDelegate();

/**
* The widget manager provider.
*/
const plugin = {
id: 'voila:widget-manager-plugin',
requires: [IRenderMimeRegistry],
provides: base.IJupyterWidgetRegistry,
activate: (app, rendermime) => {

const wManager = new VoilaManager(kernel, rendermime);

// Add a placeholder widget renderer.
rendermime.addFactory({
safe: false,
mimeTypes: [WIDGET_VIEW_MIMETYPE],
createRenderer: options => new WidgetRenderer(options, wManager)
}, 0);

wManager.restored.connect(() => {
managerPromise.resolve(wManager);
});

return {
registerWidget(data) {
wManager.register(data);
}
};
},
autoStart: true
};


/**
* A plugin providing a rendermime registry.
*/
const renderMimePluign = {
id: 'voila:rendermime-plugin',
requires: [],
optional: [ILatexTypesetter],
provides: IRenderMimeRegistry,
activate: activateRenderMime,
autoStart: true
};

let mods = [
import('@jupyterlab/application-extension'),
import('@jupyterlab/apputils-extension'),
import('@jupyterlab/codemirror-extension'),
import('@jupyterlab/markdownviewer-extension'),
import('@jupyterlab/mathjax2-extension'),
import('@jupyterlab/rendermime-extension'),
import('@jupyterlab/shortcuts-extension'),
import('@jupyterlab/theme-dark-extension'),
import('@jupyterlab/theme-light-extension'),
renderMimePluign,
plugin
];
if (extensions) {
mods = mods.concat(extensions);
}
const lab = new JupyterLab({
name: 'JupyterLab Voila App',
namespace: 'voila-lab-manager',
version: require('../package.json').version
});
lab.registerPluginModules(mods);
lab.start().then(() => {
// eslint-disable-next-line
console.log('Voila lab app started!');
});

return managerPromise.promise;
}
Loading

0 comments on commit 006aa52

Please sign in to comment.