initial revision

This commit is contained in:
Tim Paine 2018-03-11 22:55:24 -04:00
parent 94e9f7bfda
commit 475475b2ba
5 changed files with 132 additions and 0 deletions

3
.gitignore vendored
View file

@ -57,3 +57,6 @@ typings/
# dotenv environment variables file
.env
package-lock.json
lib

33
package.json Normal file
View file

@ -0,0 +1,33 @@
{
"name": "jupyterlab_iframe",
"version": "0.0.1",
"description": "A JupyterLab extension.",
"author": "Tim Paine",
"main": "lib/index.js",
"keywords": [
"jupyter",
"jupyterlab"
],
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"prepublish": "npm run build"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.css"
],
"jupyterlab": {
"extension": true
},
"dependencies": {
"@jupyterlab/application": "^0.15.0",
"@jupyterlab/apputils": "^0.15.0",
"@jupyterlab/docmanager": "^0.15.0",
"@phosphor/disposable": "^1.1.2"
},
"devDependencies": {
"rimraf": "^2.6.1",
"typescript": "~2.6.2"
}
}

78
src/index.ts Normal file
View file

@ -0,0 +1,78 @@
import {
JupyterLab, JupyterLabPlugin, ILayoutRestorer
} from '@jupyterlab/application';
import {
ICommandPalette, showDialog, Dialog
} from '@jupyterlab/apputils';
import {
IDocumentManager
} from '@jupyterlab/docmanager';
import {
Widget
} from '@phosphor/widgets';
import '../style/index.css';
const extension: JupyterLabPlugin<void> = {
id: 'jupyterlab_iframe',
autoStart: true,
requires: [IDocumentManager, ICommandPalette, ILayoutRestorer],
activate: activate
};
class IFrameWidget extends Widget {
constructor(path: string) {
super();
let div = document.createElement('div');
div.classList.add('iframe-widget');
this.node.appendChild(div);
}
};
function activate(app: JupyterLab, docManager: IDocumentManager, palette: ICommandPalette, restorer: ILayoutRestorer) {
console.log('JupyterLab extension knowledgelab is activated!');
// Declare a widget variable
let widget: IFrameWidget;
// Add an application command
const open_command = 'iframe:open';
app.commands.addCommand(open_command, {
label: 'Open IFrame',
isEnabled: () => true,
execute: args => {
var path = typeof args['path'] === 'undefined' ? '': args['path'] as string;
if (path === '') {
showDialog({
title: 'Open site',
focusNodeSelector: 'input',
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: 'path' })]
}).then(result => {
if (!result.value) {
return null;
}
path = <string>result.value;
widget = new IFrameWidget(path);
app.shell.addToMainArea(widget);
app.shell.activateById(widget.id);
});
} else {
widget = new IFrameWidget(path);
app.shell.addToMainArea(widget);
app.shell.activateById(widget.id);
}
}
});
// Add the command to the palette.
palette.addItem({command: open_command, category: 'Tools'});
};
export default extension;

3
style/index.css Normal file
View file

@ -0,0 +1,3 @@
.iframe-widget {
}

15
tsconfig.json Normal file
View file

@ -0,0 +1,15 @@
{
"compilerOptions": {
"declaration": true,
"noImplicitAny": true,
"noEmitOnError": true,
"noUnusedLocals": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "ES5",
"outDir": "./lib",
"lib": ["ES5", "ES2015.Promise", "DOM"],
"types": []
},
"include": ["src/*"]
}