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

Switch to using TypeScript #1159

Merged
merged 22 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ui-tests/.yarn/
ipyleaflet/nbextension/
ipyleaflet/labextension/
js/dist/
js/lib/

# OS X
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions js/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
lib
1 change: 1 addition & 0 deletions js/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
lib
File renamed without changes.
41 changes: 30 additions & 11 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@
"jupyterlab-extension",
"widgets"
],
"files": [
"css/",
"lib/"
],
"repository": {
"type": "git",
"url": "https://github.com/jupyter-widgets/ipyleaflet.git"
},
"license": "MIT",
"author": "Project Jupyter",
"main": "src/index.js",
"main": "lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "webpack && jupyter labextension build .",
"clean": "rimraf dist/ && rimraf ../ipyleaflet/labextension/ && rimraf ../ipyleaflet/nbextension",
"prepublish": "npm run clean && npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "run-p watch:src watch:labextension",
"watch:src": "webpack --watch",
"watch:labextension": "jupyter labextension watch .",
"lint": "eslint . --fix && prettier --write .",
"lint:check": "eslint . && prettier ."
"build": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension",
"build:lib": "tsc",
"build:nbextension": "webpack --no-devtool",
"build:labextension": "jupyter labextension build .",
"build:extensions": "yarn run build && yarn run build:labextension",
"clean": "yarn run clean:lib && yarn run clean:nbextension && yarn run clean:labextension",
"clean:lib": "rimraf lib",
"clean:nbextension": "rimraf ../ipyleaflet/nbextension/index.js",
"clean:labextension": "rimraf ../ipyleaflet/labextension",
"lint": "yarn prettier && yarn eslint",
"lint:check": "yarn prettier:check && yarn eslint",
"prettier": "yarn prettier:base --write --list-different",
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "yarn prettier:base --check",
"prepack": "yarn run build",
"watch:lib": "tsc -w",
"watch:nbextension": "webpack --watch"
},
"dependencies": {
"@jupyter-widgets/base": "^2 || ^3 || ^4 || ^5 || ^6",
Expand Down Expand Up @@ -52,6 +65,9 @@
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.8",
"@types/leaflet": "^1.9.8",
"@types/node": "^20.10.5",
"@types/webpack-env": "^1.18.4",
"css-loader": "^3.4.2",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -64,12 +80,15 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"rimraf": "^2.6.1",
"source-map-loader": "^4.0.1",
"style-loader": "^1.1.2",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5",
"webpack-cli": "^5.1.4"
},
"jupyterlab": {
"extension": "src/jupyterlab-plugin",
"extension": "lib/jupyterlab-plugin",
"outputDir": "../ipyleaflet/labextension",
"webpackConfig": "webpack.lab.config.js",
"sharedPackages": {
Expand Down
11 changes: 6 additions & 5 deletions js/src/Map.js → js/src/Map.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
// @ts-nocheck

const widgets = require('@jupyter-widgets/base');
const L = require('./leaflet.js');
const utils = require('./utils.js');
const proj = require('./projections.js');
import * as widgets from '@jupyter-widgets/base';
import L from './leaflet';
import * as utils from './utils';
import * as proj from './projections';

const DEFAULT_LOCATION = [0.0, 0.0];

Expand Down Expand Up @@ -448,7 +449,7 @@ export class LeafletMapView extends utils.LeafletDOMWidgetView {

_processLuminoMessage(msg, _super) {
_super.call(this, msg);
if(!this.obj) return;
if (!this.obj) return;
switch (msg.type) {
case 'resize':
// We set the dirty flag to true to prevent the sub-pixel error
Expand Down
4 changes: 3 additions & 1 deletion js/amd-public-path.js → js/src/amd-public-path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// In an AMD module, we set the public path using the magic requirejs 'module' dependency
// See https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module
// Since 'module' is a requirejs magic module, we must include 'module' in the webpack externals configuration.
var module = require('module');
// @ts-nocheck

import * as module from 'module';
var url = new URL(module.uri, document.location);
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/'
url.pathname = url.pathname.slice(0, url.pathname.lastIndexOf('/') + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
//@ts-nocheck

const L = require('../leaflet.js');
const control = require('./Control.js');
import L from '../leaflet';
import * as control from './Control';

export class LeafletAttributionControlModel extends control.LeafletControlModel {
defaults() {
Expand Down
7 changes: 4 additions & 3 deletions js/src/controls/Control.js → js/src/controls/Control.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const widgets = require('@jupyter-widgets/base');
const L = require('../leaflet.js');
const utils = require('../utils.js');
//@ts-nocheck

import * as widgets from '@jupyter-widgets/base';
import L from '../leaflet';
import * as utils from '../utils';
export class LeafletControlModel extends widgets.WidgetModel {
defaults() {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const widgets = require('@jupyter-widgets/base');
const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck

import * as widgets from '@jupyter-widgets/base';
import L from '../leaflet';
import * as control from './Control';

export class LeafletDrawControlModel extends control.LeafletControlModel {
defaults() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const L = require('../leaflet.js');
const control = require('./Control.js');

//@ts-nocheck
import L from '../leaflet';
import * as control from './Control';
export class LeafletFullScreenControlModel extends control.LeafletControlModel {
defaults() {
return {
Expand All @@ -21,6 +21,8 @@ export class LeafletFullScreenControlView extends control.LeafletControlView {
}

create_obj() {
//@ts-ignore

this.obj = L.control.fullscreen(this.get_options());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck
import L from '../leaflet';
import * as control from './Control';

export class LeafletLayersControlModel extends control.LeafletControlModel {
defaults() {
Expand Down Expand Up @@ -56,6 +57,7 @@ export class LeafletLayersControlView extends control.LeafletControlView {
}
return ov;
}, {});
//@ts-ignore
this.obj = L.control.layers(baselayers, overlays, this.get_options());
return this;
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const L = require('../leaflet.js');
const control = require('./Control.js');
// @ts-nocheck

import L from '../leaflet';
import * as control from './Control';
export class LeafletLegendControlModel extends control.LeafletControlModel {
defaults() {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck
import L from '../leaflet';
import * as control from './Control';

export class LeafletMeasureControlModel extends control.LeafletControlModel {
defaults() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const L = require('../leaflet.js');
const control = require('./Control.js');

//@ts-nocheck
import L from '../leaflet';
import * as control from './Control';
export class LeafletScaleControlModel extends control.LeafletControlModel {
defaults() {
return {
Expand All @@ -21,6 +21,7 @@ export class LeafletScaleControlView extends control.LeafletControlView {
}

create_obj() {
//@ts-ignore
this.obj = L.control.scale(this.get_options());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const widgets = require('@jupyter-widgets/base');
const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck
import * as widgets from '@jupyter-widgets/base';
import L from '../leaflet';
import * as control from './Control';

export class LeafletSearchControlModel extends control.LeafletControlModel {
defaults() {
Expand Down Expand Up @@ -47,6 +48,7 @@ export class LeafletSearchControlView extends control.LeafletControlView {
const options = this.get_options();
options.layer = layer_view !== null ? layer_view.obj : null;
options.marker = marker_view !== null ? marker_view.obj : false;
//@ts-ignore
this.obj = L.control.search(options);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const widgets = require('@jupyter-widgets/base');
const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck
import * as widgets from '@jupyter-widgets/base';
import L from '../leaflet';
import * as control from './Control';

export class LeafletSplitMapControlModel extends control.LeafletControlModel {
default() {
Expand Down Expand Up @@ -50,6 +51,7 @@ export class LeafletSplitMapControlView extends control.LeafletControlView {
right_views.push(view.obj);
}
});
//@ts-ignore
this.obj = L.control.splitMap(left_views, right_views);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const widgets = require('@jupyter-widgets/base');
const L = require('../leaflet.js');
const control = require('./Control.js');
const PMessaging = require('@lumino/messaging');
const PWidgets = require('@lumino/widgets');
//@ts-nocheck
import * as widgets from '@jupyter-widgets/base';
import * as PMessaging from '@lumino/messaging';
import * as PWidgets from '@lumino/widgets';
import L from '../leaflet';
import * as control from './Control';

class WidgetControl extends L.Control {
updateLayout(options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

const L = require('../leaflet.js');
const control = require('./Control.js');
//@ts-nocheck
import L from '../leaflet';
import * as control from './Control';

export class LeafletZoomControlModel extends control.LeafletControlModel {
defaults() {
Expand All @@ -25,6 +26,7 @@ export class LeafletZoomControlView extends control.LeafletControlView {
}

create_obj() {
//@ts-ignore
this.obj = L.control.zoom(this.get_options());
}
}
2 changes: 1 addition & 1 deletion js/src/embed.js → js/src/embed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

module.exports = require('./index.js');
export * from './index';
6 changes: 2 additions & 4 deletions js/src/extension.js → js/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
// @ts-nocheck

// Configure requirejs
if (window.require) {
Expand All @@ -12,7 +13,4 @@ if (window.require) {
});
}

// Export the required load_ipython_extention
module.exports = {
load_ipython_extension: function () {},
};
export const load_ipython_extension = function () {};
10 changes: 8 additions & 2 deletions js/src/index.js → js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
// @ts-nocheck

import packageJson from '../package.json';

// Export everything from jupyter-leaflet and the npm package version number.
var _oldL = window.L;
module.exports = require('./jupyter-leaflet.js');
module.exports['version'] = require('../package.json').version;

// if previous L existed and it got changed while loading this module
if (_oldL !== undefined && _oldL !== window.L) {
Expand All @@ -13,3 +14,8 @@ if (_oldL !== undefined && _oldL !== window.L) {
);
ipyL = L.noConflict(); // eslint-disable-line no-undef
}

const { version } = packageJson;

export * from './jupyter-leaflet';
export { version };
Loading
Loading