Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -3,22 +3,20 @@
*/
import 'elm-pep';
import {DEVICE_PIXEL_RATIO, PASSIVE_EVENT_LISTENERS} from './has.js';
import EventTarget from './events/Target.js';
import EventType from './events/EventType.js';
import MapBrowserEventType from './MapBrowserEventType.js';
import MapBrowserPointerEvent from './MapBrowserPointerEvent.js';
import {listen, unlistenByKey} from './events.js';
import EventTarget from './events/Target.js';
import PointerEventType from './pointer/EventType.js';
import EventType from './events/EventType.js';
import {DEVICE_PIXEL_RATIO, PASSIVE_EVENT_LISTENERS} from './has.js';
import {listen, unlistenByKey} from './events.js';
class MapBrowserEventHandler extends EventTarget {
/**
* @param {import("./PluggableMap.js").default} map The map with the viewport to listen to events on.
* @param {number=} moveTolerance The minimal distance the pointer must travel to trigger a move.
*/
constructor(map, moveTolerance) {
super(map);
/**
@@ -50,8 +48,9 @@ class MapBrowserEventHandler extends EventTarget {
* @type {number}
* @private
*/
this.moveTolerance_ = moveTolerance ?
moveTolerance * DEVICE_PIXEL_RATIO : DEVICE_PIXEL_RATIO;
this.moveTolerance_ = moveTolerance
? moveTolerance * DEVICE_PIXEL_RATIO
: DEVICE_PIXEL_RATIO;
/**
* The most recent "down" type event (or null if none have occurred).
@@ -81,9 +80,12 @@ class MapBrowserEventHandler extends EventTarget {
* @type {?import("./events.js").EventsKey}
* @private
*/
this.pointerdownListenerKey_ = listen(element,
this.pointerdownListenerKey_ = listen(
element,
PointerEventType.POINTERDOWN,
this.handlePointerDown_, this);
this.handlePointerDown_,
this
);
/**
* @type {PointerEvent}
@@ -95,17 +97,23 @@ class MapBrowserEventHandler extends EventTarget {
* @type {?import("./events.js").EventsKey}
* @private
*/
this.relayedListenerKey_ = listen(element,
this.relayedListenerKey_ = listen(
element,
PointerEventType.POINTERMOVE,
this.relayEvent_, this);
this.relayEvent_,
this
);
/**
* @private
*/
this.boundHandleTouchMove_ = this.handleTouchMove_.bind(this);
this.element_.addEventListener(EventType.TOUCHMOVE, this.boundHandleTouchMove_,
PASSIVE_EVENT_LISTENERS ? {passive: false} : false);
this.element_.addEventListener(
EventType.TOUCHMOVE,
this.boundHandleTouchMove_,
PASSIVE_EVENT_LISTENERS ? {passive: false} : false
);
}
/**
@@ -115,23 +123,35 @@ class MapBrowserEventHandler extends EventTarget {
*/
emulateClick_(pointerEvent) {
let newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.CLICK, this.map_, pointerEvent);
MapBrowserEventType.CLICK,
this.map_,
pointerEvent
);
this.dispatchEvent(newEvent);
if (this.clickTimeoutId_ !== undefined) {
// double-click
clearTimeout(this.clickTimeoutId_);
this.clickTimeoutId_ = undefined;
newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.DBLCLICK, this.map_, pointerEvent);
MapBrowserEventType.DBLCLICK,
this.map_,
pointerEvent
);
this.dispatchEvent(newEvent);
} else {
// click
this.clickTimeoutId_ = setTimeout(function() {
this.clickTimeoutId_ = undefined;
const newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
}.bind(this), 250);
this.clickTimeoutId_ = setTimeout(
function () {
this.clickTimeoutId_ = undefined;
const newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.SINGLECLICK,
this.map_,
pointerEvent
);
this.dispatchEvent(newEvent);
}.bind(this),
250
);
}
}
@@ -145,8 +165,10 @@ class MapBrowserEventHandler extends EventTarget {
updateActivePointers_(pointerEvent) {
const event = pointerEvent;
if (event.type == MapBrowserEventType.POINTERUP ||
event.type == MapBrowserEventType.POINTERCANCEL) {
if (
event.type == MapBrowserEventType.POINTERUP ||
event.type == MapBrowserEventType.POINTERCANCEL
) {
delete this.trackedTouches_[event.pointerId];
} else if (event.type == MapBrowserEventType.POINTERDOWN) {
this.trackedTouches_[event.pointerId] = true;
@@ -162,7 +184,10 @@ class MapBrowserEventHandler extends EventTarget {
handlePointerUp_(pointerEvent) {
this.updateActivePointers_(pointerEvent);
const newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.POINTERUP, this.map_, pointerEvent);
MapBrowserEventType.POINTERUP,
this.map_,
pointerEvent
);
this.dispatchEvent(newEvent);
// We emulate click events on left mouse button click, touch contact, and pen
@@ -171,7 +196,11 @@ class MapBrowserEventHandler extends EventTarget {
// See http://www.w3.org/TR/pointerevents/#button-states
// We only fire click, singleclick, and doubleclick if nobody has called
// event.stopPropagation() or event.preventDefault().
if (!newEvent.propagationStopped && !this.dragging_ && this.isMouseActionButton_(pointerEvent)) {
if (
!newEvent.propagationStopped &&
!this.dragging_ &&
this.isMouseActionButton_(pointerEvent)
) {
this.emulateClick_(this.down_);
}
@@ -201,19 +230,28 @@ class MapBrowserEventHandler extends EventTarget {
handlePointerDown_(pointerEvent) {
this.updateActivePointers_(pointerEvent);
const newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.POINTERDOWN, this.map_, pointerEvent);
MapBrowserEventType.POINTERDOWN,
this.map_,
pointerEvent
);
this.dispatchEvent(newEvent);
this.down_ = pointerEvent;
if (this.dragListenerKeys_.length === 0) {
this.dragListenerKeys_.push(
listen(document,
listen(
document,
MapBrowserEventType.POINTERMOVE,
this.handlePointerMove_, this),
listen(document,
this.handlePointerMove_,
this
),
listen(
document,
MapBrowserEventType.POINTERUP,
this.handlePointerUp_, this),
this.handlePointerUp_,
this
),
/* Note that the listener for `pointercancel is set up on
* `pointerEventHandler_` and not `documentPointerEventHandler_` like
* the `pointerup` and `pointermove` listeners.
@@ -227,9 +265,12 @@ class MapBrowserEventHandler extends EventTarget {
* only receive a `touchcancel` from `pointerEventHandler_`, because it is
* only registered there.
*/
listen(this.element_,
listen(
this.element_,
MapBrowserEventType.POINTERCANCEL,
this.handlePointerUp_, this)
this.handlePointerUp_,
this
)
);
}
}
@@ -246,8 +287,11 @@ class MapBrowserEventHandler extends EventTarget {
if (this.isMoving_(pointerEvent)) {
this.dragging_ = true;
const newEvent = new MapBrowserPointerEvent(
MapBrowserEventType.POINTERDRAG, this.map_, pointerEvent,
this.dragging_);
MapBrowserEventType.POINTERDRAG,
this.map_,
pointerEvent,
this.dragging_
);
this.dispatchEvent(newEvent);
}
}
@@ -262,8 +306,14 @@ class MapBrowserEventHandler extends EventTarget {
relayEvent_(pointerEvent) {
this.originalPointerMoveEvent_ = pointerEvent;
const dragging = !!(this.down_ && this.isMoving_(pointerEvent));
this.dispatchEvent(new MapBrowserPointerEvent(
pointerEvent.type, this.map_, pointerEvent, dragging));
this.dispatchEvent(
new MapBrowserPointerEvent(
pointerEvent.type,
this.map_,
pointerEvent,
dragging
)
);
}
/**
@@ -277,7 +327,10 @@ class MapBrowserEventHandler extends EventTarget {
handleTouchMove_(event) {
// Due to https://github.com/mpizenberg/elm-pep/issues/2, `this.originalPointerMoveEvent_`
// may not be initialized yet when we get here on a platform without native pointer events.
if (!this.originalPointerMoveEvent_ || this.originalPointerMoveEvent_.defaultPrevented) {
if (
!this.originalPointerMoveEvent_ ||
this.originalPointerMoveEvent_.defaultPrevented
) {
event.preventDefault();
}
}
@@ -289,9 +342,12 @@ class MapBrowserEventHandler extends EventTarget {
* @private
*/
isMoving_(pointerEvent) {
return this.dragging_ ||
Math.abs(pointerEvent.clientX - this.down_.clientX) > this.moveTolerance_ ||
Math.abs(pointerEvent.clientY - this.down_.clientY) > this.moveTolerance_;
return (
this.dragging_ ||
Math.abs(pointerEvent.clientX - this.down_.clientX) >
this.moveTolerance_ ||
Math.abs(pointerEvent.clientY - this.down_.clientY) > this.moveTolerance_
);
}
/**
@@ -302,7 +358,10 @@ class MapBrowserEventHandler extends EventTarget {
unlistenByKey(this.relayedListenerKey_);
this.relayedListenerKey_ = null;
}
this.element_.removeEventListener(EventType.TOUCHMOVE, this.boundHandleTouchMove_);
this.element_.removeEventListener(
EventType.TOUCHMOVE,
this.boundHandleTouchMove_
);
if (this.pointerdownListenerKey_) {
unlistenByKey(this.pointerdownListenerKey_);
@@ -317,5 +376,4 @@ class MapBrowserEventHandler extends EventTarget {
}
}
export default MapBrowserEventHandler;