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

[Flow] Add missing export types to handler/* #11503

Merged
merged 3 commits into from
Feb 11, 2022
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
11 changes: 6 additions & 5 deletions src/ui/handler/box_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Event} from '../../util/evented.js';

import type Map from '../map.js';
import type Point from '@mapbox/point-geometry';
import type {HandlerResult} from '../handler_manager.js';

/**
* The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
Expand Down Expand Up @@ -44,7 +45,7 @@ class BoxZoomHandler {
* @example
* const isBoxZoomEnabled = map.boxZoom.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return !!this._enabled;
}

Expand All @@ -55,7 +56,7 @@ class BoxZoomHandler {
* @example
* const isBoxZoomActive = map.boxZoom.isActive();
*/
isActive() {
isActive(): boolean {
return !!this._active;
}

Expand Down Expand Up @@ -122,7 +123,7 @@ class BoxZoomHandler {
});
}

mouseupWindow(e: MouseEvent, point: Point) {
mouseupWindow(e: MouseEvent, point: Point): ?HandlerResult {
if (!this._active) return;

if (e.button !== 0) return;
Expand All @@ -139,7 +140,7 @@ class BoxZoomHandler {
} else {
this._map.fire(new Event('boxzoomend', {originalEvent: e}));
return {
cameraAnimation: map => map.fitScreenCoordinates(p0, p1, this._map.getBearing(), {linear: false})
cameraAnimation: (map: Map) => map.fitScreenCoordinates(p0, p1, this._map.getBearing(), {linear: false})
};
}
}
Expand Down Expand Up @@ -173,7 +174,7 @@ class BoxZoomHandler {
delete this._lastPos;
}

_fireEvent(type: string, e: *) {
_fireEvent(type: string, e: *): Map {
return this._map.fire(new Event(type, {originalEvent: e}));
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/ui/handler/click_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type Point from '@mapbox/point-geometry';
import type Map from '../map.js';
import type {HandlerResult} from '../handler_manager.js';

export default class ClickZoomHandler {

Expand All @@ -20,7 +21,7 @@ export default class ClickZoomHandler {
this.reset();
}

dblclick(e: MouseEvent, point: Point) {
dblclick(e: MouseEvent, point: Point): HandlerResult {
e.preventDefault();
return {
cameraAnimation: (map: Map) => {
Expand All @@ -42,11 +43,11 @@ export default class ClickZoomHandler {
this.reset();
}

isEnabled() {
isEnabled(): boolean {
return this._enabled;
}

isActive() {
isActive(): boolean {
return this._active;
}
}
2 changes: 1 addition & 1 deletion src/ui/handler/handler_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from 'assert';

import type Point from '@mapbox/point-geometry';

export function indexTouches(touches: Array<Touch>, points: Array<Point>) {
export function indexTouches(touches: Array<Touch>, points: Array<Point>): {[number | string]: Point} {
assert(touches.length === points.length);
const obj = {};
for (let i = 0; i < touches.length; i++) {
Expand Down
7 changes: 4 additions & 3 deletions src/ui/handler/keyboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import type Map from '../map.js';
import type {HandlerResult} from '../handler_manager.js';

const defaultOptions = {
panStep: 100,
Expand Down Expand Up @@ -53,7 +54,7 @@ class KeyboardHandler {
this._active = false;
}

keydown(e: KeyboardEvent) {
keydown(e: KeyboardEvent): ?HandlerResult {
if (e.altKey || e.ctrlKey || e.metaKey) return;

let zoomDir = 0;
Expand Down Expand Up @@ -169,7 +170,7 @@ class KeyboardHandler {
* @example
* const isKeyboardEnabled = map.keyboard.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return this._enabled;
}

Expand All @@ -182,7 +183,7 @@ class KeyboardHandler {
* @example
* const isKeyboardActive = map.keyboard.isActive();
*/
isActive() {
isActive(): boolean {
return this._active;
}

Expand Down
19 changes: 10 additions & 9 deletions src/ui/handler/map_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {MapMouseEvent, MapTouchEvent, MapWheelEvent} from '../events.js';

import type Map from '../map.js';
import type Point from '@mapbox/point-geometry';
import type {HandlerResult} from '../handler_manager.js';

export class MapEventHandler {

Expand All @@ -21,13 +22,13 @@ export class MapEventHandler {
this._mousedownPos = undefined;
}

wheel(e: WheelEvent) {
wheel(e: WheelEvent): ?HandlerResult {
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
// - ScrollZoom
return this._firePreventable(new MapWheelEvent(e.type, this._map, e));
}

mousedown(e: MouseEvent, point: Point) {
mousedown(e: MouseEvent, point: Point): ?HandlerResult {
this._mousedownPos = point;
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
// - MousePan
Expand All @@ -53,7 +54,7 @@ export class MapEventHandler {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
}

dblclick(e: MouseEvent) {
dblclick(e: MouseEvent): ?HandlerResult {
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
// - DblClickZoom
return this._firePreventable(new MapMouseEvent(e.type, this._map, e));
Expand All @@ -67,7 +68,7 @@ export class MapEventHandler {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
}

touchstart(e: TouchEvent) {
touchstart(e: TouchEvent): ?HandlerResult {
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
// - TouchPan
// - TouchZoom
Expand All @@ -90,19 +91,19 @@ export class MapEventHandler {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}

_firePreventable(mapEvent: MapMouseEvent | MapTouchEvent | MapWheelEvent) {
_firePreventable(mapEvent: MapMouseEvent | MapTouchEvent | MapWheelEvent): ?HandlerResult {
this._map.fire(mapEvent);
if (mapEvent.defaultPrevented) {
// returning an object marks the handler as active and resets other handlers
return {};
}
}

isEnabled() {
isEnabled(): boolean {
return true;
}

isActive() {
isActive(): boolean {
return false;
}
enable() {}
Expand Down Expand Up @@ -154,11 +155,11 @@ export class BlockableMapEventHandler {
}
}

isEnabled() {
isEnabled(): boolean {
return true;
}

isActive() {
isActive(): boolean {
return false;
}
enable() {}
Expand Down
17 changes: 9 additions & 8 deletions src/ui/handler/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as DOM from '../../util/dom.js';
import type Point from '@mapbox/point-geometry';
import type {HandlerResult} from '../handler_manager.js';

const LEFT_BUTTON = 0;
const RIGHT_BUTTON = 2;
Expand Down Expand Up @@ -42,7 +43,7 @@ class MouseHandler {
this._eventButton = undefined;
}

_correctButton(e: MouseEvent, button: number) { //eslint-disable-line
_correctButton(e: MouseEvent, button: number): boolean { //eslint-disable-line
return false; // implemented by child
}

Expand Down Expand Up @@ -101,11 +102,11 @@ class MouseHandler {
this.reset();
}

isEnabled() {
isEnabled(): boolean {
return this._enabled;
}

isActive() {
isActive(): boolean {
return this._active;
}
}
Expand All @@ -116,7 +117,7 @@ export class MousePanHandler extends MouseHandler {
super.mousedown(e, point);
if (this._lastPoint) this._active = true;
}
_correctButton(e: MouseEvent, button: number) {
_correctButton(e: MouseEvent, button: number): boolean {
return button === LEFT_BUTTON && !e.ctrlKey;
}

Expand All @@ -129,11 +130,11 @@ export class MousePanHandler extends MouseHandler {
}

export class MouseRotateHandler extends MouseHandler {
_correctButton(e: MouseEvent, button: number) {
_correctButton(e: MouseEvent, button: number): boolean {
return (button === LEFT_BUTTON && e.ctrlKey) || (button === RIGHT_BUTTON);
}

_move(lastPoint: Point, point: Point) {
_move(lastPoint: Point, point: Point): ?HandlerResult {
const degreesPerPixelMoved = 0.8;
const bearingDelta = (point.x - lastPoint.x) * degreesPerPixelMoved;
if (bearingDelta) {
Expand All @@ -150,11 +151,11 @@ export class MouseRotateHandler extends MouseHandler {
}

export class MousePitchHandler extends MouseHandler {
_correctButton(e: MouseEvent, button: number) {
_correctButton(e: MouseEvent, button: number): boolean {
return (button === LEFT_BUTTON && e.ctrlKey) || (button === RIGHT_BUTTON);
}

_move(lastPoint: Point, point: Point) {
_move(lastPoint: Point, point: Point): ?HandlerResult {
const degreesPerPixelMoved = -0.5;
const pitchDelta = (point.y - lastPoint.y) * degreesPerPixelMoved;
if (pitchDelta) {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/handler/scroll_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ScrollZoomHandler {
* @example
* const isScrollZoomEnabled = map.scrollZoom.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return !!this._enabled;
}

Expand All @@ -120,11 +120,11 @@ class ScrollZoomHandler {
* render is called, so _active is not a good candidate for determining if a scroll zoom animation is in
* progress.
*/
isActive() {
isActive(): boolean {
return !!this._active || this._finishTimeout !== undefined;
}

isZooming() {
isZooming(): boolean {
return !!this._zooming;
}

Expand Down Expand Up @@ -397,7 +397,7 @@ class ScrollZoomHandler {
}
}

_isFullscreen() {
_isFullscreen(): boolean {
return !!window.document.fullscreenElement;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui/handler/shim/dblclick_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class DoubleClickZoomHandler {
* @example
* const isDoubleClickZoomEnabled = map.doubleClickZoom.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return this._clickZoom.isEnabled() && this._tapZoom.isEnabled();
}

Expand All @@ -62,7 +62,7 @@ export default class DoubleClickZoomHandler {
* @example
* const isDoubleClickZoomActive = map.doubleClickZoom.isActive();
*/
isActive() {
isActive(): boolean {
return this._clickZoom.isActive() || this._tapZoom.isActive();
}
}
4 changes: 2 additions & 2 deletions src/ui/handler/shim/drag_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class DragPanHandler {
* @example
* const isDragPanEnabled = map.dragPan.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return this._mousePan.isEnabled() && this._touchPan.isEnabled();
}

Expand All @@ -90,7 +90,7 @@ export default class DragPanHandler {
* @example
* const isDragPanActive = map.dragPan.isActive();
*/
isActive() {
isActive(): boolean {
return this._mousePan.isActive() || this._touchPan.isActive();
}
}
4 changes: 2 additions & 2 deletions src/ui/handler/shim/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class DragRotateHandler {
* @example
* const isDragRotateEnabled = map.dragRotate.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return this._mouseRotate.isEnabled() && (!this._pitchWithRotate || this._mousePitch.isEnabled());
}

Expand All @@ -68,7 +68,7 @@ export default class DragRotateHandler {
* @example
* const isDragRotateActive = map.dragRotate.isActive();
*/
isActive() {
isActive(): boolean {
return this._mouseRotate.isActive() || this._mousePitch.isActive();
}
}
4 changes: 2 additions & 2 deletions src/ui/handler/shim/touch_zoom_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class TouchZoomRotateHandler {
* @example
* const isTouchZoomRotateEnabled = map.touchZoomRotate.isEnabled();
*/
isEnabled() {
isEnabled(): boolean {
return this._touchZoom.isEnabled() &&
(this._rotationDisabled || this._touchRotate.isEnabled()) &&
this._tapDragZoom.isEnabled();
Expand All @@ -84,7 +84,7 @@ export default class TouchZoomRotateHandler {
* @example
* const isTouchZoomRotateActive = map.touchZoomRotate.isActive();
*/
isActive() {
isActive(): boolean {
return this._touchZoom.isActive() || this._touchRotate.isActive() || this._tapDragZoom.isActive();
}

Expand Down
Loading