@opengeoweb/shared 9.8.0 → 9.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.esm.js +788 -41
- package/package.json +2 -2
- package/src/lib/components/CanvasComponent/CanvasComponent.d.ts +71 -0
- package/src/lib/components/CanvasComponent/CanvasComponent.stories.d.ts +7 -0
- package/src/lib/components/CanvasComponent/index.d.ts +1 -0
- package/src/lib/components/DraggableResizable/types.d.ts +8 -8
- package/src/lib/components/ToggleMenu/ToggleMenu.d.ts +2 -2
- package/src/lib/components/TooltipSelect/TooltipSelect.d.ts +6 -5
- package/src/lib/components/UserMenu/CheatSheet/ShortcutList.d.ts +2 -2
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/types/types.d.ts +1 -1
- package/src/lib/utils/dateUtils/dateUtils.d.ts +64 -11
- package/src/lib/utils/index.d.ts +1 -1
- package/src/lib/utils/metronome.d.ts +77 -0
- package/src/lib/utils/metronome.spec.d.ts +1 -0
- package/src/lib/utils/metronome.stories.d.ts +7 -0
- package/src/lib/utils/layoutUtils.d.ts +0 -1
- /package/src/lib/{utils/layoutUtils.spec.d.ts → components/CanvasComponent/CanvasComponent.spec.d.ts} +0 -0
package/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { useRef } from 'react';
|
|
2
|
+
import React__default, { useRef, Component } from 'react';
|
|
3
3
|
import { Box, Typography, Tooltip, IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Button, CircularProgress, Alert, AlertTitle, useTheme, Drawer, Link, Avatar as Avatar$1, Paper, ClickAwayListener, MenuList, MenuItem, Grid, RadioGroup, FormControlLabel, Radio, List, ListItem, Tabs, Tab, Backdrop, Slider, ToggleButton, Menu, ListSubheader, ListItemText, ListItemIcon, Select, Accordion, AccordionSummary, AccordionDetails, FormLabel, Switch, TextField, InputAdornment } from '@mui/material';
|
|
4
4
|
import { Close, Exclamation, Success, Info, ChevronRight, GeoWebLogo, HamburgerMenu, Resize, useThemeContext, DragHandle, ArrowLeft, ArrowRight, KeyOption, ArrowUp, ArrowDown, KeyCommand, Options, ChevronDown, Search, Clear, Cached } from '@opengeoweb/theme';
|
|
5
5
|
import { throttle, escapeRegExp, debounce } from 'lodash';
|
|
6
6
|
import Draggable from 'react-draggable';
|
|
7
7
|
import { Resizable } from 're-resizable';
|
|
8
8
|
import { useStore } from 'react-redux';
|
|
9
|
-
import { parseISO, parse, format, isEqual, add as add$1, sub as sub$1, differenceInMinutes as differenceInMinutes$1, differenceInHours as differenceInHours$1, isBefore as isBefore$1, isAfter as isAfter$1, isValid as isValid$1, getUnixTime, fromUnixTime, set as set$1, startOfDay } from 'date-fns';
|
|
9
|
+
import { parseISO, parse, format, isEqual, add as add$1, sub as sub$1, differenceInYears as differenceInYears$1, differenceInMonths as differenceInMonths$1, differenceInDays as differenceInDays$1, differenceInMinutes as differenceInMinutes$1, differenceInHours as differenceInHours$1, differenceInSeconds as differenceInSeconds$1, isBefore as isBefore$1, isAfter as isAfter$1, isValid as isValid$1, getUnixTime, fromUnixTime, set as set$1, startOfDay, isWithinInterval } from 'date-fns';
|
|
10
10
|
import configureStore from 'redux-mock-store';
|
|
11
11
|
import { configureStore as configureStore$1 } from '@reduxjs/toolkit';
|
|
12
12
|
|
|
@@ -259,6 +259,57 @@ function _nonIterableSpread() {
|
|
|
259
259
|
function _nonIterableRest() {
|
|
260
260
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
261
261
|
}
|
|
262
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
263
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
264
|
+
if (!it) {
|
|
265
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
266
|
+
if (it) o = it;
|
|
267
|
+
var i = 0;
|
|
268
|
+
var F = function () {};
|
|
269
|
+
return {
|
|
270
|
+
s: F,
|
|
271
|
+
n: function () {
|
|
272
|
+
if (i >= o.length) return {
|
|
273
|
+
done: true
|
|
274
|
+
};
|
|
275
|
+
return {
|
|
276
|
+
done: false,
|
|
277
|
+
value: o[i++]
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
e: function (e) {
|
|
281
|
+
throw e;
|
|
282
|
+
},
|
|
283
|
+
f: F
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
287
|
+
}
|
|
288
|
+
var normalCompletion = true,
|
|
289
|
+
didErr = false,
|
|
290
|
+
err;
|
|
291
|
+
return {
|
|
292
|
+
s: function () {
|
|
293
|
+
it = it.call(o);
|
|
294
|
+
},
|
|
295
|
+
n: function () {
|
|
296
|
+
var step = it.next();
|
|
297
|
+
normalCompletion = step.done;
|
|
298
|
+
return step;
|
|
299
|
+
},
|
|
300
|
+
e: function (e) {
|
|
301
|
+
didErr = true;
|
|
302
|
+
err = e;
|
|
303
|
+
},
|
|
304
|
+
f: function () {
|
|
305
|
+
try {
|
|
306
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
307
|
+
} finally {
|
|
308
|
+
if (didErr) throw err;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
262
313
|
|
|
263
314
|
var defaultDelay = 1000;
|
|
264
315
|
var useControlledTooltip = function useControlledTooltip() {
|
|
@@ -1113,9 +1164,16 @@ var DraggableComponent$1 = function DraggableComponent(_a) {
|
|
|
1113
1164
|
bounds = _a$bounds === void 0 ? 'body' : _a$bounds,
|
|
1114
1165
|
children = _a.children,
|
|
1115
1166
|
props = __rest(_a, ["bounds", "children"]);
|
|
1167
|
+
var onDragStart = function onDragStart(e) {
|
|
1168
|
+
// This makes sure that nothing is selected during drag
|
|
1169
|
+
e.preventDefault();
|
|
1170
|
+
};
|
|
1116
1171
|
return /*#__PURE__*/React__default.createElement(Draggable, Object.assign({
|
|
1117
1172
|
bounds: bounds
|
|
1118
|
-
}, props
|
|
1173
|
+
}, props, {
|
|
1174
|
+
enableUserSelectHack: false,
|
|
1175
|
+
onStart: onDragStart
|
|
1176
|
+
}), children);
|
|
1119
1177
|
};
|
|
1120
1178
|
|
|
1121
1179
|
/* *
|
|
@@ -2879,7 +2937,9 @@ var TooltipSelect = function TooltipSelect(_a) {
|
|
|
2879
2937
|
isEnabled = _a.isEnabled,
|
|
2880
2938
|
noStyling = _a.noStyling,
|
|
2881
2939
|
hasBackgroundColor = _a.hasBackgroundColor,
|
|
2882
|
-
|
|
2940
|
+
_a$variant = _a.variant,
|
|
2941
|
+
variant = _a$variant === void 0 ? 'standard' : _a$variant,
|
|
2942
|
+
props = __rest(_a, ["tooltip", "list", "currentIndex", "onChangeMouseWheel", "requiresCtrlToChange", "isEnabled", "noStyling", "hasBackgroundColor", "variant"]);
|
|
2883
2943
|
var _React$useState = React.useState(false),
|
|
2884
2944
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
2885
2945
|
selectOpen = _React$useState2[0],
|
|
@@ -2929,7 +2989,7 @@ var TooltipSelect = function TooltipSelect(_a) {
|
|
|
2929
2989
|
placement: "top",
|
|
2930
2990
|
open: tooltipOpen
|
|
2931
2991
|
}, /*#__PURE__*/React.createElement(Select, Object.assign({
|
|
2932
|
-
variant:
|
|
2992
|
+
variant: variant,
|
|
2933
2993
|
disableUnderline: true,
|
|
2934
2994
|
onOpen: onOpen,
|
|
2935
2995
|
onClose: onClose,
|
|
@@ -3316,6 +3376,366 @@ var LastUpdateTime = function LastUpdateTime(_ref) {
|
|
|
3316
3376
|
}, /*#__PURE__*/React__default.createElement(Cached, null)));
|
|
3317
3377
|
};
|
|
3318
3378
|
|
|
3379
|
+
var CanvasComponent = /*#__PURE__*/function (_Component) {
|
|
3380
|
+
_inherits(CanvasComponent, _Component);
|
|
3381
|
+
function CanvasComponent(props) {
|
|
3382
|
+
var _this;
|
|
3383
|
+
_classCallCheck(this, CanvasComponent);
|
|
3384
|
+
_this = _callSuper(this, CanvasComponent, [props]);
|
|
3385
|
+
_this.canvas = null;
|
|
3386
|
+
_this.ctx = null;
|
|
3387
|
+
_this.currentWidth = 1;
|
|
3388
|
+
_this.currentHeight = 1;
|
|
3389
|
+
_this.canvascontaineroutside = null;
|
|
3390
|
+
_this.canvascontainer = null;
|
|
3391
|
+
_this.timer = null;
|
|
3392
|
+
_this.redrawTimer = null;
|
|
3393
|
+
_this.loopHasStarted = false;
|
|
3394
|
+
_this.mounted = false;
|
|
3395
|
+
_this.updateCanvas = _this.updateCanvas.bind(_assertThisInitialized(_this));
|
|
3396
|
+
_this.handleMouseMoveEvent = _this.handleMouseMoveEvent.bind(_assertThisInitialized(_this));
|
|
3397
|
+
_this.handleMouseUpEvent = _this.handleMouseUpEvent.bind(_assertThisInitialized(_this));
|
|
3398
|
+
_this.handleMouseDownEvent = _this.handleMouseDownEvent.bind(_assertThisInitialized(_this));
|
|
3399
|
+
_this.resize = _this.resize.bind(_assertThisInitialized(_this));
|
|
3400
|
+
_this._handleWindowResize = _this._handleWindowResize.bind(_assertThisInitialized(_this));
|
|
3401
|
+
_this.handleClickEvent = _this.handleClickEvent.bind(_assertThisInitialized(_this));
|
|
3402
|
+
_this.handleWheelEvent = _this.handleWheelEvent.bind(_assertThisInitialized(_this));
|
|
3403
|
+
_this.handleTouchStartEvent = _this.handleTouchStartEvent.bind(_assertThisInitialized(_this));
|
|
3404
|
+
_this.handleTouchEndEvent = _this.handleTouchEndEvent.bind(_assertThisInitialized(_this));
|
|
3405
|
+
_this.handleTouchMoveEvent = _this.handleTouchMoveEvent.bind(_assertThisInitialized(_this));
|
|
3406
|
+
_this.onKeyUp = _this.onKeyUp.bind(_assertThisInitialized(_this));
|
|
3407
|
+
_this.onBlur = _this.onBlur.bind(_assertThisInitialized(_this));
|
|
3408
|
+
_this.onFocus = _this.onFocus.bind(_assertThisInitialized(_this));
|
|
3409
|
+
_this.startLoop = _this.startLoop.bind(_assertThisInitialized(_this));
|
|
3410
|
+
_this._documentKeyDown = _this._documentKeyDown.bind(_assertThisInitialized(_this));
|
|
3411
|
+
_this._isFocussed = false;
|
|
3412
|
+
_this.canvas = null;
|
|
3413
|
+
_this.canvascontaineroutside = /*#__PURE__*/React__default.createRef();
|
|
3414
|
+
_this.canvascontainer = /*#__PURE__*/React__default.createRef();
|
|
3415
|
+
return _this;
|
|
3416
|
+
}
|
|
3417
|
+
_createClass(CanvasComponent, [{
|
|
3418
|
+
key: "componentDidMount",
|
|
3419
|
+
value: function componentDidMount() {
|
|
3420
|
+
var _this2 = this;
|
|
3421
|
+
this.mounted = true;
|
|
3422
|
+
if (this.canvas) {
|
|
3423
|
+
this.canvas.addEventListener('mousemove', this.handleMouseMoveEvent);
|
|
3424
|
+
this.canvas.addEventListener('mouseup', this.handleMouseUpEvent);
|
|
3425
|
+
this.canvas.addEventListener('mousedown', this.handleMouseDownEvent);
|
|
3426
|
+
this.canvas.addEventListener('touchstart', this.handleTouchStartEvent);
|
|
3427
|
+
this.canvas.addEventListener('touchend', this.handleTouchEndEvent);
|
|
3428
|
+
this.canvas.addEventListener('touchmove', this.handleTouchMoveEvent);
|
|
3429
|
+
this.canvas.addEventListener('wheel', this.handleWheelEvent);
|
|
3430
|
+
this.canvas.addEventListener('click', this.handleClickEvent);
|
|
3431
|
+
document.addEventListener('keydown', this._documentKeyDown, false);
|
|
3432
|
+
this.resize();
|
|
3433
|
+
this.updateCanvas();
|
|
3434
|
+
}
|
|
3435
|
+
var _this$props = this.props,
|
|
3436
|
+
onKeyUp = _this$props.onKeyUp,
|
|
3437
|
+
loopInterval = _this$props.redrawInterval;
|
|
3438
|
+
if (onKeyUp) {
|
|
3439
|
+
window.addEventListener('keyup', this.onKeyUp);
|
|
3440
|
+
}
|
|
3441
|
+
window.addEventListener('resize', this._handleWindowResize);
|
|
3442
|
+
if (this.canvascontaineroutside && this.canvascontaineroutside.current && onKeyUp) {
|
|
3443
|
+
this.canvascontaineroutside.current.focus();
|
|
3444
|
+
}
|
|
3445
|
+
this.timer = setInterval(function () {
|
|
3446
|
+
_this2.resize();
|
|
3447
|
+
}, 1000);
|
|
3448
|
+
if (loopInterval) {
|
|
3449
|
+
this.redrawTimer = setInterval(function () {
|
|
3450
|
+
_this2.updateCanvas();
|
|
3451
|
+
}, loopInterval);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
}, {
|
|
3455
|
+
key: "shouldComponentUpdate",
|
|
3456
|
+
value: function shouldComponentUpdate() {
|
|
3457
|
+
var _this3 = this;
|
|
3458
|
+
window.requestAnimationFrame(function () {
|
|
3459
|
+
_this3.updateCanvas();
|
|
3460
|
+
});
|
|
3461
|
+
return false;
|
|
3462
|
+
}
|
|
3463
|
+
}, {
|
|
3464
|
+
key: "componentWillUnmount",
|
|
3465
|
+
value: function componentWillUnmount() {
|
|
3466
|
+
this.mounted = false;
|
|
3467
|
+
window.removeEventListener('resize', this._handleWindowResize);
|
|
3468
|
+
var onKeyUp = this.props.onKeyUp;
|
|
3469
|
+
if (onKeyUp) {
|
|
3470
|
+
window.removeEventListener('keyup', this.onKeyUp);
|
|
3471
|
+
}
|
|
3472
|
+
if (this.canvas) {
|
|
3473
|
+
this.canvas.removeEventListener('mousedown', this.handleMouseDownEvent);
|
|
3474
|
+
this.canvas.removeEventListener('mouseup', this.handleMouseUpEvent);
|
|
3475
|
+
this.canvas.removeEventListener('mousemove', this.handleMouseMoveEvent);
|
|
3476
|
+
this.canvas.removeEventListener('touchstart', this.handleTouchStartEvent);
|
|
3477
|
+
this.canvas.removeEventListener('touchend', this.handleTouchEndEvent);
|
|
3478
|
+
this.canvas.removeEventListener('touchmove', this.handleTouchMoveEvent);
|
|
3479
|
+
this.canvas.removeEventListener('wheel', this.handleWheelEvent);
|
|
3480
|
+
this.canvas.removeEventListener('click', this.handleClickEvent);
|
|
3481
|
+
document.removeEventListener('keydown', this._documentKeyDown);
|
|
3482
|
+
}
|
|
3483
|
+
clearInterval(this.timer);
|
|
3484
|
+
clearInterval(this.redrawTimer);
|
|
3485
|
+
}
|
|
3486
|
+
}, {
|
|
3487
|
+
key: "handleMouseMoveEvent",
|
|
3488
|
+
value: function handleMouseMoveEvent(event) {
|
|
3489
|
+
var _this$props2 = this.props,
|
|
3490
|
+
onMouseMove = _this$props2.onMouseMove,
|
|
3491
|
+
onCanvasClick = _this$props2.onCanvasClick;
|
|
3492
|
+
var x = event.offsetX;
|
|
3493
|
+
var y = event.offsetY;
|
|
3494
|
+
if (event.buttons === 1) {
|
|
3495
|
+
onCanvasClick(x, y, this.currentWidth, this.currentHeight);
|
|
3496
|
+
}
|
|
3497
|
+
onMouseMove(x, y, event, this.currentWidth);
|
|
3498
|
+
}
|
|
3499
|
+
}, {
|
|
3500
|
+
key: "handleMouseUpEvent",
|
|
3501
|
+
value: function handleMouseUpEvent(event) {
|
|
3502
|
+
var onMouseUp = this.props.onMouseUp;
|
|
3503
|
+
var x = event.offsetX;
|
|
3504
|
+
onMouseUp(x);
|
|
3505
|
+
}
|
|
3506
|
+
}, {
|
|
3507
|
+
key: "handleMouseDownEvent",
|
|
3508
|
+
value: function handleMouseDownEvent(event) {
|
|
3509
|
+
var onMouseDown = this.props.onMouseDown;
|
|
3510
|
+
var x = event.offsetX;
|
|
3511
|
+
var y = event.offsetY;
|
|
3512
|
+
onMouseDown(x, y, this.currentWidth);
|
|
3513
|
+
}
|
|
3514
|
+
}, {
|
|
3515
|
+
key: "handleTouchStartEvent",
|
|
3516
|
+
value: function handleTouchStartEvent(event) {
|
|
3517
|
+
var onTouchStart = this.props.onTouchStart;
|
|
3518
|
+
onTouchStart(event, this.currentWidth);
|
|
3519
|
+
}
|
|
3520
|
+
}, {
|
|
3521
|
+
key: "handleTouchEndEvent",
|
|
3522
|
+
value: function handleTouchEndEvent() {
|
|
3523
|
+
var onTouchEnd = this.props.onTouchEnd;
|
|
3524
|
+
onTouchEnd();
|
|
3525
|
+
}
|
|
3526
|
+
}, {
|
|
3527
|
+
key: "handleTouchMoveEvent",
|
|
3528
|
+
value: function handleTouchMoveEvent(event) {
|
|
3529
|
+
var _this$props3 = this.props,
|
|
3530
|
+
onTouchMove = _this$props3.onTouchMove,
|
|
3531
|
+
onCanvasClick = _this$props3.onCanvasClick;
|
|
3532
|
+
var touches = event && event.touches && event.touches[0];
|
|
3533
|
+
if (touches && touches.clientX && touches.clientY) {
|
|
3534
|
+
var x2 = event.touches[0].clientX - event.touches[0].target.offsetLeft;
|
|
3535
|
+
var y2 = event.touches[0].clientY;
|
|
3536
|
+
onCanvasClick(x2, y2, this.currentWidth, this.currentHeight);
|
|
3537
|
+
}
|
|
3538
|
+
onTouchMove(event, this.currentWidth);
|
|
3539
|
+
}
|
|
3540
|
+
}, {
|
|
3541
|
+
key: "handleClickEvent",
|
|
3542
|
+
value: function handleClickEvent(event) {
|
|
3543
|
+
var onCanvasClick = this.props.onCanvasClick;
|
|
3544
|
+
var x = event.offsetX;
|
|
3545
|
+
var y = event.offsetY;
|
|
3546
|
+
onCanvasClick(x, y, this.currentWidth, this.currentHeight);
|
|
3547
|
+
}
|
|
3548
|
+
}, {
|
|
3549
|
+
key: "handleWheelEvent",
|
|
3550
|
+
value: function handleWheelEvent(event) {
|
|
3551
|
+
var onWheel = this.props.onWheel;
|
|
3552
|
+
onWheel({
|
|
3553
|
+
event: event,
|
|
3554
|
+
deltaY: event.deltaY,
|
|
3555
|
+
deltaX: event.deltaX,
|
|
3556
|
+
canvasWidth: event.srcElement.width,
|
|
3557
|
+
mouseX: event.offsetX
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
}, {
|
|
3561
|
+
key: "onFocus",
|
|
3562
|
+
value: function onFocus() {
|
|
3563
|
+
var isFocussed = this.props.isFocussed;
|
|
3564
|
+
this._isFocussed = true;
|
|
3565
|
+
if (isFocussed) {
|
|
3566
|
+
isFocussed(true);
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
}, {
|
|
3570
|
+
key: "onBlur",
|
|
3571
|
+
value: function onBlur() {
|
|
3572
|
+
var isFocussed = this.props.isFocussed;
|
|
3573
|
+
this._isFocussed = false;
|
|
3574
|
+
if (isFocussed) {
|
|
3575
|
+
isFocussed(false);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}, {
|
|
3579
|
+
key: "onKeyUp",
|
|
3580
|
+
value: function onKeyUp(event) {
|
|
3581
|
+
var onKeyUp = this.props.onKeyUp;
|
|
3582
|
+
if (onKeyUp) {
|
|
3583
|
+
onKeyUp(event);
|
|
3584
|
+
}
|
|
3585
|
+
if (this.canvascontaineroutside && this.canvascontaineroutside.current && onKeyUp) {
|
|
3586
|
+
if (event.code === 'Escape') {
|
|
3587
|
+
this.canvascontaineroutside.current.focus();
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
}, {
|
|
3592
|
+
key: "_documentKeyDown",
|
|
3593
|
+
value: function _documentKeyDown(event) {
|
|
3594
|
+
if (this._isFocussed) {
|
|
3595
|
+
var onKeyDown = this.props.onKeyDown;
|
|
3596
|
+
if (onKeyDown) {
|
|
3597
|
+
onKeyDown(event);
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
}, {
|
|
3602
|
+
key: "_handleWindowResize",
|
|
3603
|
+
value: function _handleWindowResize() {
|
|
3604
|
+
this.resize();
|
|
3605
|
+
}
|
|
3606
|
+
}, {
|
|
3607
|
+
key: "startLoop",
|
|
3608
|
+
value: function startLoop() {
|
|
3609
|
+
var onRenderCanvas = this.props.onRenderCanvas;
|
|
3610
|
+
if (this.mounted === false || this.loopHasStarted === false) {
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
if (this.canvas) {
|
|
3614
|
+
onRenderCanvas(this.ctx, this.currentWidth, this.currentHeight, this.canvas);
|
|
3615
|
+
}
|
|
3616
|
+
requestAnimationFrame(this.startLoop);
|
|
3617
|
+
}
|
|
3618
|
+
}, {
|
|
3619
|
+
key: "updateCanvas",
|
|
3620
|
+
value: function updateCanvas() {
|
|
3621
|
+
if (!this.canvas) {
|
|
3622
|
+
return;
|
|
3623
|
+
}
|
|
3624
|
+
var _this$props4 = this.props,
|
|
3625
|
+
onRenderCanvas = _this$props4.onRenderCanvas,
|
|
3626
|
+
loop = _this$props4.loop;
|
|
3627
|
+
this.ctx = this.canvas.getContext('2d');
|
|
3628
|
+
if (!this.ctx) {
|
|
3629
|
+
return;
|
|
3630
|
+
}
|
|
3631
|
+
if (this.ctx.canvas.height !== this.currentHeight) {
|
|
3632
|
+
this.ctx.canvas.height = this.currentHeight;
|
|
3633
|
+
}
|
|
3634
|
+
if (this.ctx.canvas.width !== this.currentWidth) {
|
|
3635
|
+
this.ctx.canvas.width = this.currentWidth;
|
|
3636
|
+
}
|
|
3637
|
+
if (loop !== true) {
|
|
3638
|
+
this.loopHasStarted = false;
|
|
3639
|
+
onRenderCanvas(this.ctx, this.currentWidth, this.currentHeight, this.canvas);
|
|
3640
|
+
} else if (this.loopHasStarted === false) {
|
|
3641
|
+
this.loopHasStarted = true;
|
|
3642
|
+
this.startLoop();
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
}, {
|
|
3646
|
+
key: "resize",
|
|
3647
|
+
value: function resize() {
|
|
3648
|
+
var canvascontainer = this.canvascontainer,
|
|
3649
|
+
resizeCallback = this.props.resizeCallback;
|
|
3650
|
+
if (canvascontainer && canvascontainer.current) {
|
|
3651
|
+
var newWidth = canvascontainer.current.clientWidth;
|
|
3652
|
+
var newHeight = canvascontainer.current.clientHeight;
|
|
3653
|
+
if (newWidth !== undefined && newHeight !== undefined && (this.currentWidth !== newWidth || this.currentHeight !== newHeight)) {
|
|
3654
|
+
this.currentWidth = newWidth;
|
|
3655
|
+
this.currentHeight = newHeight;
|
|
3656
|
+
this.updateCanvas();
|
|
3657
|
+
resizeCallback && resizeCallback(newWidth);
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
}, {
|
|
3662
|
+
key: "render",
|
|
3663
|
+
value: function render() {
|
|
3664
|
+
var _this4 = this;
|
|
3665
|
+
this.updateCanvas();
|
|
3666
|
+
this._handleWindowResize();
|
|
3667
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
3668
|
+
role: "button",
|
|
3669
|
+
ref: this.canvascontaineroutside,
|
|
3670
|
+
tabIndex: 0,
|
|
3671
|
+
onFocus: this.onFocus,
|
|
3672
|
+
onBlur: this.onBlur,
|
|
3673
|
+
style: {
|
|
3674
|
+
height: '100%',
|
|
3675
|
+
width: '100%',
|
|
3676
|
+
border: 'none',
|
|
3677
|
+
display: 'block',
|
|
3678
|
+
overflow: 'hidden'
|
|
3679
|
+
}
|
|
3680
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
3681
|
+
ref: this.canvascontainer,
|
|
3682
|
+
style: {
|
|
3683
|
+
minWidth: 'inherit',
|
|
3684
|
+
minHeight: 'inherit',
|
|
3685
|
+
width: 'inherit',
|
|
3686
|
+
height: 'inherit',
|
|
3687
|
+
overflow: 'hidden',
|
|
3688
|
+
display: 'block',
|
|
3689
|
+
border: 'none'
|
|
3690
|
+
},
|
|
3691
|
+
"data-testid": "canvas-container"
|
|
3692
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
3693
|
+
style: {
|
|
3694
|
+
overflow: 'visible',
|
|
3695
|
+
width: 0,
|
|
3696
|
+
height: 0
|
|
3697
|
+
},
|
|
3698
|
+
role: "presentation",
|
|
3699
|
+
"aria-label": "canvas"
|
|
3700
|
+
}, /*#__PURE__*/React__default.createElement("canvas", {
|
|
3701
|
+
ref: function ref(canvas) {
|
|
3702
|
+
_this4.canvas = canvas;
|
|
3703
|
+
}
|
|
3704
|
+
}))));
|
|
3705
|
+
}
|
|
3706
|
+
}]);
|
|
3707
|
+
return CanvasComponent;
|
|
3708
|
+
}(Component);
|
|
3709
|
+
CanvasComponent.defaultProps = {
|
|
3710
|
+
onRenderCanvas: function onRenderCanvas() {
|
|
3711
|
+
/* intentionally left blank */
|
|
3712
|
+
},
|
|
3713
|
+
onCanvasClick: function onCanvasClick() {
|
|
3714
|
+
/* intentionally left blank */
|
|
3715
|
+
},
|
|
3716
|
+
onMouseMove: function onMouseMove() {
|
|
3717
|
+
/* intentionally left blank */
|
|
3718
|
+
},
|
|
3719
|
+
onMouseUp: function onMouseUp() {
|
|
3720
|
+
/* intentionally left blank */
|
|
3721
|
+
},
|
|
3722
|
+
onMouseDown: function onMouseDown() {
|
|
3723
|
+
/* intentionally left blank */
|
|
3724
|
+
},
|
|
3725
|
+
onTouchStart: function onTouchStart() {
|
|
3726
|
+
/* intentionally left blank */
|
|
3727
|
+
},
|
|
3728
|
+
onTouchEnd: function onTouchEnd() {
|
|
3729
|
+
/* intentionally left blank */
|
|
3730
|
+
},
|
|
3731
|
+
onTouchMove: function onTouchMove() {
|
|
3732
|
+
/* intentionally left blank */
|
|
3733
|
+
},
|
|
3734
|
+
onWheel: function onWheel() {
|
|
3735
|
+
/* intentionally left blank */
|
|
3736
|
+
}
|
|
3737
|
+
};
|
|
3738
|
+
|
|
3319
3739
|
/* *
|
|
3320
3740
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3321
3741
|
* you may not use this file except in compliance with the License.
|
|
@@ -3441,7 +3861,13 @@ var getWarningMessage = function getWarningMessage(error) {
|
|
|
3441
3861
|
*/
|
|
3442
3862
|
var isoStringToDate = function isoStringToDate(input) {
|
|
3443
3863
|
var utc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
3864
|
+
if (!input) {
|
|
3865
|
+
return undefined;
|
|
3866
|
+
}
|
|
3444
3867
|
var parsed = parseISO(input);
|
|
3868
|
+
if (!isValid(parsed)) {
|
|
3869
|
+
return undefined;
|
|
3870
|
+
}
|
|
3445
3871
|
if (utc) {
|
|
3446
3872
|
return setUTCDate(parsed);
|
|
3447
3873
|
}
|
|
@@ -3465,12 +3891,24 @@ var isoStringToDate = function isoStringToDate(input) {
|
|
|
3465
3891
|
var stringToDate = function stringToDate(input, strFormat) {
|
|
3466
3892
|
var utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
3467
3893
|
var referenceDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Date();
|
|
3894
|
+
if (!input) {
|
|
3895
|
+
return undefined;
|
|
3896
|
+
}
|
|
3468
3897
|
var parsed = parse(input, strFormat, referenceDate);
|
|
3898
|
+
if (!isValid(parsed)) {
|
|
3899
|
+
return undefined;
|
|
3900
|
+
}
|
|
3469
3901
|
if (utc) {
|
|
3470
3902
|
return setUTCDate(parsed);
|
|
3471
3903
|
}
|
|
3472
3904
|
return parsed;
|
|
3473
3905
|
};
|
|
3906
|
+
var dateToIsoString = function dateToIsoString(input) {
|
|
3907
|
+
if (!input || !isValid(input)) {
|
|
3908
|
+
return undefined;
|
|
3909
|
+
}
|
|
3910
|
+
return input.toISOString();
|
|
3911
|
+
};
|
|
3474
3912
|
/**
|
|
3475
3913
|
* Use this if you initialise a date without a timezone to set it to utc correctly
|
|
3476
3914
|
* eg.
|
|
@@ -3486,6 +3924,9 @@ var stringToDate = function stringToDate(input, strFormat) {
|
|
|
3486
3924
|
* ``` setUTCDate(new Date(2022, 10, 12, 15, 30)) ```
|
|
3487
3925
|
*/
|
|
3488
3926
|
var setUTCDate = function setUTCDate(inDate) {
|
|
3927
|
+
if (!inDate || !isValid(inDate)) {
|
|
3928
|
+
return undefined;
|
|
3929
|
+
}
|
|
3489
3930
|
var utcDate = new Date(inDate);
|
|
3490
3931
|
utcDate.setUTCFullYear(inDate.getFullYear(), inDate.getMonth(), inDate.getDate());
|
|
3491
3932
|
utcDate.setUTCHours(inDate.getHours(), inDate.getMinutes(), inDate.getSeconds(), inDate.getMilliseconds());
|
|
@@ -3506,10 +3947,11 @@ var setUTCDate = function setUTCDate(inDate) {
|
|
|
3506
3947
|
var dateToString = function dateToString(inDate) {
|
|
3507
3948
|
var strFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
|
3508
3949
|
var utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
3509
|
-
if (
|
|
3510
|
-
return
|
|
3950
|
+
if (!inDate || !isValid(inDate)) {
|
|
3951
|
+
return undefined;
|
|
3511
3952
|
}
|
|
3512
|
-
|
|
3953
|
+
var formattedDate = utc ? format(new Date(inDate.getUTCFullYear(), inDate.getUTCMonth(), inDate.getUTCDate(), inDate.getUTCHours(), inDate.getUTCMinutes(), inDate.getUTCSeconds()), strFormat) : format(inDate, strFormat);
|
|
3954
|
+
return formattedDate;
|
|
3513
3955
|
};
|
|
3514
3956
|
/**
|
|
3515
3957
|
* Find out if a date is between two other dates.
|
|
@@ -3585,6 +4027,36 @@ var add = function add(date, duration) {
|
|
|
3585
4027
|
var sub = function sub(date, duration) {
|
|
3586
4028
|
return sub$1(date, duration);
|
|
3587
4029
|
};
|
|
4030
|
+
/**
|
|
4031
|
+
* Finds the number of years between to dates
|
|
4032
|
+
*
|
|
4033
|
+
* @param dateLeft - the later date
|
|
4034
|
+
* @param dateRight - the earlier date
|
|
4035
|
+
* @returns {number} the number of minutes
|
|
4036
|
+
*/
|
|
4037
|
+
var differenceInYears = function differenceInYears(dateLeft, dateRight) {
|
|
4038
|
+
return differenceInYears$1(dateLeft, dateRight);
|
|
4039
|
+
};
|
|
4040
|
+
/**
|
|
4041
|
+
* Finds the number of months between to dates
|
|
4042
|
+
*
|
|
4043
|
+
* @param dateLeft - the later date
|
|
4044
|
+
* @param dateRight - the earlier date
|
|
4045
|
+
* @returns {number} the number of minutes
|
|
4046
|
+
*/
|
|
4047
|
+
var differenceInMonths = function differenceInMonths(dateLeft, dateRight) {
|
|
4048
|
+
return differenceInMonths$1(dateLeft, dateRight);
|
|
4049
|
+
};
|
|
4050
|
+
/**
|
|
4051
|
+
* Finds the number of days between to dates
|
|
4052
|
+
*
|
|
4053
|
+
* @param dateLeft - the later date
|
|
4054
|
+
* @param dateRight - the earlier date
|
|
4055
|
+
* @returns {number} the number of minutes
|
|
4056
|
+
*/
|
|
4057
|
+
var differenceInDays = function differenceInDays(dateLeft, dateRight) {
|
|
4058
|
+
return differenceInDays$1(dateLeft, dateRight);
|
|
4059
|
+
};
|
|
3588
4060
|
/**
|
|
3589
4061
|
* Finds the number of minuts between to dates
|
|
3590
4062
|
*
|
|
@@ -3607,6 +4079,16 @@ var differenceInHours = function differenceInHours(dateLeft, dateRight, rounding
|
|
|
3607
4079
|
roundingMethod: roundingMethod
|
|
3608
4080
|
}) : differenceInHours$1(dateLeft, dateRight);
|
|
3609
4081
|
};
|
|
4082
|
+
/**
|
|
4083
|
+
* Finds the number of seconds between to dates
|
|
4084
|
+
*
|
|
4085
|
+
* @param dateLeft - the later date
|
|
4086
|
+
* @param dateRight - the earlier date
|
|
4087
|
+
* @returns {number} the number of minutes
|
|
4088
|
+
*/
|
|
4089
|
+
var differenceInSeconds = function differenceInSeconds(dateLeft, dateRight) {
|
|
4090
|
+
return differenceInSeconds$1(dateLeft, dateRight);
|
|
4091
|
+
};
|
|
3610
4092
|
/**
|
|
3611
4093
|
*
|
|
3612
4094
|
* @param date - the date that should be before the other one to return true
|
|
@@ -3629,14 +4111,29 @@ var isAfter = function isAfter(date, dateToCompare) {
|
|
|
3629
4111
|
return isAfter$1(date, dateToCompare);
|
|
3630
4112
|
};
|
|
3631
4113
|
/**
|
|
3632
|
-
*
|
|
4114
|
+
* Gracefully parsing string to a date, setting tz to UTC even if it's missing or input is invalid
|
|
4115
|
+
* Note: use getUtcFromString() to convert a string to a date with stricter returns
|
|
3633
4116
|
* @param dateStr - string containing date
|
|
3634
|
-
* @returns {Date} - Date in UTC
|
|
4117
|
+
* @returns {Date} - Date in UTC, or current date when something invalid is passed.
|
|
3635
4118
|
*/
|
|
3636
4119
|
var utc = function utc(dateStr) {
|
|
3637
|
-
if (dateStr
|
|
4120
|
+
if (!dateStr) {
|
|
3638
4121
|
return createDate();
|
|
3639
4122
|
}
|
|
4123
|
+
if (hasOffset(dateStr)) {
|
|
4124
|
+
return isoStringToDate(dateStr, false) || createDate();
|
|
4125
|
+
}
|
|
4126
|
+
return isoStringToDate(dateStr) || createDate();
|
|
4127
|
+
};
|
|
4128
|
+
/**
|
|
4129
|
+
* Parsing string to a date. Stricter check, will return undefined when dateString is invalid.
|
|
4130
|
+
* @param dateStr - string containing date
|
|
4131
|
+
* @returns {Date} - Date in UTC, undefined when not valid
|
|
4132
|
+
*/
|
|
4133
|
+
var getUtcFromString = function getUtcFromString(dateStr) {
|
|
4134
|
+
if (!dateStr) {
|
|
4135
|
+
return undefined;
|
|
4136
|
+
}
|
|
3640
4137
|
if (hasOffset(dateStr)) {
|
|
3641
4138
|
return isoStringToDate(dateStr, false);
|
|
3642
4139
|
}
|
|
@@ -3652,7 +4149,7 @@ var getOffsetStr = function getOffsetStr(input) {
|
|
|
3652
4149
|
};
|
|
3653
4150
|
/**
|
|
3654
4151
|
* Check if a date object is valid
|
|
3655
|
-
* @param {Date} date - date to be checked
|
|
4152
|
+
* @param {Date | number} date - date to be checked
|
|
3656
4153
|
* @returns {boolean} - True if valid
|
|
3657
4154
|
*/
|
|
3658
4155
|
var isValid = function isValid(date) {
|
|
@@ -3695,6 +4192,25 @@ var parseCustomDateString = function parseCustomDateString(dateStr) {
|
|
|
3695
4192
|
}
|
|
3696
4193
|
return new Date(dateStr);
|
|
3697
4194
|
};
|
|
4195
|
+
/**
|
|
4196
|
+
* Returns Date in UTC
|
|
4197
|
+
* @returns {Date} - Date in UTC
|
|
4198
|
+
*/
|
|
4199
|
+
var getNowUtc = function getNowUtc() {
|
|
4200
|
+
return createDate();
|
|
4201
|
+
};
|
|
4202
|
+
/**
|
|
4203
|
+
* Returns current time as string
|
|
4204
|
+
* @param {string} strFormat - [default: "yyyy-MM-dd'T'HH:mm:ss'Z'"] format of string
|
|
4205
|
+
* @param {boolean} utc - [default: true] true to return in utc otherwise return in local timezone
|
|
4206
|
+
*
|
|
4207
|
+
* @returns {string} - formatted date string
|
|
4208
|
+
*/
|
|
4209
|
+
var getCurrentTimeAsString = function getCurrentTimeAsString() {
|
|
4210
|
+
var strFormat = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
|
4211
|
+
var utc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
4212
|
+
return dateToString(getNowUtc(), strFormat, utc);
|
|
4213
|
+
};
|
|
3698
4214
|
/**
|
|
3699
4215
|
* Set date values to a given date (by default it is assumed you are passing the new values in UTC).
|
|
3700
4216
|
* @param date - the dater to be changed
|
|
@@ -3753,25 +4269,34 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3753
4269
|
__proto__: null,
|
|
3754
4270
|
isoStringToDate: isoStringToDate,
|
|
3755
4271
|
stringToDate: stringToDate,
|
|
4272
|
+
dateToIsoString: dateToIsoString,
|
|
3756
4273
|
setUTCDate: setUTCDate,
|
|
3757
4274
|
dateToString: dateToString,
|
|
3758
4275
|
isBetween: isBetween,
|
|
3759
4276
|
createDate: createDate,
|
|
3760
4277
|
add: add,
|
|
3761
4278
|
sub: sub,
|
|
4279
|
+
differenceInYears: differenceInYears,
|
|
4280
|
+
differenceInMonths: differenceInMonths,
|
|
4281
|
+
differenceInDays: differenceInDays,
|
|
3762
4282
|
differenceInMinutes: differenceInMinutes,
|
|
3763
4283
|
differenceInHours: differenceInHours,
|
|
4284
|
+
differenceInSeconds: differenceInSeconds,
|
|
3764
4285
|
isBefore: isBefore,
|
|
3765
4286
|
isAfter: isAfter,
|
|
3766
4287
|
utc: utc,
|
|
4288
|
+
getUtcFromString: getUtcFromString,
|
|
3767
4289
|
isValid: isValid,
|
|
3768
4290
|
unix: unix,
|
|
3769
4291
|
fromUnix: fromUnix,
|
|
3770
4292
|
parseCustomDateString: parseCustomDateString,
|
|
4293
|
+
getNowUtc: getNowUtc,
|
|
4294
|
+
getCurrentTimeAsString: getCurrentTimeAsString,
|
|
3771
4295
|
set: set,
|
|
3772
4296
|
isEqual: isEqual,
|
|
3773
4297
|
startOfDay: startOfDay,
|
|
3774
|
-
parseISO: parseISO
|
|
4298
|
+
parseISO: parseISO,
|
|
4299
|
+
isWithinInterval: isWithinInterval
|
|
3775
4300
|
});
|
|
3776
4301
|
|
|
3777
4302
|
/* *
|
|
@@ -3815,33 +4340,6 @@ var createToolkitMockStoreWithEggs = function createToolkitMockStoreWithEggs(sto
|
|
|
3815
4340
|
return store;
|
|
3816
4341
|
};
|
|
3817
4342
|
|
|
3818
|
-
/* *
|
|
3819
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3820
|
-
* you may not use this file except in compliance with the License.
|
|
3821
|
-
* You may obtain a copy of the License at
|
|
3822
|
-
*
|
|
3823
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3824
|
-
*
|
|
3825
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3826
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3827
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3828
|
-
* See the License for the specific language governing permissions and
|
|
3829
|
-
* limitations under the License.
|
|
3830
|
-
*
|
|
3831
|
-
* Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
3832
|
-
* Copyright 2023 - Finnish Meteorological Institute (FMI)
|
|
3833
|
-
* */
|
|
3834
|
-
// TODO: Move to related component when doing this user story: https://gitlab.com/opengeoweb/geoweb-assets/-/issues/2955
|
|
3835
|
-
var getHeight = function getHeight(element) {
|
|
3836
|
-
if (!element) {
|
|
3837
|
-
return null;
|
|
3838
|
-
}
|
|
3839
|
-
var style = getComputedStyle(element);
|
|
3840
|
-
var marginTop = style.marginTop ? parseInt(style.marginTop, 10) : 0;
|
|
3841
|
-
var marginBottom = style.marginTop ? parseInt(style.marginBottom, 10) : 0;
|
|
3842
|
-
return element.offsetHeight + marginTop + marginBottom;
|
|
3843
|
-
};
|
|
3844
|
-
|
|
3845
4343
|
/* *
|
|
3846
4344
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3847
4345
|
* you may not use this file except in compliance with the License.
|
|
@@ -3900,4 +4398,253 @@ var RenderCounter = /*#__PURE__*/function () {
|
|
|
3900
4398
|
}();
|
|
3901
4399
|
var renderCounter = new RenderCounter();
|
|
3902
4400
|
|
|
3903
|
-
|
|
4401
|
+
/* *
|
|
4402
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4403
|
+
* you may not use this file except in compliance with the License.
|
|
4404
|
+
* You may obtain a copy of the License at
|
|
4405
|
+
*
|
|
4406
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4407
|
+
*
|
|
4408
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4409
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4410
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4411
|
+
* See the License for the specific language governing permissions and
|
|
4412
|
+
* limitations under the License.
|
|
4413
|
+
*
|
|
4414
|
+
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
4415
|
+
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
4416
|
+
* */
|
|
4417
|
+
/**
|
|
4418
|
+
* This class should NEVER be initialized with new Metronome(). Use the
|
|
4419
|
+
* exported variable. To reset the metronome use unregisterAllTimers()
|
|
4420
|
+
* to remove all existing timers followed by init() to initialize the
|
|
4421
|
+
* ticks.
|
|
4422
|
+
*/
|
|
4423
|
+
var Metronome = /*#__PURE__*/function () {
|
|
4424
|
+
function Metronome() {
|
|
4425
|
+
_classCallCheck(this, Metronome);
|
|
4426
|
+
this.tickId = 0;
|
|
4427
|
+
this.step = this.step.bind(this);
|
|
4428
|
+
this.isPaused = this.isPaused.bind(this);
|
|
4429
|
+
this.continueTimer = this.continueTimer.bind(this);
|
|
4430
|
+
this.pauseTimer = this.pauseTimer.bind(this);
|
|
4431
|
+
this.toggleTimer = this.toggleTimer.bind(this);
|
|
4432
|
+
this.init = this.init.bind(this);
|
|
4433
|
+
this.unregisterAllTimers = this.unregisterAllTimers.bind(this);
|
|
4434
|
+
this.setSpeed = this.setSpeed.bind(this);
|
|
4435
|
+
this.interval = null;
|
|
4436
|
+
this.init();
|
|
4437
|
+
this.handleTimerTicks = null;
|
|
4438
|
+
this.timers = [];
|
|
4439
|
+
}
|
|
4440
|
+
_createClass(Metronome, [{
|
|
4441
|
+
key: "init",
|
|
4442
|
+
value: function init() {
|
|
4443
|
+
if (this.interval != null) {
|
|
4444
|
+
clearInterval(this.interval);
|
|
4445
|
+
}
|
|
4446
|
+
this.interval = setInterval(this.step, 10);
|
|
4447
|
+
}
|
|
4448
|
+
}, {
|
|
4449
|
+
key: "unregisterAllTimers",
|
|
4450
|
+
value: function unregisterAllTimers() {
|
|
4451
|
+
this.timers.length = 0;
|
|
4452
|
+
}
|
|
4453
|
+
}, {
|
|
4454
|
+
key: "step",
|
|
4455
|
+
value: function step() {
|
|
4456
|
+
var _this = this;
|
|
4457
|
+
this.tickId += 1;
|
|
4458
|
+
var triggeredTimerIds = [];
|
|
4459
|
+
this.timers.forEach(function (timer) {
|
|
4460
|
+
// Delay in x10 ms
|
|
4461
|
+
var delay = 100 / timer.hertz;
|
|
4462
|
+
// Get nearest multiple of delay
|
|
4463
|
+
var nearestDelay = delay * Math.floor((_this.tickId + delay / 2) / delay);
|
|
4464
|
+
var distanceToDelay = _this.tickId - nearestDelay;
|
|
4465
|
+
if (Math.abs(distanceToDelay) < 0.5 || distanceToDelay === -0.5) {
|
|
4466
|
+
if (!timer.isPaused) {
|
|
4467
|
+
timer.timerFunc && timer.timerFunc(timer.timerId, _this.tickId);
|
|
4468
|
+
triggeredTimerIds.push(timer.timerId);
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4471
|
+
});
|
|
4472
|
+
// Trigger the handleTimerTicks function with all collected timerIds
|
|
4473
|
+
if (triggeredTimerIds.length > 0) {
|
|
4474
|
+
this.handleTimerTicks && this.handleTimerTicks(triggeredTimerIds);
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
/**
|
|
4478
|
+
* Multiple timers with varying frequencies can be made at the same
|
|
4479
|
+
* time however each timerId must be unique. If you attempt to create
|
|
4480
|
+
* two timers with the same timerId, the second will silently be ignored.
|
|
4481
|
+
*
|
|
4482
|
+
* @param timerFunc The function to be executed at the given hertz frequency
|
|
4483
|
+
* @param hertz Frequency of the timer given in hertz
|
|
4484
|
+
* @param timerId Id of the timer
|
|
4485
|
+
* @returns Timer or nothing if no timer was created
|
|
4486
|
+
*/
|
|
4487
|
+
}, {
|
|
4488
|
+
key: "register",
|
|
4489
|
+
value: function register(timerFunc, hertz, timerId) {
|
|
4490
|
+
var existingTimer = this.timers.find(function (timer) {
|
|
4491
|
+
return timer.timerId === timerId;
|
|
4492
|
+
});
|
|
4493
|
+
if (existingTimer) {
|
|
4494
|
+
existingTimer.hertz = hertz;
|
|
4495
|
+
existingTimer.timerFunc = timerFunc;
|
|
4496
|
+
return existingTimer;
|
|
4497
|
+
}
|
|
4498
|
+
this.timers.push({
|
|
4499
|
+
timerFunc: timerFunc,
|
|
4500
|
+
hertz: hertz,
|
|
4501
|
+
timerId: timerId,
|
|
4502
|
+
isPaused: false
|
|
4503
|
+
});
|
|
4504
|
+
return this.timers.at(-1);
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* Unregistering a timer completely removes it, if you want to pause a
|
|
4508
|
+
* timer, then use pauseTimer()
|
|
4509
|
+
*
|
|
4510
|
+
* @param timerId Id of the timer
|
|
4511
|
+
*/
|
|
4512
|
+
}, {
|
|
4513
|
+
key: "unregister",
|
|
4514
|
+
value: function unregister(timerId) {
|
|
4515
|
+
var indexToRemove = this.timers.findIndex(function (timer) {
|
|
4516
|
+
return timer.timerId === timerId;
|
|
4517
|
+
});
|
|
4518
|
+
if (indexToRemove > -1) {
|
|
4519
|
+
this.timers.splice(indexToRemove, 1);
|
|
4520
|
+
}
|
|
4521
|
+
}
|
|
4522
|
+
/**
|
|
4523
|
+
* Checks if a timer is paused
|
|
4524
|
+
*
|
|
4525
|
+
* @param timerId Id of the timer
|
|
4526
|
+
* @returns true if the timer is paused, false if it is running
|
|
4527
|
+
*/
|
|
4528
|
+
}, {
|
|
4529
|
+
key: "isPaused",
|
|
4530
|
+
value: function isPaused(timerId) {
|
|
4531
|
+
var _iterator = _createForOfIteratorHelper(this.timers),
|
|
4532
|
+
_step;
|
|
4533
|
+
try {
|
|
4534
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
4535
|
+
var timer = _step.value;
|
|
4536
|
+
if (timer.timerId === timerId && timer.isPaused) {
|
|
4537
|
+
return true;
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
} catch (err) {
|
|
4541
|
+
_iterator.e(err);
|
|
4542
|
+
} finally {
|
|
4543
|
+
_iterator.f();
|
|
4544
|
+
}
|
|
4545
|
+
return false;
|
|
4546
|
+
}
|
|
4547
|
+
/**
|
|
4548
|
+
* Continues running a timer
|
|
4549
|
+
*
|
|
4550
|
+
* @param timerId Id of the timer
|
|
4551
|
+
*/
|
|
4552
|
+
}, {
|
|
4553
|
+
key: "continueTimer",
|
|
4554
|
+
value: function continueTimer(timerId) {
|
|
4555
|
+
var _iterator2 = _createForOfIteratorHelper(this.timers),
|
|
4556
|
+
_step2;
|
|
4557
|
+
try {
|
|
4558
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
4559
|
+
var timer = _step2.value;
|
|
4560
|
+
if (timer.timerId === timerId) {
|
|
4561
|
+
timer.isPaused = false;
|
|
4562
|
+
break;
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
} catch (err) {
|
|
4566
|
+
_iterator2.e(err);
|
|
4567
|
+
} finally {
|
|
4568
|
+
_iterator2.f();
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
/**
|
|
4572
|
+
* Pauses a timer
|
|
4573
|
+
*
|
|
4574
|
+
* @param timerId Id of the timer
|
|
4575
|
+
*/
|
|
4576
|
+
}, {
|
|
4577
|
+
key: "pauseTimer",
|
|
4578
|
+
value: function pauseTimer(timerId) {
|
|
4579
|
+
var _iterator3 = _createForOfIteratorHelper(this.timers),
|
|
4580
|
+
_step3;
|
|
4581
|
+
try {
|
|
4582
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
4583
|
+
var timer = _step3.value;
|
|
4584
|
+
if (timer.timerId === timerId) {
|
|
4585
|
+
timer.isPaused = true;
|
|
4586
|
+
break;
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
} catch (err) {
|
|
4590
|
+
_iterator3.e(err);
|
|
4591
|
+
} finally {
|
|
4592
|
+
_iterator3.f();
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
/**
|
|
4596
|
+
* Toggles a timer to be paused or running. Be careful when asking redux
|
|
4597
|
+
* to toggle a timer, it might toggle twice and therefore do nothing
|
|
4598
|
+
*
|
|
4599
|
+
* @param timerId Id of the timer
|
|
4600
|
+
*/
|
|
4601
|
+
}, {
|
|
4602
|
+
key: "toggleTimer",
|
|
4603
|
+
value: function toggleTimer(timerId) {
|
|
4604
|
+
var _iterator4 = _createForOfIteratorHelper(this.timers),
|
|
4605
|
+
_step4;
|
|
4606
|
+
try {
|
|
4607
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
4608
|
+
var timer = _step4.value;
|
|
4609
|
+
if (timer.timerId === timerId) {
|
|
4610
|
+
timer.isPaused = !timer.isPaused;
|
|
4611
|
+
break;
|
|
4612
|
+
}
|
|
4613
|
+
}
|
|
4614
|
+
} catch (err) {
|
|
4615
|
+
_iterator4.e(err);
|
|
4616
|
+
} finally {
|
|
4617
|
+
_iterator4.f();
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
/**
|
|
4621
|
+
* Sets the speed of a timer to a new frequency given in hertz
|
|
4622
|
+
*
|
|
4623
|
+
* @param timerId Id of the timer
|
|
4624
|
+
* @param hertz Frequency of the timer given in hertz
|
|
4625
|
+
*/
|
|
4626
|
+
}, {
|
|
4627
|
+
key: "setSpeed",
|
|
4628
|
+
value: function setSpeed(timerId, hertz) {
|
|
4629
|
+
var _iterator5 = _createForOfIteratorHelper(this.timers),
|
|
4630
|
+
_step5;
|
|
4631
|
+
try {
|
|
4632
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
4633
|
+
var timer = _step5.value;
|
|
4634
|
+
if (timer.timerId === timerId) {
|
|
4635
|
+
timer.hertz = hertz;
|
|
4636
|
+
break;
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
} catch (err) {
|
|
4640
|
+
_iterator5.e(err);
|
|
4641
|
+
} finally {
|
|
4642
|
+
_iterator5.f();
|
|
4643
|
+
}
|
|
4644
|
+
}
|
|
4645
|
+
}]);
|
|
4646
|
+
return Metronome;
|
|
4647
|
+
}();
|
|
4648
|
+
var metronome = new Metronome();
|
|
4649
|
+
|
|
4650
|
+
export { AlertBanner, AlertIcon, AppHeader, AppLayout, Avatar, BUTTON_TITLE, CanvasComponent, ConfirmationDialog, ConfirmationServiceProvider, CustomAccordion, CustomDialog, CustomIconButton, CustomSlider, CustomToggleButton, CustomTooltip, DEFAULT_ERROR_MESSAGE, DraggableComponent$1 as Draggable, ErrorBoundary, LastUpdateTime, ResizeComponent as Resizable, SearchField, SearchFieldButton, SearchHighlight, StatusTag, SwitchButton, ToggleMenu, ToolContainer, DraggableComponent as ToolContainerDraggable, ToolFooter, ToolHeader, TooltipSelect, UserMenu, UserMenuItemCheatSheet, MenuItemTheme as UserMenuItemTheme, adjustPosition, calculateDialogSizeAndPosition, calculateStartSize, createMockStoreWithEggs, createMockStoreWithEggsAndMiddleware, createToolkitMockStoreWithEggs, index as dateUtils, defaultDelay, getAxiosErrorMessage, getAxiosWarningMessage, getErrorMessage, getInitials, getLastUpdateTitle, getPosition, getWarningMessage, isAxiosError, metronome, pollingIntervalTimeout, renderCounter, showPrompt, sliderHeaderStyle, tooltipContainerStyles, useConfirmationDialog, useControlledTooltip, useDialogActions, useIsMounted, useMakeSureContainerStaysInsideWindow, usePoller, usePreventBrowserClose, usePrevious, useUserMenu, withEggs };
|