From 61dca6f43edc4c00502854348334312af6d3761f Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 10:12:43 +0200 Subject: [PATCH 1/7] HTMLManager: Support both ipywidgets 7 and 8 models --- packages/html-manager/package.json | 5 +- .../html-manager/scripts/concat-amd-build.js | 4 +- packages/html-manager/src/htmlmanager.ts | 47 ++- packages/html-manager/src/libembed-amd.ts | 17 +- packages/html-manager/src/libembed.ts | 10 - packages/html-manager/src/utils.ts | 15 + packages/html-manager/webpack.config.js | 28 ++ yarn.lock | 389 +++++++++++++++--- 8 files changed, 435 insertions(+), 80 deletions(-) create mode 100644 packages/html-manager/src/utils.ts diff --git a/packages/html-manager/package.json b/packages/html-manager/package.json index aed9619ec9..1df0e53a38 100644 --- a/packages/html-manager/package.json +++ b/packages/html-manager/package.json @@ -38,7 +38,9 @@ "@fortawesome/fontawesome-free": "^5.12.0", "@jupyter-widgets/base": "^6.0.8", "@jupyter-widgets/base-manager": "^1.0.9", + "@jupyter-widgets/base7": "npm:@jupyter-widgets/base@4.1.6", "@jupyter-widgets/controls": "^5.0.9", + "@jupyter-widgets/controls7": "npm:@jupyter-widgets/controls@3.1.6", "@jupyter-widgets/output": "^6.0.8", "@jupyter-widgets/schema": "^0.5.5", "@jupyterlab/outputarea": "^3.0.0 || ^4.0.0", @@ -47,7 +49,8 @@ "@lumino/messaging": "^1.10.1 || ^2.1", "@lumino/widgets": "^1.30.0 || ^2.1", "ajv": "^8.6.0", - "jquery": "^3.1.1" + "jquery": "^3.1.1", + "semver": "^7.3.5" }, "devDependencies": { "@types/jquery": "^3.5.16", diff --git a/packages/html-manager/scripts/concat-amd-build.js b/packages/html-manager/scripts/concat-amd-build.js index d63b26d746..8183594543 100755 --- a/packages/html-manager/scripts/concat-amd-build.js +++ b/packages/html-manager/scripts/concat-amd-build.js @@ -4,7 +4,7 @@ var fs = require('fs'); // Make a script file that defines all of the relevant AMD modules -var files = ['base.js', 'controls.js', 'index.js', 'libembed-amd.js']; +var files = ['base.js', 'controls.js', 'base7.js', 'controls7.js', 'index.js', 'libembed-amd.js']; var output = files .map((f) => { return fs.readFileSync('./dist/amd/' + f).toString(); @@ -17,6 +17,8 @@ fs.writeFileSync('./dist/libembed-amd.js', output); files = [ 'base.js', 'controls.js', + 'base7.js', + 'controls7.js', 'index.js', 'libembed-amd.js', 'embed-amd-render.js', diff --git a/packages/html-manager/src/htmlmanager.ts b/packages/html-manager/src/htmlmanager.ts index 50f5807da5..9808bcaa11 100644 --- a/packages/html-manager/src/htmlmanager.ts +++ b/packages/html-manager/src/htmlmanager.ts @@ -1,7 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import * as widgets from '@jupyter-widgets/controls'; +import { maxSatisfying } from 'semver'; import * as base from '@jupyter-widgets/base'; import * as outputWidgets from './output'; import { ManagerBase } from '@jupyter-widgets/base-manager'; @@ -15,6 +15,7 @@ import { import { WidgetRenderer, WIDGET_MIMETYPE } from './output_renderers'; import { WidgetModel, WidgetView, DOMWidgetView } from '@jupyter-widgets/base'; +import { requirePromise } from './utils'; export class HTMLManager extends ManagerBase { constructor(options?: { @@ -38,7 +39,7 @@ export class HTMLManager extends ManagerBase { window.addEventListener('resize', () => { this._viewList.forEach((view) => { MessageLoop.postMessage( - view.luminoWidget, + view.luminoWidget || view.pWidget, LuminoWidget.Widget.ResizeMessage.UnknownSize ); }); @@ -66,7 +67,7 @@ export class HTMLManager extends ManagerBase { v.render(); } - LuminoWidget.Widget.attach(v.luminoWidget, el); + LuminoWidget.Widget.attach(v.luminoWidget || v.pWidget, el); this._viewList.add(v); v.once('remove', () => { this._viewList.delete(v); @@ -113,9 +114,45 @@ export class HTMLManager extends ManagerBase { ): Promise { return new Promise((resolve, reject) => { if (moduleName === '@jupyter-widgets/base') { - resolve(base); + const best = maxSatisfying(['1.2.0', '2.0.0'], moduleVersion); + + if (best === '1.2.0') { + // ipywidgets 7 model + requirePromise(['@jupyter-widgets/base7']).then(resolve); + } else { + // ipywidgets 8 model + requirePromise(['@jupyter-widgets/base']).then(resolve); + } } else if (moduleName === '@jupyter-widgets/controls') { - resolve(widgets); + const best = maxSatisfying(['1.5.0', '2.0.0'], moduleVersion); + + if (best === '1.5.0') { + // ipywidgets 7 controls JS and CSS + require('@jupyter-widgets/controls7/css/widgets-base.css'); + + // If lab variables are not found, we set them (we don't want to reset the variables if they are already defined) + if ( + getComputedStyle(document.documentElement).getPropertyValue( + '--jp-layout-color0' + ) === '' + ) { + require('@jupyter-widgets/controls7/css/labvariables.css'); + } + requirePromise(['@jupyter-widgets/controls7']).then(resolve); + } else { + // ipywidgets 8 controls JS and CSS + require('@jupyter-widgets/controls/css/widgets-base.css'); + + // If lab variables are not found, we set them (we don't want to reset the variables if they are already defined) + if ( + getComputedStyle(document.documentElement).getPropertyValue( + '--jp-layout-color0' + ) === '' + ) { + require('@jupyter-widgets/controls/css/labvariables.css'); + } + requirePromise(['@jupyter-widgets/controls']).then(resolve); + } } else if (moduleName === '@jupyter-widgets/output') { resolve(outputWidgets); } else if (this.loader !== undefined) { diff --git a/packages/html-manager/src/libembed-amd.ts b/packages/html-manager/src/libembed-amd.ts index 6cf1868c60..76c8728ddf 100644 --- a/packages/html-manager/src/libembed-amd.ts +++ b/packages/html-manager/src/libembed-amd.ts @@ -2,6 +2,7 @@ // Distributed under the terms of the Modified BSD License. import * as libembed from './libembed'; +import { requirePromise } from './utils'; let cdn = 'https://cdn.jsdelivr.net/npm/'; let onlyCDN = false; @@ -13,22 +14,6 @@ Array.prototype.forEach.call(scripts, (script: HTMLScriptElement) => { onlyCDN = onlyCDN || script.hasAttribute('data-jupyter-widgets-cdn-only'); }); -/** - * Load a package using requirejs and return a promise - * - * @param pkg Package name or names to load - */ -const requirePromise = function (pkg: string | string[]): Promise { - return new Promise((resolve, reject) => { - const require = (window as any).requirejs; - if (require === undefined) { - reject('Requirejs is needed, please ensure it is loaded on the page.'); - } else { - require(pkg, resolve, reject); - } - }); -}; - function moduleNameToCDNUrl(moduleName: string, moduleVersion: string): string { let packageName = moduleName; let fileName = 'index'; // default filename diff --git a/packages/html-manager/src/libembed.ts b/packages/html-manager/src/libembed.ts index 494734d6aa..00e5ceb13e 100644 --- a/packages/html-manager/src/libembed.ts +++ b/packages/html-manager/src/libembed.ts @@ -11,16 +11,6 @@ import '@fortawesome/fontawesome-free/css/all.min.css'; import '@fortawesome/fontawesome-free/css/v4-shims.min.css'; import '@lumino/widgets/style/index.css'; -import '@jupyter-widgets/controls/css/widgets-base.css'; - -// If lab variables are not found, we set them (we don't want to reset the variables if they are already defined) -if ( - getComputedStyle(document.documentElement).getPropertyValue( - '--jp-layout-color0' - ) === '' -) { - require('@jupyter-widgets/controls/css/labvariables.css'); -} // Used just for the typing. We must not import the javascript because we don't // want to include it in the require embedding. diff --git a/packages/html-manager/src/utils.ts b/packages/html-manager/src/utils.ts new file mode 100644 index 0000000000..a454c401e7 --- /dev/null +++ b/packages/html-manager/src/utils.ts @@ -0,0 +1,15 @@ +/** + * Load a package using requirejs and return a promise + * + * @param pkg Package name or names to load + */ +export function requirePromise(pkg: string | string[]): Promise { + return new Promise((resolve, reject) => { + const require = (window as any).requirejs; + if (require === undefined) { + reject('Requirejs is needed, please ensure it is loaded on the page.'); + } else { + require(pkg, resolve, reject); + } + }); +}; diff --git a/packages/html-manager/webpack.config.js b/packages/html-manager/webpack.config.js index 7b8dc1d5bb..826566add0 100644 --- a/packages/html-manager/webpack.config.js +++ b/packages/html-manager/webpack.config.js @@ -93,4 +93,32 @@ module.exports = [ externals: ['@jupyter-widgets/base', 'module'], ...options, }, + { + // @jupyter-widgets/base ipywidgets 7 + entry: ['./amd-public-path.js', '@jupyter-widgets/base7/lib/index'], + output: { + library: '@jupyter-widgets/base7', + filename: 'base7.js', + path: path.resolve(__dirname, 'dist', 'amd'), + libraryTarget: 'amd', + publicPath: '', // Set in amd-public-path.js + }, + // 'module' is the magic requirejs dependency used to set the publicPath + externals: ['module'], + ...options, + }, + { + // @jupyter-widgets/controls + entry: ['./amd-public-path.js', '@jupyter-widgets/controls7/lib/index'], + output: { + library: '@jupyter-widgets/controls7', + filename: 'controls7.js', + path: path.resolve(__dirname, 'dist', 'amd'), + libraryTarget: 'amd', + publicPath: '', // Set in amd-public-path.js + }, + // 'module' is the magic requirejs dependency used to set the publicPath + externals: ['@jupyter-widgets/base7', 'module'], + ...options, + }, ]; diff --git a/yarn.lock b/yarn.lock index 3cf819b206..953df175c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -732,11 +732,11 @@ __metadata: languageName: node linkType: hard -"@jupyter-widgets/base-manager@^1.0.8, @jupyter-widgets/base-manager@workspace:packages/base-manager": +"@jupyter-widgets/base-manager@^1.0.9, @jupyter-widgets/base-manager@workspace:packages/base-manager": version: 0.0.0-use.local resolution: "@jupyter-widgets/base-manager@workspace:packages/base-manager" dependencies: - "@jupyter-widgets/base": ^6.0.7 + "@jupyter-widgets/base": ^6.0.8 "@jupyterlab/services": ^6.0.0 || ^7.0.0 "@lumino/coreutils": ^1.11.1 || ^2 "@types/base64-js": ^1.2.5 @@ -771,7 +771,25 @@ __metadata: languageName: unknown linkType: soft -"@jupyter-widgets/base@^6.0.7, @jupyter-widgets/base@workspace:packages/base": +"@jupyter-widgets/base7@npm:@jupyter-widgets/base@4.1.6, @jupyter-widgets/base@npm:^4.1.6": + version: 4.1.6 + resolution: "@jupyter-widgets/base@npm:4.1.6" + dependencies: + "@jupyterlab/services": ^6.0.0 + "@lumino/coreutils": ^1.2.0 + "@lumino/messaging": ^1.2.1 + "@lumino/widgets": ^1.3.0 + "@types/backbone": ^1.4.1 + "@types/lodash": ^4.14.134 + backbone: 1.2.3 + base64-js: ^1.2.1 + jquery: ^3.1.1 + lodash: ^4.17.4 + checksum: cdd11e8fd480a44b9e9f5a37529361c407456d9e2d2a09f35b8f067b65e915c132aaaaab8d8523f3c8c624e3403215d6eb56a21337f57213b75ebb377a26c208 + languageName: node + linkType: hard + +"@jupyter-widgets/base@^6.0.8, @jupyter-widgets/base@workspace:packages/base": version: 0.0.0-use.local resolution: "@jupyter-widgets/base@workspace:packages/base" dependencies: @@ -814,11 +832,29 @@ __metadata: languageName: unknown linkType: soft -"@jupyter-widgets/controls@^5.0.8, @jupyter-widgets/controls@workspace:packages/controls": +"@jupyter-widgets/controls7@npm:@jupyter-widgets/controls@3.1.6": + version: 3.1.6 + resolution: "@jupyter-widgets/controls@npm:3.1.6" + dependencies: + "@jupyter-widgets/base": ^4.1.6 + "@lumino/algorithm": ^1.1.0 + "@lumino/domutils": ^1.1.0 + "@lumino/messaging": ^1.2.1 + "@lumino/signaling": ^1.2.0 + "@lumino/widgets": ^1.3.0 + d3-format: ^1.3.0 + jquery: ^3.1.1 + jquery-ui: ^1.12.1 + underscore: ^1.8.3 + checksum: 9c69ebe9ce22d7e7cf3cd66dc849505c1433da4424d8daa7411d85f41027d5600c20c2350d703fe582fd44a4b5d11ad8b404fe058b686f17cd47bafd41547646 + languageName: node + linkType: hard + +"@jupyter-widgets/controls@^5.0.9, @jupyter-widgets/controls@workspace:packages/controls": version: 0.0.0-use.local resolution: "@jupyter-widgets/controls@workspace:packages/controls" dependencies: - "@jupyter-widgets/base": ^6.0.7 + "@jupyter-widgets/base": ^6.0.8 "@jupyterlab/services": ^6.0.0 || ^7.0.0 "@lumino/algorithm": ^1.9.1 || ^2.1 "@lumino/domutils": ^1.8.1 || ^2.1 @@ -869,9 +905,9 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/example-web1@workspace:examples/web1" dependencies: - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/base-manager": ^1.0.8 - "@jupyter-widgets/controls": ^5.0.8 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/base-manager": ^1.0.9 + "@jupyter-widgets/controls": ^5.0.9 chai: ^4.0.0 css-loader: ^6.5.1 karma: ^6.3.3 @@ -890,9 +926,9 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/example-web2@workspace:examples/web2" dependencies: - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/base-manager": ^1.0.8 - "@jupyter-widgets/controls": ^5.0.8 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/base-manager": ^1.0.9 + "@jupyter-widgets/controls": ^5.0.9 codemirror: ^5.48.0 css-loader: ^6.5.1 font-awesome: ^4.7.0 @@ -905,9 +941,9 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/example-web3@workspace:examples/web3" dependencies: - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/controls": ^5.0.8 - "@jupyter-widgets/html-manager": ^1.0.10 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/controls": ^5.0.9 + "@jupyter-widgets/html-manager": ^1.0.11 "@jupyterlab/services": ^6.0.0 || ^7.0.0 "@types/codemirror": ^5.60.0 "@types/node": ^17.0.2 @@ -927,7 +963,7 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/example-web4@workspace:examples/web4" dependencies: - "@jupyter-widgets/html-manager": ^1.0.10 + "@jupyter-widgets/html-manager": ^1.0.11 css-loader: ^6.5.1 font-awesome: ^4.7.0 style-loader: ^3.3.1 @@ -935,16 +971,18 @@ __metadata: languageName: unknown linkType: soft -"@jupyter-widgets/html-manager@^1.0.10, @jupyter-widgets/html-manager@workspace:packages/html-manager": +"@jupyter-widgets/html-manager@^1.0.11, @jupyter-widgets/html-manager@workspace:packages/html-manager": version: 0.0.0-use.local resolution: "@jupyter-widgets/html-manager@workspace:packages/html-manager" dependencies: "@fortawesome/fontawesome-free": ^5.12.0 - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/base-manager": ^1.0.8 - "@jupyter-widgets/controls": ^5.0.8 - "@jupyter-widgets/output": ^6.0.7 - "@jupyter-widgets/schema": ^0.5.4 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/base-manager": ^1.0.9 + "@jupyter-widgets/base7": "npm:@jupyter-widgets/base@4.1.6" + "@jupyter-widgets/controls": ^5.0.9 + "@jupyter-widgets/controls7": "npm:@jupyter-widgets/controls@3.1.6" + "@jupyter-widgets/output": ^6.0.8 + "@jupyter-widgets/schema": ^0.5.5 "@jupyterlab/outputarea": ^3.0.0 || ^4.0.0 "@jupyterlab/rendermime": ^3.0.0 || ^4.0.0 "@jupyterlab/rendermime-interfaces": ^3.0.0 || ^4.0.0 @@ -970,6 +1008,7 @@ __metadata: postcss-import: ^14.0.2 postcss-loader: ^6.1.0 rimraf: ^3.0.2 + semver: ^7.3.5 style-loader: ^3.3.1 typescript: ~4.9.4 webpack: ^5.65.0 @@ -981,10 +1020,10 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/jupyterlab-manager@workspace:python/jupyterlab_widgets" dependencies: - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/base-manager": ^1.0.8 - "@jupyter-widgets/controls": ^5.0.8 - "@jupyter-widgets/output": ^6.0.7 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/base-manager": ^1.0.9 + "@jupyter-widgets/controls": ^5.0.9 + "@jupyter-widgets/output": ^6.0.8 "@jupyterlab/application": ^3.0.0 || ^4.0.0 "@jupyterlab/apputils": ^3.0.0 || ^4.0.0 "@jupyterlab/builder": ^3.0.0 || ^4.0.0 @@ -1028,11 +1067,11 @@ __metadata: version: 0.0.0-use.local resolution: "@jupyter-widgets/notebook-manager@workspace:python/widgetsnbextension" dependencies: - "@jupyter-widgets/base": ^6.0.7 - "@jupyter-widgets/base-manager": ^1.0.8 - "@jupyter-widgets/controls": ^5.0.8 - "@jupyter-widgets/html-manager": ^1.0.10 - "@jupyter-widgets/output": ^6.0.7 + "@jupyter-widgets/base": ^6.0.8 + "@jupyter-widgets/base-manager": ^1.0.9 + "@jupyter-widgets/controls": ^5.0.9 + "@jupyter-widgets/html-manager": ^1.0.11 + "@jupyter-widgets/output": ^6.0.8 "@jupyterlab/services": ^6.0.0 || ^7.0.0 "@lumino/messaging": ^1.10.1 || ^2.1 "@lumino/widgets": ^1.30.0 || ^2.1 @@ -1046,17 +1085,17 @@ __metadata: languageName: unknown linkType: soft -"@jupyter-widgets/output@^6.0.7, @jupyter-widgets/output@workspace:packages/output": +"@jupyter-widgets/output@^6.0.8, @jupyter-widgets/output@workspace:packages/output": version: 0.0.0-use.local resolution: "@jupyter-widgets/output@workspace:packages/output" dependencies: - "@jupyter-widgets/base": ^6.0.7 + "@jupyter-widgets/base": ^6.0.8 rimraf: ^3.0.2 typescript: ~4.9.4 languageName: unknown linkType: soft -"@jupyter-widgets/schema@^0.5.4, @jupyter-widgets/schema@workspace:packages/schema": +"@jupyter-widgets/schema@^0.5.5, @jupyter-widgets/schema@workspace:packages/schema": version: 0.0.0-use.local resolution: "@jupyter-widgets/schema@workspace:packages/schema" languageName: unknown @@ -1371,6 +1410,21 @@ __metadata: languageName: node linkType: hard +"@jupyterlab/coreutils@npm:^5.6.7": + version: 5.6.7 + resolution: "@jupyterlab/coreutils@npm:5.6.7" + dependencies: + "@lumino/coreutils": ^1.11.0 + "@lumino/disposable": ^1.10.0 + "@lumino/signaling": ^1.10.0 + minimist: ~1.2.0 + moment: ^2.24.0 + path-browserify: ^1.0.0 + url-parse: ~1.5.1 + checksum: 94530cd2559ce8b5fe6b86a3125868be10d15bcdf91ae71abaf3f96653b76a618158b707f60d30aaf0bcc372993ed3dca874814e500bd43351a724930e6af81d + languageName: node + linkType: hard + "@jupyterlab/coreutils@npm:^6.2.1": version: 6.2.1 resolution: "@jupyterlab/coreutils@npm:6.2.1" @@ -1549,6 +1603,15 @@ __metadata: languageName: node linkType: hard +"@jupyterlab/nbformat@npm:^3.6.7": + version: 3.6.7 + resolution: "@jupyterlab/nbformat@npm:3.6.7" + dependencies: + "@lumino/coreutils": ^1.11.0 + checksum: 41def9da46c8cc2baddc61e5d43f9fd567ba9729d7f78f0cc9c34cb894e765d2b713643b8457c1d97272c52a1f10cc62febcbf97450fdfa1b26a7c205bd9581c + languageName: node + linkType: hard + "@jupyterlab/notebook@npm:^3.0.0 || ^4.0.0": version: 4.2.1 resolution: "@jupyterlab/notebook@npm:4.2.1" @@ -1587,6 +1650,19 @@ __metadata: languageName: node linkType: hard +"@jupyterlab/observables@npm:^4.6.7": + version: 4.6.7 + resolution: "@jupyterlab/observables@npm:4.6.7" + dependencies: + "@lumino/algorithm": ^1.9.0 + "@lumino/coreutils": ^1.11.0 + "@lumino/disposable": ^1.10.0 + "@lumino/messaging": ^1.10.0 + "@lumino/signaling": ^1.10.0 + checksum: af9ccc6db2c63bb38a041ae1c2c6ec3b29f8b9ab3fce03e8b18e79095ccd1690fc00c79d606fcfc388d9595ef38d4f98e5df36f6fc12c58f10aa152177fb1c6b + languageName: node + linkType: hard + "@jupyterlab/observables@npm:^5.2.1": version: 5.2.1 resolution: "@jupyterlab/observables@npm:5.2.1" @@ -1652,6 +1728,26 @@ __metadata: languageName: node linkType: hard +"@jupyterlab/services@npm:^6.0.0": + version: 6.6.7 + resolution: "@jupyterlab/services@npm:6.6.7" + dependencies: + "@jupyterlab/coreutils": ^5.6.7 + "@jupyterlab/nbformat": ^3.6.7 + "@jupyterlab/observables": ^4.6.7 + "@jupyterlab/settingregistry": ^3.6.7 + "@jupyterlab/statedb": ^3.6.7 + "@lumino/algorithm": ^1.9.0 + "@lumino/coreutils": ^1.11.0 + "@lumino/disposable": ^1.10.0 + "@lumino/polling": ^1.9.0 + "@lumino/signaling": ^1.10.0 + node-fetch: ^2.6.0 + ws: ^7.4.6 + checksum: ad3e8f5c9edb6b09ddad50be2285c80bafa22c604fd4f99cc46f7bdb9c9592079f5ccea7a497bf791e9b388b114fd2952814db806a9dd25df8eaed17bb5ec9e6 + languageName: node + linkType: hard + "@jupyterlab/services@npm:^6.0.0 || ^7.0.0, @jupyterlab/services@npm:^7.2.1": version: 7.2.1 resolution: "@jupyterlab/services@npm:7.2.1" @@ -1690,6 +1786,34 @@ __metadata: languageName: node linkType: hard +"@jupyterlab/settingregistry@npm:^3.6.7": + version: 3.6.7 + resolution: "@jupyterlab/settingregistry@npm:3.6.7" + dependencies: + "@jupyterlab/statedb": ^3.6.7 + "@lumino/commands": ^1.19.0 + "@lumino/coreutils": ^1.11.0 + "@lumino/disposable": ^1.10.0 + "@lumino/signaling": ^1.10.0 + ajv: ^6.12.3 + json5: ^2.1.1 + checksum: 01e2066d1fc08af7465ad458e06096e3d893776567e1818841fb204c763ba9c067fde49fcc57941a4f8399a5006d36e63832042b77cd5c3447c48ccaaafee864 + languageName: node + linkType: hard + +"@jupyterlab/statedb@npm:^3.6.7": + version: 3.6.7 + resolution: "@jupyterlab/statedb@npm:3.6.7" + dependencies: + "@lumino/commands": ^1.19.0 + "@lumino/coreutils": ^1.11.0 + "@lumino/disposable": ^1.10.0 + "@lumino/properties": ^1.8.0 + "@lumino/signaling": ^1.10.0 + checksum: 4c92b467e6c616becd8fc958ffe699a648215516e33d0b3987d23469f81e0ad81404b3b2c6413b250620ce8a2940489bea6cf3ed31a82f9063f7291b7f8f655f + languageName: node + linkType: hard + "@jupyterlab/statedb@npm:^4.2.1": version: 4.2.1 resolution: "@jupyterlab/statedb@npm:4.2.1" @@ -2755,6 +2879,13 @@ __metadata: languageName: node linkType: hard +"@lumino/algorithm@npm:^1.1.0, @lumino/algorithm@npm:^1.9.0, @lumino/algorithm@npm:^1.9.1 || ^2.1, @lumino/algorithm@npm:^1.9.2": + version: 1.9.2 + resolution: "@lumino/algorithm@npm:1.9.2" + checksum: a89e7c63504236119634858e271db1cc649684d30ced5a6ebe2788af7c0837f1e05a6fd3047d8525eb756c42ce137f76b3688f75fd3ef915b71cd4f213dfbb96 + languageName: node + linkType: hard + "@lumino/algorithm@npm:^1.11.1 || ^2.0.0, @lumino/algorithm@npm:^2.0.1": version: 2.0.1 resolution: "@lumino/algorithm@npm:2.0.1" @@ -2762,13 +2893,6 @@ __metadata: languageName: node linkType: hard -"@lumino/algorithm@npm:^1.9.1 || ^2.1, @lumino/algorithm@npm:^1.9.2": - version: 1.9.2 - resolution: "@lumino/algorithm@npm:1.9.2" - checksum: a89e7c63504236119634858e271db1cc649684d30ced5a6ebe2788af7c0837f1e05a6fd3047d8525eb756c42ce137f76b3688f75fd3ef915b71cd4f213dfbb96 - languageName: node - linkType: hard - "@lumino/application@npm:^2.3.1": version: 2.3.1 resolution: "@lumino/application@npm:2.3.1" @@ -2798,6 +2922,21 @@ __metadata: languageName: node linkType: hard +"@lumino/commands@npm:^1.19.0, @lumino/commands@npm:^1.21.1": + version: 1.21.1 + resolution: "@lumino/commands@npm:1.21.1" + dependencies: + "@lumino/algorithm": ^1.9.2 + "@lumino/coreutils": ^1.12.1 + "@lumino/disposable": ^1.10.4 + "@lumino/domutils": ^1.8.2 + "@lumino/keyboard": ^1.8.2 + "@lumino/signaling": ^1.11.1 + "@lumino/virtualdom": ^1.14.3 + checksum: 1e2ee7ce14b7241aee829df76f2bee6c046a82c2c137c6bb58049142c52a67f8ae74168fdcc4027b0d5a1c9f2ffa8b8f5231ef89f6f0ea8dcc4cab8d475e1ad4 + languageName: node + linkType: hard + "@lumino/commands@npm:^2.3.0": version: 2.3.0 resolution: "@lumino/commands@npm:2.3.0" @@ -2820,6 +2959,15 @@ __metadata: languageName: node linkType: hard +"@lumino/coreutils@npm:^1.11.0, @lumino/coreutils@npm:^1.12.1, @lumino/coreutils@npm:^1.2.0": + version: 1.12.1 + resolution: "@lumino/coreutils@npm:1.12.1" + peerDependencies: + crypto: 1.0.1 + checksum: 55f1b87997f8dd0af28ff23c2d4b3aa252e515b9d3bc91b350a5c6c8526ceae61b14b55dc0d8d01691c69d42974b3d559f2b49bc7ced0f474b8f5dc52b3e83ed + languageName: node + linkType: hard + "@lumino/disposable@npm:^1.10.0 || ^2.0.0, @lumino/disposable@npm:^1.10.1 || ^2.1, @lumino/disposable@npm:^2.1.2": version: 2.1.2 resolution: "@lumino/disposable@npm:2.1.2" @@ -2829,7 +2977,17 @@ __metadata: languageName: node linkType: hard -"@lumino/domutils@npm:^1.8.1 || ^2.1": +"@lumino/disposable@npm:^1.10.0, @lumino/disposable@npm:^1.10.4": + version: 1.10.4 + resolution: "@lumino/disposable@npm:1.10.4" + dependencies: + "@lumino/algorithm": ^1.9.2 + "@lumino/signaling": ^1.11.1 + checksum: b53e259830f1d3231455548e6b95c9ae0f4b91e1b501980a1d0bb9708322bf5469b5cbb4e5005653d6f33b549d4bb7e58ce02226477876f51c124ea755152a33 + languageName: node + linkType: hard + +"@lumino/domutils@npm:^1.1.0, @lumino/domutils@npm:^1.8.1 || ^2.1, @lumino/domutils@npm:^1.8.2": version: 1.8.2 resolution: "@lumino/domutils@npm:1.8.2" checksum: 196f25316a17cd8df8f11dbe17f10cbd96e5ce166ea97aab6402307dc554382423d860859bb5d05226f05909748b781fb281bb9220690fe1f3ddc716072c2ed5 @@ -2843,6 +3001,16 @@ __metadata: languageName: node linkType: hard +"@lumino/dragdrop@npm:^1.14.5": + version: 1.14.5 + resolution: "@lumino/dragdrop@npm:1.14.5" + dependencies: + "@lumino/coreutils": ^1.12.1 + "@lumino/disposable": ^1.10.4 + checksum: c10031e9aa9ef7f3ab71a1b73f761b84291dda85a449e5f4d2d7c462277759a947513eb7ee3e3d984f7cfc2730b1c96d0706124802492f9adbd7be00d13137ee + languageName: node + linkType: hard + "@lumino/dragdrop@npm:^2.1.4": version: 2.1.4 resolution: "@lumino/dragdrop@npm:2.1.4" @@ -2853,6 +3021,13 @@ __metadata: languageName: node linkType: hard +"@lumino/keyboard@npm:^1.8.2": + version: 1.8.2 + resolution: "@lumino/keyboard@npm:1.8.2" + checksum: 30f8ced53ca0aa466dba33be3c9379a2a6abcf1c52485073d9f9d9bc119eb3327a7343fad764c2d63a8a30ae05c0047098c40ec605e60af215356f3edb9ab4a9 + languageName: node + linkType: hard + "@lumino/keyboard@npm:^2.0.1": version: 2.0.1 resolution: "@lumino/keyboard@npm:2.0.1" @@ -2860,7 +3035,7 @@ __metadata: languageName: node linkType: hard -"@lumino/messaging@npm:^1.10.1 || ^2.1": +"@lumino/messaging@npm:^1.10.0, @lumino/messaging@npm:^1.10.1 || ^2.1, @lumino/messaging@npm:^1.10.3, @lumino/messaging@npm:^1.2.1": version: 1.10.3 resolution: "@lumino/messaging@npm:1.10.3" dependencies: @@ -2880,6 +3055,17 @@ __metadata: languageName: node linkType: hard +"@lumino/polling@npm:^1.9.0": + version: 1.11.4 + resolution: "@lumino/polling@npm:1.11.4" + dependencies: + "@lumino/coreutils": ^1.12.1 + "@lumino/disposable": ^1.10.4 + "@lumino/signaling": ^1.11.1 + checksum: d4625da7bf5399f6bffed29251daaeb4bf14a0733ad77ad1573c9893973480961be445d8700a5d004102d14ab5a2cf4b79244b1fe74680d060167e55db211c04 + languageName: node + linkType: hard + "@lumino/polling@npm:^2.1.2": version: 2.1.2 resolution: "@lumino/polling@npm:2.1.2" @@ -2891,6 +3077,13 @@ __metadata: languageName: node linkType: hard +"@lumino/properties@npm:^1.8.0, @lumino/properties@npm:^1.8.2": + version: 1.8.2 + resolution: "@lumino/properties@npm:1.8.2" + checksum: 9a53709fe58d3abbc99062f0c0fda4d5f64a4c7dca509251f0f89cdcaf881fdf6172ee852dbfe70594ee34bb97255acca771a722d62e7e2150ba8cf6f7e7d15c + languageName: node + linkType: hard + "@lumino/properties@npm:^2.0.1": version: 2.0.1 resolution: "@lumino/properties@npm:2.0.1" @@ -2908,6 +3101,25 @@ __metadata: languageName: node linkType: hard +"@lumino/signaling@npm:^1.10.0, @lumino/signaling@npm:^1.11.1, @lumino/signaling@npm:^1.2.0": + version: 1.11.1 + resolution: "@lumino/signaling@npm:1.11.1" + dependencies: + "@lumino/algorithm": ^1.9.2 + "@lumino/properties": ^1.8.2 + checksum: 3d822be705d9ba8adc46ec405a4422cd4f76ed774f94da5386a511f01df4325c3c8bfa288c9c812184c94cfd0c3ef7b1121dcc9c9489750ad6cfaa7ffb2a3a67 + languageName: node + linkType: hard + +"@lumino/virtualdom@npm:^1.14.3": + version: 1.14.3 + resolution: "@lumino/virtualdom@npm:1.14.3" + dependencies: + "@lumino/algorithm": ^1.9.2 + checksum: dd6acc5402eb7961ab05f5ce9afaebce4258eb92111f4d97b58ac87a6453686376d2b7d0a2041a54eef6e78091e36a430c74834c97b862fba31fa82ef43c72cb + languageName: node + linkType: hard + "@lumino/virtualdom@npm:^2.0.1": version: 2.0.1 resolution: "@lumino/virtualdom@npm:2.0.1" @@ -2917,6 +3129,25 @@ __metadata: languageName: node linkType: hard +"@lumino/widgets@npm:^1.3.0": + version: 1.37.2 + resolution: "@lumino/widgets@npm:1.37.2" + dependencies: + "@lumino/algorithm": ^1.9.2 + "@lumino/commands": ^1.21.1 + "@lumino/coreutils": ^1.12.1 + "@lumino/disposable": ^1.10.4 + "@lumino/domutils": ^1.8.2 + "@lumino/dragdrop": ^1.14.5 + "@lumino/keyboard": ^1.8.2 + "@lumino/messaging": ^1.10.3 + "@lumino/properties": ^1.8.2 + "@lumino/signaling": ^1.11.1 + "@lumino/virtualdom": ^1.14.3 + checksum: 3193f8cca4bad2c9d59031515b7b81b8a3655088f2b8c4f69f575116140d45c5caed935da0ed3fab9dc5ce96fde037bfa5fef0c129921955b3fb73cf725d1b06 + languageName: node + linkType: hard + "@lumino/widgets@npm:^1.30.0 || ^2.1, @lumino/widgets@npm:^1.37.2 || ^2.3.2, @lumino/widgets@npm:^2.3.2": version: 2.3.2 resolution: "@lumino/widgets@npm:2.3.2" @@ -3587,6 +3818,16 @@ __metadata: languageName: node linkType: hard +"@types/backbone@npm:^1.4.1": + version: 1.4.19 + resolution: "@types/backbone@npm:1.4.19" + dependencies: + "@types/jquery": "*" + "@types/underscore": "*" + checksum: fdd3452c9ccba44e54eeeeeab408421ae95e0303a971a45b908f33f6b1d33721fe559e38103a40103d3767c3334b10ce6f3a85659cd19cd30f0f4f30e5f5794f + languageName: node + linkType: hard + "@types/base64-js@npm:^1.2.5": version: 1.3.2 resolution: "@types/base64-js@npm:1.3.2" @@ -4832,7 +5073,7 @@ __metadata: languageName: node linkType: hard -"ajv@npm:^6.12.4, ajv@npm:^6.12.5": +"ajv@npm:^6.12.3, ajv@npm:^6.12.4, ajv@npm:^6.12.5": version: 6.12.6 resolution: "ajv@npm:6.12.6" dependencies: @@ -5299,6 +5540,15 @@ __metadata: languageName: node linkType: hard +"backbone@npm:1.2.3": + version: 1.2.3 + resolution: "backbone@npm:1.2.3" + dependencies: + underscore: ">=1.7.0" + checksum: 7e460e9e951bcba0907334d41ccc4bd84b5d17658e72fc61f4c7e1057c238e82f97d3545582cfa0501cb824ee2d44f78a45cd18f735d869e6b71430a0c183073 + languageName: node + linkType: hard + "backbone@npm:1.4.0": version: 1.4.0 resolution: "backbone@npm:1.4.0" @@ -6624,6 +6874,13 @@ __metadata: languageName: node linkType: hard +"d3-format@npm:^1.3.0": + version: 1.4.5 + resolution: "d3-format@npm:1.4.5" + checksum: 1b8b2c0bca182173bccd290a43e8b635a83fc8cfe52ec878c7bdabb997d47daac11f2b175cebbe73f807f782ad655f542bdfe18180ca5eb3498a3a82da1e06ab + languageName: node + linkType: hard + "d3-format@npm:^3.0.1": version: 3.1.0 resolution: "d3-format@npm:3.1.0" @@ -9809,7 +10066,16 @@ __metadata: languageName: node linkType: hard -"jquery@npm:^3.1.1": +"jquery-ui@npm:^1.12.1": + version: 1.13.3 + resolution: "jquery-ui@npm:1.13.3" + dependencies: + jquery: ">=1.8.0 <4.0.0" + checksum: e0df58215db4acc4ae160f637cb18d9abc4d8315b3187308f8ad8d1ef101c71ae6bcc4103a3b8e8767b347bd42f453706a13993af183c8d0c1d4b99e2c820245 + languageName: node + linkType: hard + +"jquery@npm:>=1.8.0 <4.0.0, jquery@npm:^3.1.1": version: 3.7.1 resolution: "jquery@npm:3.7.1" checksum: 4370b8139d6ae82867eb6f7f21d1edccf1d1bdf41c0840920ea80d366c2cd5dbe1ceebb110ee9772aa839b04400faa1572c5c560b507c688ed7b61cea26c0e27 @@ -9986,7 +10252,7 @@ __metadata: languageName: node linkType: hard -"json5@npm:^2.1.2, json5@npm:^2.2.2, json5@npm:^2.2.3": +"json5@npm:^2.1.1, json5@npm:^2.1.2, json5@npm:^2.2.2, json5@npm:^2.2.3": version: 2.2.3 resolution: "json5@npm:2.2.3" bin: @@ -11372,6 +11638,13 @@ __metadata: languageName: node linkType: hard +"moment@npm:^2.24.0": + version: 2.30.1 + resolution: "moment@npm:2.30.1" + checksum: 859236bab1e88c3e5802afcf797fc801acdbd0ee509d34ea3df6eea21eb6bcc2abd4ae4e4e64aa7c986aa6cba563c6e62806218e6412a765010712e5fa121ba6 + languageName: node + linkType: hard + "ms@npm:2.0.0": version: 2.0.0 resolution: "ms@npm:2.0.0" @@ -11534,7 +11807,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": +"node-fetch@npm:^2.6.0, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": version: 2.7.0 resolution: "node-fetch@npm:2.7.0" dependencies: @@ -15681,6 +15954,13 @@ __metadata: languageName: node linkType: hard +"underscore@npm:>=1.7.0, underscore@npm:^1.8.3": + version: 1.13.7 + resolution: "underscore@npm:1.13.7" + checksum: 174b011af29e4fbe2c70eb2baa8bfab0d0336cf2f5654f364484967bc6264a86224d0134b9176e4235c8cceae00d11839f0fd4824268de04b11c78aca1241684 + languageName: node + linkType: hard + "underscore@npm:>=1.8.3": version: 1.13.6 resolution: "underscore@npm:1.13.6" @@ -15836,7 +16116,7 @@ __metadata: languageName: node linkType: hard -"url-parse@npm:^1.5.3, url-parse@npm:~1.5.4": +"url-parse@npm:^1.5.3, url-parse@npm:~1.5.1, url-parse@npm:~1.5.4": version: 1.5.10 resolution: "url-parse@npm:1.5.10" dependencies: @@ -16585,6 +16865,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:^7.4.6": + version: 7.5.10 + resolution: "ws@npm:7.5.10" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ^5.0.2 + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: f9bb062abf54cc8f02d94ca86dcd349c3945d63851f5d07a3a61c2fcb755b15a88e943a63cf580cbdb5b74436d67ef6b67f745b8f7c0814e411379138e1863cb + languageName: node + linkType: hard + "ws@npm:^8.11.0": version: 8.17.0 resolution: "ws@npm:8.17.0" From 1fd50702a11ae05d4076ab4b7c2ff743b57dfd77 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 11:51:18 +0200 Subject: [PATCH 2/7] Linter --- docs/requirements.txt | 4 ++-- packages/html-manager/scripts/concat-amd-build.js | 9 ++++++++- packages/html-manager/src/utils.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 922711b316..4c431f62ba 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,8 +6,8 @@ ipyleaflet jupyter-client jupyter-packaging jupyterlab >=4 -jupyterlite-core >=0.3.0<0.4.0 -jupyterlite-pyodide-kernel >=0.3.0<0.4.0 +jupyterlite-core >=0.3.0,<0.4.0 +jupyterlite-pyodide-kernel >=0.3.0,<0.4.0 matplotlib myst-nb >=0.17,<0.18 numpy diff --git a/packages/html-manager/scripts/concat-amd-build.js b/packages/html-manager/scripts/concat-amd-build.js index 8183594543..71338cdce5 100755 --- a/packages/html-manager/scripts/concat-amd-build.js +++ b/packages/html-manager/scripts/concat-amd-build.js @@ -4,7 +4,14 @@ var fs = require('fs'); // Make a script file that defines all of the relevant AMD modules -var files = ['base.js', 'controls.js', 'base7.js', 'controls7.js', 'index.js', 'libembed-amd.js']; +var files = [ + 'base.js', + 'controls.js', + 'base7.js', + 'controls7.js', + 'index.js', + 'libembed-amd.js', +]; var output = files .map((f) => { return fs.readFileSync('./dist/amd/' + f).toString(); diff --git a/packages/html-manager/src/utils.ts b/packages/html-manager/src/utils.ts index a454c401e7..b52e12c6de 100644 --- a/packages/html-manager/src/utils.ts +++ b/packages/html-manager/src/utils.ts @@ -12,4 +12,4 @@ export function requirePromise(pkg: string | string[]): Promise { require(pkg, resolve, reject); } }); -}; +} From 1fd7d52a719bf2346a478ccf92893024f37761dc Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 12:00:58 +0200 Subject: [PATCH 3/7] Fix integrity test --- scripts/package-integrity.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/package-integrity.js b/scripts/package-integrity.js index d516132992..1edb3c2cf1 100644 --- a/scripts/package-integrity.js +++ b/scripts/package-integrity.js @@ -108,7 +108,11 @@ function validate(dname) { problems.push('Bad core version: ' + name + ' should be ' + desired); } } - if (names.indexOf(name) === -1) { + if ( + names.indexOf(name) === -1 && + !name.startsWith('@jupyter-widgets/base') && + !name.startsWith('@jupyter-widgets/controls') + ) { problems.push('Unused package: ' + name); } }); From c6d005168f2f05235d57c1feb20d9f2611e6f5b0 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 12:15:54 +0200 Subject: [PATCH 4/7] Add test --- packages/html-manager/test/src/output_test.ts | 84 ++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/packages/html-manager/test/src/output_test.ts b/packages/html-manager/test/src/output_test.ts index f5ac1d7707..712c58f2ab 100644 --- a/packages/html-manager/test/src/output_test.ts +++ b/packages/html-manager/test/src/output_test.ts @@ -63,6 +63,84 @@ describe('Output widget', function () { expect(elt.querySelectorAll('table').length).to.equal(1); }); + + it('renders widgets ipywidgets 7', async function () { + const modelState = { + _view_module: '@jupyter-widgets/output', + outputs: [ + { + output_type: 'display_data', + data: { + 'application/vnd.jupyter.widget-view+json': { + model_id: 'adffc4580a0944f6929c381463b0059b', + version_minor: 0, + version_major: 2, + }, + 'text/plain': 'A Jupyter Widget', + }, + metadata: {}, + }, + ], + }; + + const elt = document.createElement('div'); + elt.className = 'widget-subarea'; + document.body.appendChild(elt); + const manager = new HTMLManager(); + + // We need to seed the manager with the state of the widgets + const managerState = { + adffc4580a0944f6929c381463b0059b: { + model_name: 'IntSliderModel', + model_module: '@jupyter-widgets/controls', + model_module_version: '1.5.0', + state: { + style: 'IPY_MODEL_3b8780f457254737a83be48bc32b0613', + _view_module: '@jupyter-widgets/controls', + layout: 'IPY_MODEL_33cb011834fd4c9d9af512e5e98c9904', + value: 45, + _model_module: '@jupyter-widgets/controls', + }, + }, + '3b8780f457254737a83be48bc32b0613': { + model_name: 'SliderStyleModel', + model_module: '@jupyter-widgets/controls', + model_module_version: '1.5.0', + state: { + description_width: '', + _model_module: '@jupyter-widgets/controls', + }, + }, + '33cb011834fd4c9d9af512e5e98c9904': { + model_name: 'LayoutModel', + model_module: '@jupyter-widgets/base', + model_module_version: '1.2.0', + state: {}, + }, + }; + await manager.set_state({ + state: managerState, + version_major: 2, + version_minor: 0, + }); + const modelId = 'u-u-i-d'; + const modelCreate: base.IModelOptions = { + model_name: 'OutputModel', + model_id: modelId, + model_module: '@jupyter-widgets/output', + model_module_version: '*', + }; + const model = await manager.new_model(modelCreate, modelState); + await manager.display_view(manager.create_view(model), elt); + + // Give the widget time to render + await new Promise((resolve) => { + setTimeout(resolve, 20); + }); + + expect(elt.querySelectorAll('.slider').length).to.equal(1); + }); + it('renders widgets', async function () { const modelState = { _view_module: '@jupyter-widgets/output', @@ -92,7 +170,7 @@ describe('Output widget', function () { adffc4580a0944f6929c381463b0059b: { model_name: 'IntSliderModel', model_module: '@jupyter-widgets/controls', - model_module_version: '1.0.0', + model_module_version: '2.0.0', state: { style: 'IPY_MODEL_3b8780f457254737a83be48bc32b0613', _view_module: '@jupyter-widgets/controls', @@ -104,7 +182,7 @@ describe('Output widget', function () { '3b8780f457254737a83be48bc32b0613': { model_name: 'SliderStyleModel', model_module: '@jupyter-widgets/controls', - model_module_version: '1.0.0', + model_module_version: '2.0.0', state: { description_width: '', _model_module: '@jupyter-widgets/controls', @@ -113,7 +191,7 @@ describe('Output widget', function () { '33cb011834fd4c9d9af512e5e98c9904': { model_name: 'LayoutModel', model_module: '@jupyter-widgets/base', - model_module_version: '1.0.0', + model_module_version: '2.0.0', state: {}, }, }; From 45b43399a5f06feae602198170a3d765dcff0fea Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 15:17:38 +0200 Subject: [PATCH 5/7] Fix the tests --- packages/html-manager/src/htmlmanager.ts | 10 +++++----- packages/html-manager/src/output_renderers.ts | 2 +- packages/html-manager/test/src/output_test.ts | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/html-manager/src/htmlmanager.ts b/packages/html-manager/src/htmlmanager.ts index 9808bcaa11..9e194532e5 100644 --- a/packages/html-manager/src/htmlmanager.ts +++ b/packages/html-manager/src/htmlmanager.ts @@ -15,7 +15,6 @@ import { import { WidgetRenderer, WIDGET_MIMETYPE } from './output_renderers'; import { WidgetModel, WidgetView, DOMWidgetView } from '@jupyter-widgets/base'; -import { requirePromise } from './utils'; export class HTMLManager extends ManagerBase { constructor(options?: { @@ -118,10 +117,10 @@ export class HTMLManager extends ManagerBase { if (best === '1.2.0') { // ipywidgets 7 model - requirePromise(['@jupyter-widgets/base7']).then(resolve); + resolve(require('@jupyter-widgets/base7')); } else { // ipywidgets 8 model - requirePromise(['@jupyter-widgets/base']).then(resolve); + resolve(require('@jupyter-widgets/base')); } } else if (moduleName === '@jupyter-widgets/controls') { const best = maxSatisfying(['1.5.0', '2.0.0'], moduleVersion); @@ -138,7 +137,7 @@ export class HTMLManager extends ManagerBase { ) { require('@jupyter-widgets/controls7/css/labvariables.css'); } - requirePromise(['@jupyter-widgets/controls7']).then(resolve); + resolve(require('@jupyter-widgets/controls7')); } else { // ipywidgets 8 controls JS and CSS require('@jupyter-widgets/controls/css/widgets-base.css'); @@ -151,7 +150,8 @@ export class HTMLManager extends ManagerBase { ) { require('@jupyter-widgets/controls/css/labvariables.css'); } - requirePromise(['@jupyter-widgets/controls']).then(resolve); + + resolve(require('@jupyter-widgets/controls')); } } else if (moduleName === '@jupyter-widgets/output') { resolve(outputWidgets); diff --git a/packages/html-manager/src/output_renderers.ts b/packages/html-manager/src/output_renderers.ts index c343aa1201..24155086ec 100644 --- a/packages/html-manager/src/output_renderers.ts +++ b/packages/html-manager/src/output_renderers.ts @@ -27,7 +27,7 @@ export class WidgetRenderer extends Widget implements IRenderMime.IRenderer { try { const wModel = await this._manager.get_model(source.model_id); const wView = await this._manager.create_view(wModel); - Widget.attach(wView.luminoWidget, this.node); + Widget.attach(wView.luminoWidget || wView.pWidget, this.node); } catch (err) { console.log('Error displaying widget'); console.log(err); diff --git a/packages/html-manager/test/src/output_test.ts b/packages/html-manager/test/src/output_test.ts index 712c58f2ab..ad1298e213 100644 --- a/packages/html-manager/test/src/output_test.ts +++ b/packages/html-manager/test/src/output_test.ts @@ -63,7 +63,6 @@ describe('Output widget', function () { expect(elt.querySelectorAll('table').length).to.equal(1); }); - it('renders widgets ipywidgets 7', async function () { const modelState = { _view_module: '@jupyter-widgets/output', From 5aadeb69a4504bf9213a8f81fe750975784c7274 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 15:27:07 +0200 Subject: [PATCH 6/7] Apply same special case for jupyter-widgets packages as in the lab manager --- packages/html-manager/src/htmlmanager.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/html-manager/src/htmlmanager.ts b/packages/html-manager/src/htmlmanager.ts index 9e194532e5..731c1e0c61 100644 --- a/packages/html-manager/src/htmlmanager.ts +++ b/packages/html-manager/src/htmlmanager.ts @@ -112,6 +112,13 @@ export class HTMLManager extends ManagerBase { moduleVersion: string ): Promise { return new Promise((resolve, reject) => { + if ( + moduleName === '@jupyter-widgets/base' || + moduleName === '@jupyter-widgets/controls' + ) { + moduleVersion = `^${moduleVersion}`; + } + if (moduleName === '@jupyter-widgets/base') { const best = maxSatisfying(['1.2.0', '2.0.0'], moduleVersion); From c1f7e2a2a88fd58e3670b1be7c9f333620c5f713 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 30 Jul 2024 16:23:07 +0200 Subject: [PATCH 7/7] Reduce PR diff --- packages/html-manager/src/libembed-amd.ts | 17 ++++++++++++++++- packages/html-manager/src/utils.ts | 15 --------------- 2 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 packages/html-manager/src/utils.ts diff --git a/packages/html-manager/src/libembed-amd.ts b/packages/html-manager/src/libembed-amd.ts index 76c8728ddf..1a3ed21742 100644 --- a/packages/html-manager/src/libembed-amd.ts +++ b/packages/html-manager/src/libembed-amd.ts @@ -2,7 +2,22 @@ // Distributed under the terms of the Modified BSD License. import * as libembed from './libembed'; -import { requirePromise } from './utils'; + +/** + * Load a package using requirejs and return a promise + * + * @param pkg Package name or names to load + */ +const requirePromise = function (pkg: string | string[]): Promise { + return new Promise((resolve, reject) => { + const require = (window as any).requirejs; + if (require === undefined) { + reject('Requirejs is needed, please ensure it is loaded on the page.'); + } else { + require(pkg, resolve, reject); + } + }); +}; let cdn = 'https://cdn.jsdelivr.net/npm/'; let onlyCDN = false; diff --git a/packages/html-manager/src/utils.ts b/packages/html-manager/src/utils.ts deleted file mode 100644 index b52e12c6de..0000000000 --- a/packages/html-manager/src/utils.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Load a package using requirejs and return a promise - * - * @param pkg Package name or names to load - */ -export function requirePromise(pkg: string | string[]): Promise { - return new Promise((resolve, reject) => { - const require = (window as any).requirejs; - if (require === undefined) { - reject('Requirejs is needed, please ensure it is loaded on the page.'); - } else { - require(pkg, resolve, reject); - } - }); -}