diff --git a/index.js b/index.js new file mode 100644 index 00000000..3344fcbf --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +// This is the main file that will be loaded when urth-widgets is required in an +// npm environment. +// +//module.exports = function createDefine(targetModule) { +// var amdefine = require('amdefine')(targetModule, require); +// +// return function define() { +// var args = Array.prototype.slice.call(arguments); +// //if (args.length > 1) { +// // args[0] = args[0].map(function(arg) { +// // if (arg === 'jqueryui') arg = 'jquery'; +// // arg = arg.replace('nbextensions/widgets/widgets/css/', '../css/'); +// // arg = arg.replace('nbextensions/widgets/components/require-css/css!', ''); +// // return arg; +// // }); +// //} +// amdefine.apply(this, args); +// }; +//}; + +require('./dist/urth_widgets/js/init/init'); diff --git a/nb-extension/js/init/init.js b/nb-extension/js/init/init.js index ae41ef5b..7da9fc2e 100644 --- a/nb-extension/js/init/init.js +++ b/nb-extension/js/init/init.js @@ -7,12 +7,22 @@ * Loads the web component polyfill and all web components specified in * elements.html. */ +debugger; +// npm compatibility +function requireLocalFiles() { + require('jquery'); + require('../widgets/DeclWidgetModel'); +} + +if (typeof define !== 'function') { var define = require('amdefine')(module, require); } + define([ 'require', 'jquery', '../widgets/DeclWidgetModel'], function(require, $) { 'use strict'; + debugger; function loadComponents(bower_root, links) { console.debug('Bower root is: ', bower_root); diff --git a/nb-extension/js/widgets/DeclWidgetModel.js b/nb-extension/js/widgets/DeclWidgetModel.js index 4747ad16..cc3a79dc 100644 --- a/nb-extension/js/widgets/DeclWidgetModel.js +++ b/nb-extension/js/widgets/DeclWidgetModel.js @@ -1,10 +1,35 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +// npm compatibility +function requireLocalFiles() { + require('../../../../node_modules/jupyter-js-widgets/static/widgets/js/manager-base'); + require('../../../../node_modules/jupyter-js-widgets/static/widgets/js/widget'); +} + +if (typeof define !== 'function') { + var amdefine = require('amdefine')(module, require); + + var mapping = {} + mapping['nbextensions/widgets/widgets/js/manager'] = '../../../../node_modules/jupyter-js-widgets/static/widgets/js/manager-base' + mapping['nbextensions/widgets/widgets/js/widget'] = '../../../../node_modules/jupyter-js-widgets/static/widgets/js/widget' + + var define = function(){ + debugger; + var args = Array.prototype.slice.call(arguments); + if (args.length > 1) { + args[0] = args[0].map(function(arg) { + arg = mapping[arg] || arg; + return arg; + }); + } + amdefine.apply(this, args); + } +} + define(["nbextensions/widgets/widgets/js/manager", - "nbextensions/widgets/widgets/js/widget", - "base/js/namespace" -], function(widgetmanager, ipywidget, IPython) { + "nbextensions/widgets/widgets/js/widget" +], function(widgetmanager, ipywidget) { "use strict"; /** @@ -33,7 +58,7 @@ define(["nbextensions/widgets/widgets/js/manager", this.comm.send(data, callbacks); }; - widgetmanager.WidgetManager.register_widget_model('DeclWidgetModel', DeclWidgetModel); + widgetmanager.ManagerBase.register_widget_model('DeclWidgetModel', DeclWidgetModel); return DeclWidgetModel; diff --git a/notebooks/examples/urth-scala-widgets.ipynb b/notebooks/examples/urth-scala-widgets.ipynb index 267b8f60..0557d653 100644 --- a/notebooks/examples/urth-scala-widgets.ipynb +++ b/notebooks/examples/urth-scala-widgets.ipynb @@ -35,7 +35,7 @@ "outputs": [], "source": [ "// modify to IP and Port of this notebook server\n", - "%addjar http://192.168.99.100:8888/nbextensions/urth_widgets/urth-widgets.jar" + "%addjar http://192.168.99.100:8888/nbexten tsions/urth_widgets/urth-widgets.jar" ] }, { diff --git a/package.json b/package.json index 4d5a4898..83319573 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,10 @@ "selenium-standalone": "latest", "web-component-tester": "~3.4" }, + "dependencies": { + "amdefine": "^1.0.0", + "jquery": "^2.1.4" + }, "config": {}, "scripts": { "bower": "bower",