Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to TypeScript 4.3 #3162

Merged
merged 14 commits into from
Jun 11, 2021
17 changes: 13 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
"prettier"
],
"rules": {
"@typescript-eslint/interface-name-prefix": [
"@typescript-eslint/naming-convention": [
"error",
{ "prefixWithI": "always" }
{
"selector": "interface",
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": true
}
}
],
"@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-namespace": "off"
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/camelcase": "off"
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
Expand Down
1 change: 1 addition & 0 deletions examples/web1/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<head>
<meta charset="utf-8"/>
<script src="./built/index.built.js"></script>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion examples/web1/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WidgetManager extends ManagerBase {
display_view(view) {
var that = this;
return Promise.resolve(view).then(view => {
LuminoWidget.attach(view.pWidget, that.el);
LuminoWidget.attach(view.luminoWidget, that.el);
return view;
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web2/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WidgetManager extends ManagerBase {
display_view(view) {
var that = this;
return Promise.resolve(view).then(function(view) {
LuminoWidget.attach(view.pWidget, that.el);
LuminoWidget.attach(view.luminoWidget, that.el);
return view;
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"postcss-loader": "^3.0.0",
"rimraf": "^2.6.1",
"style-loader": "^1.1.2",
"typescript": "~3.7.4",
"typescript": "~4.3.2",
"url-loader": "^3.0.0",
"webpack": "^4.41.5"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
const model = await manager.get_model(widgetData.model_id);
if (model !== undefined) {
const view = await manager.create_view(model);
luminoWidget.Widget.attach(view.pWidget, widgetarea);
luminoWidget.Widget.attach(view.luminoWidget, widgetarea);
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions jupyterlab_widgets/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
tsconfigRootDir: __dirname
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/interface-name-prefix': [
'@typescript-eslint/naming-convention': [
'error',
{ prefixWithI: 'always' }
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: true,
},
},
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
{ avoidEscape: true, allowTemplateLiterals: false },
],
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
}
'prefer-arrow-callback': 'error',
},
};
15 changes: 8 additions & 7 deletions jupyterlab_widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "jupyter labextension build --development True .",
"build:lib": "tsc",
"build:prod": "jlpm run build:lib && jlpm run build:labextension",
"clean": "jlpm run clean:lib",
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
"clean:labextension": "rimraf jupyterlab_widgets/labextension",
Expand Down Expand Up @@ -78,15 +79,15 @@
"@jupyterlab/builder": "^3.0.0",
"@jupyterlab/cells": "^3.0.0",
"@types/semver": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"typescript": "~3.9.0"
"typescript": "~4.3.2"
},
"jupyterlab": {
"extension": true,
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_widgets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export { registerWidgetManager } from './plugin';
export {
KernelWidgetManager,
LabWidgetManager,
WidgetManager
WidgetManager,
} from './manager';

export { WidgetRenderer } from './renderer';
Expand Down
33 changes: 17 additions & 16 deletions jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
WidgetModel,
WidgetView,
put_buffers,
ICallbacks
ICallbacks,
} from '@jupyter-widgets/base';

import {
ManagerBase,
serialize_state,
IStateOptions
IStateOptions,
} from '@jupyter-widgets/base-manager';

import { IDisposable } from '@lumino/disposable';
Expand Down Expand Up @@ -51,7 +51,8 @@ export const WIDGET_STATE_MIMETYPE =
/**
* A widget manager that returns Lumino widgets.
*/
export abstract class LabWidgetManager extends ManagerBase
export abstract class LabWidgetManager
extends ManagerBase
implements IDisposable {
constructor(rendermime: IRenderMimeRegistry) {
super();
Expand All @@ -66,8 +67,8 @@ export abstract class LabWidgetManager extends ManagerBase
iopub: {
output: (msg: KernelMessage.IIOPubMessage): void => {
this._onUnhandledIOPubMessage.emit(msg);
}
}
},
},
};
}

Expand All @@ -76,7 +77,7 @@ export abstract class LabWidgetManager extends ManagerBase
*/
protected _handleKernelChanged({
oldValue,
newValue
newValue,
}: Session.ISessionConnection.IKernelChangedArgs): void {
if (oldValue) {
oldValue.removeCommTarget(this.comm_target_name, this._handleCommOpen);
Expand Down Expand Up @@ -108,7 +109,7 @@ export abstract class LabWidgetManager extends ManagerBase

// For each comm id that we do not know about, create the comm, and request the state.
const widgets_info = await Promise.all(
Object.keys(comm_ids).map(async comm_id => {
Object.keys(comm_ids).map(async (comm_id) => {
try {
await this.get_model(comm_id);
// If we successfully get the model, do no more.
Expand Down Expand Up @@ -140,7 +141,7 @@ export abstract class LabWidgetManager extends ManagerBase
});
msg_id = comm.send(
{
method: 'request_state'
method: 'request_state',
},
this.callbacks(undefined)
);
Expand All @@ -156,7 +157,7 @@ export abstract class LabWidgetManager extends ManagerBase
// asynchronously, so promises to every widget reference should be available
// by the time they are used.
await Promise.all(
widgets_info.map(async widget_info => {
widgets_info.map(async (widget_info) => {
if (!widget_info) {
return;
}
Expand All @@ -166,7 +167,7 @@ export abstract class LabWidgetManager extends ManagerBase
model_name: content.data.state._model_name,
model_module: content.data.state._model_module,
model_module_version: content.data.state._model_module_version,
comm: widget_info.comm
comm: widget_info.comm,
},
content.data.state
);
Expand Down Expand Up @@ -204,7 +205,7 @@ export abstract class LabWidgetManager extends ManagerBase
throw new Error('No current kernel');
}
const reply = await kernel.requestCommInfo({
target_name: this.comm_target_name
target_name: this.comm_target_name,
});
if (reply.content.status === 'ok') {
return (reply.content as any).comms;
Expand Down Expand Up @@ -340,7 +341,7 @@ export abstract class LabWidgetManager extends ManagerBase
super.register_model(model_id, modelPromise);

// Update the synchronous model map
modelPromise.then(model => {
modelPromise.then((model) => {
this._modelsSync.set(model_id, model);
model.once('comm:close', () => {
this._modelsSync.delete(model_id);
Expand Down Expand Up @@ -424,7 +425,7 @@ export class KernelWidgetManager extends LabWidgetManager {
this._handleKernelChanged({
name: 'kernel',
oldValue: null,
newValue: kernel
newValue: kernel,
});
this.restoreWidgets();
}
Expand Down Expand Up @@ -507,7 +508,7 @@ export class WidgetManager extends LabWidgetManager {
this._handleKernelChanged({
name: 'kernel',
oldValue: null,
newValue: context.sessionContext.session?.kernel
newValue: context.sessionContext.session?.kernel,
});
}

Expand All @@ -527,7 +528,7 @@ export class WidgetManager extends LabWidgetManager {
private _saveState(): void {
const state = this.get_state_sync({ drop_defaults: true });
this._context.model.metadata.set('widgets', {
'application/vnd.jupyter.widget-state+json': state
'application/vnd.jupyter.widget-state+json': state,
});
}

Expand All @@ -539,7 +540,7 @@ export class WidgetManager extends LabWidgetManager {
// We only want to restore widgets from the kernel, not ones saved in the notebook.
this.restoreWidgets(this._context!.model, {
loadKernel: true,
loadNotebook: false
loadNotebook: false,
});
}
}
Expand Down
24 changes: 12 additions & 12 deletions jupyterlab_widgets/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class OutputModel extends outputBase.OutputModel {
* Register a new kernel
*/
_handleKernelChanged({
oldValue
oldValue,
}: Session.ISessionConnection.IKernelChangedArgs): void {
const msgId = this.get('msg_id');
if (msgId && oldValue) {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class OutputModel extends outputBase.OutputModel {
export class JupyterLuminoPanelWidget extends Panel {
constructor(options: JupyterLuminoWidget.IOptions & Panel.IOptions) {
const view = options.view;
delete options.view;
delete (options as any).view;
super(options);
this._view = view;
}
Expand Down Expand Up @@ -162,18 +162,18 @@ export class JupyterLuminoPanelWidget extends Panel {

export class OutputView extends outputBase.OutputView {
_createElement(tagName: string): HTMLElement {
this.pWidget = new JupyterLuminoPanelWidget({ view: this });
return this.pWidget.node;
this.luminoWidget = new JupyterLuminoPanelWidget({ view: this });
return this.luminoWidget.node;
}

_setElement(el: HTMLElement): void {
if (this.el || el !== this.pWidget.node) {
if (this.el || el !== this.luminoWidget.node) {
// Boxes don't allow setting the element beyond the initial creation.
throw new Error('Cannot reset the DOM element.');
}

this.el = this.pWidget.node;
this.$el = $(this.pWidget.node);
this.el = this.luminoWidget.node;
this.$el = $(this.luminoWidget.node);
}

/**
Expand All @@ -184,16 +184,16 @@ export class OutputView extends outputBase.OutputView {
this._outputView = new OutputArea({
rendermime: this.model.widget_manager.rendermime,
contentFactory: OutputArea.defaultContentFactory,
model: this.model.outputs
model: this.model.outputs,
});
// TODO: why is this a readonly property now?
// this._outputView.model = this.model.outputs;
// TODO: why is this on the model now?
// this._outputView.trusted = true;
this.pWidget.insertWidget(0, this._outputView);
this.luminoWidget.insertWidget(0, this._outputView);

this.pWidget.addClass('jupyter-widgets');
this.pWidget.addClass('widget-output');
this.luminoWidget.addClass('jupyter-widgets');
this.luminoWidget.addClass('widget-output');
this.update(); // Set defaults.
}

Expand All @@ -204,5 +204,5 @@ export class OutputView extends outputBase.OutputView {

model: OutputModel;
_outputView: OutputArea;
pWidget: Panel;
luminoWidget: Panel;
}
Loading