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:
+43
-50
@@ -2,10 +2,9 @@
|
||||
* @module ol/events/condition
|
||||
*/
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import {FALSE, TRUE} from '../functions.js';
|
||||
import {MAC, WEBKIT} from '../has.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {TRUE, FALSE} from '../functions.js';
|
||||
import {WEBKIT, MAC} from '../has.js';
|
||||
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/MapBrowserEvent} and returns a
|
||||
@@ -14,7 +13,6 @@ import {WEBKIT, MAC} from '../has.js';
|
||||
* @typedef {function(this: ?, import("../MapBrowserEvent.js").default): boolean} Condition
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the alt-key is pressed, `false` otherwise (e.g. when
|
||||
* additionally the shift-key is pressed).
|
||||
@@ -23,15 +21,15 @@ import {WEBKIT, MAC} from '../has.js';
|
||||
* @return {boolean} True if only the alt key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const altKeyOnly = function(mapBrowserEvent) {
|
||||
export const altKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the alt-key and shift-key is pressed, `false` otherwise
|
||||
* (e.g. when additionally the platform-modifier-key is pressed).
|
||||
@@ -40,15 +38,15 @@ export const altKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the alt and shift keys are pressed.
|
||||
* @api
|
||||
*/
|
||||
export const altShiftKeysOnly = function(mapBrowserEvent) {
|
||||
export const altShiftKeysOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the map has the focus. This condition requires a map target
|
||||
* element with a `tabindex` attribute, e.g. `<div id="map" tabindex="1">`.
|
||||
@@ -57,11 +55,10 @@ export const altShiftKeysOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} The map has the focus.
|
||||
* @api
|
||||
*/
|
||||
export const focus = function(event) {
|
||||
export const focus = function (event) {
|
||||
return event.target.getTargetElement().contains(document.activeElement);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return always true.
|
||||
*
|
||||
@@ -71,7 +68,6 @@ export const focus = function(event) {
|
||||
*/
|
||||
export const always = TRUE;
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a `click` event, `false` otherwise.
|
||||
*
|
||||
@@ -79,11 +75,10 @@ export const always = TRUE;
|
||||
* @return {boolean} True if the event is a map `click` event.
|
||||
* @api
|
||||
*/
|
||||
export const click = function(mapBrowserEvent) {
|
||||
export const click = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.CLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event has an "action"-producing mouse button.
|
||||
*
|
||||
@@ -93,13 +88,11 @@ export const click = function(mapBrowserEvent) {
|
||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} The result.
|
||||
*/
|
||||
export const mouseActionButton = function(mapBrowserEvent) {
|
||||
export const mouseActionButton = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {MouseEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return originalEvent.button == 0 &&
|
||||
!(WEBKIT && MAC && originalEvent.ctrlKey);
|
||||
return originalEvent.button == 0 && !(WEBKIT && MAC && originalEvent.ctrlKey);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return always false.
|
||||
*
|
||||
@@ -109,7 +102,6 @@ export const mouseActionButton = function(mapBrowserEvent) {
|
||||
*/
|
||||
export const never = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the browser event is a `pointermove` event, `false`
|
||||
* otherwise.
|
||||
@@ -118,11 +110,10 @@ export const never = FALSE;
|
||||
* @return {boolean} True if the browser event is a `pointermove` event.
|
||||
* @api
|
||||
*/
|
||||
export const pointerMove = function(mapBrowserEvent) {
|
||||
export const pointerMove = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == 'pointermove';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a map `singleclick` event, `false` otherwise.
|
||||
*
|
||||
@@ -130,11 +121,10 @@ export const pointerMove = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event is a map `singleclick` event.
|
||||
* @api
|
||||
*/
|
||||
export const singleClick = function(mapBrowserEvent) {
|
||||
export const singleClick = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.SINGLECLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a map `dblclick` event, `false` otherwise.
|
||||
*
|
||||
@@ -142,11 +132,10 @@ export const singleClick = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event is a map `dblclick` event.
|
||||
* @api
|
||||
*/
|
||||
export const doubleClick = function(mapBrowserEvent) {
|
||||
export const doubleClick = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.DBLCLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if no modifier key (alt-, shift- or platform-modifier-key) is
|
||||
* pressed.
|
||||
@@ -155,15 +144,15 @@ export const doubleClick = function(mapBrowserEvent) {
|
||||
* @return {boolean} True only if there no modifier keys are pressed.
|
||||
* @api
|
||||
*/
|
||||
export const noModifierKeys = function(mapBrowserEvent) {
|
||||
export const noModifierKeys = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the platform-modifier-key (the meta-key on Mac,
|
||||
* ctrl-key otherwise) is pressed, `false` otherwise (e.g. when additionally
|
||||
@@ -173,14 +162,15 @@ export const noModifierKeys = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the platform modifier key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const platformModifierKeyOnly = function(mapBrowserEvent) {
|
||||
export const platformModifierKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return !originalEvent.altKey &&
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
(MAC ? originalEvent.metaKey : originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey;
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the shift-key is pressed, `false` otherwise (e.g. when
|
||||
* additionally the alt-key is pressed).
|
||||
@@ -189,15 +179,15 @@ export const platformModifierKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the shift key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const shiftKeyOnly = function(mapBrowserEvent) {
|
||||
export const shiftKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the target element is not editable, i.e. not a `<input>`-,
|
||||
* `<select>`- or `<textarea>`-element, `false` otherwise.
|
||||
@@ -206,13 +196,12 @@ export const shiftKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True only if the target element is not editable.
|
||||
* @api
|
||||
*/
|
||||
export const targetNotEditable = function(mapBrowserEvent) {
|
||||
export const targetNotEditable = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
const tagName = /** @type {Element} */ (originalEvent.target).tagName;
|
||||
return tagName !== 'INPUT' && tagName !== 'SELECT' && tagName !== 'TEXTAREA';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event originates from a mouse device.
|
||||
*
|
||||
@@ -220,8 +209,9 @@ export const targetNotEditable = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a mouse device.
|
||||
* @api
|
||||
*/
|
||||
export const mouseOnly = function(mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const mouseOnly = function (mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvent.pointerType == 'mouse';
|
||||
@@ -234,8 +224,9 @@ export const mouseOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a touchable device.
|
||||
* @api
|
||||
*/
|
||||
export const touchOnly = function(mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const touchOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'touch';
|
||||
@@ -248,8 +239,9 @@ export const touchOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a digital pen.
|
||||
* @api
|
||||
*/
|
||||
export const penOnly = function(mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const penOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'pen';
|
||||
@@ -264,8 +256,9 @@ export const penOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a primary pointer.
|
||||
* @api
|
||||
*/
|
||||
export const primaryAction = function(mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const primaryAction = function (mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
return pointerEvent.isPrimary && pointerEvent.button === 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user