Skip to content

Commit 5ed5b23

Browse files
fix: support both lumino and phosphorjs
Some versions of colab only support the lumino naming scheme. In case neither is found, we fall back to DOM manipulation.
1 parent a1bf722 commit 5ed5b23

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

js/src/VueRenderer.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint camelcase: ['error', {allow: ['v_model']}] */
2-
import { JupyterPhosphorWidget } from '@jupyter-widgets/base';
2+
import * as base from '@jupyter-widgets/base';
33
import { vueTemplateRender } from './VueTemplateRenderer'; // eslint-disable-line import/no-cycle
44
import { VueModel } from './VueModel';
55
import { VueTemplateModel } from './VueTemplateModel';
66
import Vue from './VueWithCompiler';
77

8+
const JupyterPhosphorWidget = base.JupyterPhosphorWidget || base.JupyterLuminoWidget;
9+
810
export function createObjectForNestedModel(model, parentView) {
911
let currentView = null;
1012
let destroyed = false;
@@ -16,7 +18,13 @@ export function createObjectForNestedModel(model, parentView) {
1618
currentView = view;
1719
// since create view is async, the vue component might be destroyed before the view is created
1820
if(!destroyed) {
19-
JupyterPhosphorWidget.attach(view.pWidget, this.$el);
21+
if(JupyterPhosphorWidget && (view.pWidget || view.luminoWidget || view.lmWidget)) {
22+
JupyterPhosphorWidget.attach(view.pWidget || view.luminoWidget || view.lmWidget, this.$el);
23+
} else {
24+
console.error("Could not attach widget to DOM using Lumino or Phosphor. Fallback to normal DOM attach", JupyterPhosphorWidget, view.pWidget, view.luminoWidget, view.lmWidget);
25+
this.$el.appendChild(view.el);
26+
27+
}
2028
} else {
2129
currentView.remove();
2230
}
@@ -29,8 +37,9 @@ export function createObjectForNestedModel(model, parentView) {
2937
// In order to avoid an error in phosphor, we add the node to the body before removing it.
3038
// (current.remove triggers a phosphor detach)
3139
// To be sure we do not cause any flickering, we hide the node before moving it.
32-
currentView.pWidget.node.style.display = "none";
33-
document.body.appendChild(currentView.pWidget.node)
40+
const widget = currentView.pWidget || currentView.luminoWidget || currentView.lmWidget;
41+
widget.node.style.display = "none";
42+
document.body.appendChild(widget.node)
3443
currentView.remove();
3544
} else {
3645
destroyed = true;

0 commit comments

Comments
 (0)