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

feat: Add typescript definitions #358

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
copy: {
tsd: {
src: "src/L.Control.Locate.d.ts",
dest: "dist/L.Control.Locate.d.ts"
}
},
uglify: {
options: {
banner: banner,
Expand Down Expand Up @@ -48,6 +54,8 @@ module.exports = function (grunt) {
"dist/L.Control.Locate.css",
"dist/L.Control.Locate.min.css",
"dist/L.Control.Locate.min.css.map",
"dist/L.Control.Locate.d.ts",
"dist/L.Control.Locate.esm.js",
"dist/L.Control.Locate.mapbox.css",
"dist/L.Control.Locate.mapbox.min.css",
"dist/L.Control.Locate.mapbox.min.css.map",
Expand Down Expand Up @@ -108,7 +116,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-rollup");
grunt.loadNpmTasks("grunt-bump");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-copy");

// Default task(s).
grunt.registerTask("default", ["rollup:build_es", "rollup:build_umd", "uglify", "sass"]);
grunt.registerTask("default", ["rollup:build_es", "rollup:build_umd", "copy", "uglify", "sass"]);
};
2 changes: 1 addition & 1 deletion dist/L.Control.Locate.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions dist/L.Control.Locate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Control, Layer, Map, ControlOptions, PathOptions, MarkerOptions, LocationEvent, LatLngBounds } from "leaflet";

export type SetView = false | 'once' | 'always' | 'untilPan' | 'untilPanOrZoom';

export interface StringsOptions {
title?: string | undefined;
metersUnit?: string | undefined;
feetUnit?: string | undefined;
popup?: string | undefined;
outsideMapBoundsMsg?: string | undefined;
}

export interface LocateOptions extends ControlOptions {
layer?: Layer | undefined;
setView?: SetView | undefined;
keepCurrentZoomLevel?: boolean | undefined;
initialZoomLevel?: number | boolean | undefined;
getLocationBounds?: ((locationEvent: LocationEvent) => LatLngBounds) | undefined;
flyTo?: boolean | undefined;
clickBehavior?: any;
returnToPrevBounds?: boolean | undefined;
cacheLocation?: boolean | undefined;
drawCircle?: boolean | undefined;
drawMarker?: boolean | undefined;
showCompass?: boolean | undefined;
markerClass?: any;
compassClass?: any;
circleStyle?: PathOptions | undefined;
markerStyle?: PathOptions | MarkerOptions | undefined;
compassStyle?: PathOptions | undefined;
followCircleStyle?: PathOptions | undefined;
followMarkerStyle?: PathOptions | undefined;
icon?: string | undefined;
iconLoading?: string | undefined;
iconElementTag?: string | undefined;
textElementTag?: string | undefined;
circlePadding?: number[] | undefined;
metric?: boolean | undefined;
createButtonCallback?: ((container: HTMLDivElement, options: LocateOptions) => { link: HTMLAnchorElement; icon: HTMLElement }) | undefined;
onLocationError?: ((event: ErrorEvent, control: LocateControl) => void) | undefined;
onLocationOutsideMapBounds?: ((control: LocateControl) => void) | undefined;
showPopup?: boolean | undefined;
strings?: StringsOptions | undefined;
locateOptions?: L.LocateOptions | undefined;
}

export class LocateControl extends Control {
constructor(locateOptions?: LocateOptions);

onAdd(map: Map): HTMLElement;

start(): void;

stop(): void;

stopFollowing(): void;

setView(): void;
}
2 changes: 1 addition & 1 deletion dist/L.Control.Locate.mapbox.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/L.Control.Locate.mapbox.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/L.Control.Locate.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 107 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"unpkg": "dist/L.Control.Locate.min.js",
"jsdelivr": "dist/L.Control.Locate.min.js",
"module": "dist/L.Control.Locate.esm.js",
"types": "dist/L.Control.Locate.d.ts",
"author": "Dominik Moritz <[email protected]>",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,6 +37,7 @@
"grunt": "^1.6.1",
"grunt-bump": "0.8.0",
"grunt-contrib-connect": "^4.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-uglify": "^5.2.2",
"grunt-rollup": "^12.0.0",
"grunt-sass": "^3.1.0",
Expand Down
66 changes: 66 additions & 0 deletions src/L.Control.Locate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Control, Layer, Map, ControlOptions, PathOptions, MarkerOptions, LocationEvent, LatLngBounds } from "leaflet";

export type SetView = false | 'once' | 'always' | 'untilPan' | 'untilPanOrZoom';
export type ClickBehavior = 'stop' | 'setView';

export interface StringsOptions {
title?: string | undefined;
metersUnit?: string | undefined;
feetUnit?: string | undefined;
popup?: string | undefined;
outsideMapBoundsMsg?: string | undefined;
}

export interface ClickBehaviorOptions {
inView?: ClickBehavior | undefined;
outOfView?: ClickBehavior | undefined;
inViewNotFollowing?: ClickBehavior | 'inView' | undefined;
}

export interface LocateOptions extends ControlOptions {
layer?: Layer | undefined;
setView?: SetView | undefined;
keepCurrentZoomLevel?: boolean | undefined;
initialZoomLevel?: number | boolean | undefined;
getLocationBounds?: ((locationEvent: LocationEvent) => LatLngBounds) | undefined;
flyTo?: boolean | undefined;
clickBehavior?: ClickBehaviorOptions | undefined;
returnToPrevBounds?: boolean | undefined;
cacheLocation?: boolean | undefined;
drawCircle?: boolean | undefined;
drawMarker?: boolean | undefined;
showCompass?: boolean | undefined;
markerClass?: any;
compassClass?: any;
circleStyle?: PathOptions | undefined;
markerStyle?: PathOptions | MarkerOptions | undefined;
compassStyle?: PathOptions | undefined;
followCircleStyle?: PathOptions | undefined;
followMarkerStyle?: PathOptions | undefined;
icon?: string | undefined;
iconLoading?: string | undefined;
iconElementTag?: string | undefined;
textElementTag?: string | undefined;
circlePadding?: number[] | undefined;
metric?: boolean | undefined;
createButtonCallback?: ((container: HTMLDivElement, options: LocateOptions) => { link: HTMLAnchorElement; icon: HTMLElement }) | undefined;
onLocationError?: ((event: ErrorEvent, control: LocateControl) => void) | undefined;
onLocationOutsideMapBounds?: ((control: LocateControl) => void) | undefined;
showPopup?: boolean | undefined;
strings?: StringsOptions | undefined;
locateOptions?: L.LocateOptions | undefined;
}

export class LocateControl extends Control {
constructor(locateOptions?: LocateOptions);

onAdd(map: Map): HTMLElement;

start(): void;

stop(): void;

stopFollowing(): void;

setView(): void;
}