Skip to content

Commit 7e96dd2

Browse files
committed
Split the JupyterLab extension into plugins that provide the widget manager and register widgets.
This paves the way to having separate extensions that load multiple versions of core widgets, so that ipywidgets 7.x and 8.x can be supported simultaneously, for example.
1 parent 88cec8b commit 7e96dd2

File tree

1 file changed

+76
-43
lines changed

1 file changed

+76
-43
lines changed

python/jupyterlab_widgets/src/plugin.ts

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function registerWidgetManager(
144144
/**
145145
* The widget manager provider.
146146
*/
147-
const plugin: JupyterFrontEndPlugin<base.IJupyterWidgetRegistry> = {
147+
export const managerPlugin: JupyterFrontEndPlugin<base.IJupyterWidgetRegistry> = {
148148
id: '@jupyter-widgets/jupyterlab-manager:plugin',
149149
requires: [IRenderMimeRegistry],
150150
optional: [
@@ -159,7 +159,6 @@ const plugin: JupyterFrontEndPlugin<base.IJupyterWidgetRegistry> = {
159159
autoStart: true,
160160
};
161161

162-
export default plugin;
163162

164163
function updateSettings(settings: ISettingRegistry.ISettings): void {
165164
SETTINGS.saveState = settings.get('saveState').composite as boolean;
@@ -277,47 +276,6 @@ function activateWidgetExtension(
277276
]);
278277
}
279278

280-
WIDGET_REGISTRY.push({
281-
name: '@jupyter-widgets/base',
282-
version: base.JUPYTER_WIDGETS_VERSION,
283-
exports: {
284-
WidgetModel: base.WidgetModel,
285-
WidgetView: base.WidgetView,
286-
DOMWidgetView: base.DOMWidgetView,
287-
DOMWidgetModel: base.DOMWidgetModel,
288-
LayoutModel: base.LayoutModel,
289-
LayoutView: base.LayoutView,
290-
StyleModel: base.StyleModel,
291-
StyleView: base.StyleView,
292-
ErrorWidgetView: base.ErrorWidgetView,
293-
},
294-
});
295-
296-
WIDGET_REGISTRY.push({
297-
name: '@jupyter-widgets/controls',
298-
version: JUPYTER_CONTROLS_VERSION,
299-
exports: () => {
300-
return new Promise((resolve, reject) => {
301-
(require as any).ensure(
302-
['@jupyter-widgets/controls'],
303-
(require: NodeRequire) => {
304-
// eslint-disable-next-line @typescript-eslint/no-var-requires
305-
resolve(require('@jupyter-widgets/controls'));
306-
},
307-
(err: any) => {
308-
reject(err);
309-
},
310-
'@jupyter-widgets/controls'
311-
);
312-
});
313-
},
314-
});
315-
316-
WIDGET_REGISTRY.push({
317-
name: '@jupyter-widgets/output',
318-
version: OUTPUT_WIDGET_VERSION,
319-
exports: { OutputModel, OutputView },
320-
});
321279

322280
return {
323281
registerWidget(data: base.IWidgetRegistryData): void {
@@ -326,6 +284,81 @@ function activateWidgetExtension(
326284
};
327285
}
328286

287+
288+
/**
289+
* The base widgets.
290+
*/
291+
export const baseWidgetsPlugin: JupyterFrontEndPlugin<void> = {
292+
id: `@jupyter-widgets/jupyterlab-manager:base-${base.JUPYTER_WIDGETS_VERSION}`,
293+
requires: [base.IJupyterWidgetRegistry],
294+
autoStart: true,
295+
activate: (app: JupyterFrontEnd, registry: base.IJupyterWidgetRegistry): void => {
296+
registry.registerWidget({
297+
name: '@jupyter-widgets/base',
298+
version: base.JUPYTER_WIDGETS_VERSION,
299+
exports: {
300+
WidgetModel: base.WidgetModel,
301+
WidgetView: base.WidgetView,
302+
DOMWidgetView: base.DOMWidgetView,
303+
DOMWidgetModel: base.DOMWidgetModel,
304+
LayoutModel: base.LayoutModel,
305+
LayoutView: base.LayoutView,
306+
StyleModel: base.StyleModel,
307+
StyleView: base.StyleView,
308+
ErrorWidgetView: base.ErrorWidgetView,
309+
},
310+
});
311+
}
312+
};
313+
314+
315+
/**
316+
* The control widgets.
317+
*/
318+
export const controlWidgetsPlugin: JupyterFrontEndPlugin<void> = {
319+
id: `@jupyter-widgets/jupyterlab-manager:controls-${JUPYTER_CONTROLS_VERSION}`,
320+
requires: [base.IJupyterWidgetRegistry],
321+
autoStart: true,
322+
activate: (app: JupyterFrontEnd, registry: base.IJupyterWidgetRegistry): void => {
323+
registry.registerWidget({
324+
name: '@jupyter-widgets/controls',
325+
version: JUPYTER_CONTROLS_VERSION,
326+
exports: () => {
327+
return new Promise((resolve, reject) => {
328+
(require as any).ensure(
329+
['@jupyter-widgets/controls'],
330+
(require: NodeRequire) => {
331+
// eslint-disable-next-line @typescript-eslint/no-var-requires
332+
resolve(require('@jupyter-widgets/controls'));
333+
},
334+
(err: any) => {
335+
reject(err);
336+
},
337+
'@jupyter-widgets/controls'
338+
);
339+
});
340+
}
341+
});
342+
}
343+
};
344+
345+
/**
346+
* The output widget.
347+
*/
348+
export const outputWidgetPlugin: JupyterFrontEndPlugin<void> = {
349+
id: `@jupyter-widgets/jupyterlab-manager:output-${OUTPUT_WIDGET_VERSION}`,
350+
requires: [base.IJupyterWidgetRegistry],
351+
autoStart: true,
352+
activate: (app: JupyterFrontEnd, registry: base.IJupyterWidgetRegistry): void => {
353+
registry.registerWidget({
354+
name: '@jupyter-widgets/output',
355+
version: OUTPUT_WIDGET_VERSION,
356+
exports: { OutputModel, OutputView }
357+
});
358+
}
359+
};
360+
361+
export default [managerPlugin, baseWidgetsPlugin, controlWidgetsPlugin, outputWidgetPlugin];
329362
namespace Private {
330363
/**
331364
* A private attached property for a widget manager.

0 commit comments

Comments
 (0)