@opengeoweb/shared 9.8.0 → 9.9.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 CHANGED
@@ -6,7 +6,7 @@ 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
 
@@ -1113,9 +1113,16 @@ var DraggableComponent$1 = function DraggableComponent(_a) {
1113
1113
  bounds = _a$bounds === void 0 ? 'body' : _a$bounds,
1114
1114
  children = _a.children,
1115
1115
  props = __rest(_a, ["bounds", "children"]);
1116
+ var onDragStart = function onDragStart(e) {
1117
+ // This makes sure that nothing is selected during drag
1118
+ e.preventDefault();
1119
+ };
1116
1120
  return /*#__PURE__*/React__default.createElement(Draggable, Object.assign({
1117
1121
  bounds: bounds
1118
- }, props), children);
1122
+ }, props, {
1123
+ enableUserSelectHack: false,
1124
+ onStart: onDragStart
1125
+ }), children);
1119
1126
  };
1120
1127
 
1121
1128
  /* *
@@ -3441,7 +3448,13 @@ var getWarningMessage = function getWarningMessage(error) {
3441
3448
  */
3442
3449
  var isoStringToDate = function isoStringToDate(input) {
3443
3450
  var utc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3451
+ if (!input) {
3452
+ return undefined;
3453
+ }
3444
3454
  var parsed = parseISO(input);
3455
+ if (!isValid(parsed)) {
3456
+ return undefined;
3457
+ }
3445
3458
  if (utc) {
3446
3459
  return setUTCDate(parsed);
3447
3460
  }
@@ -3465,12 +3478,24 @@ var isoStringToDate = function isoStringToDate(input) {
3465
3478
  var stringToDate = function stringToDate(input, strFormat) {
3466
3479
  var utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3467
3480
  var referenceDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Date();
3481
+ if (!input) {
3482
+ return undefined;
3483
+ }
3468
3484
  var parsed = parse(input, strFormat, referenceDate);
3485
+ if (!isValid(parsed)) {
3486
+ return undefined;
3487
+ }
3469
3488
  if (utc) {
3470
3489
  return setUTCDate(parsed);
3471
3490
  }
3472
3491
  return parsed;
3473
3492
  };
3493
+ var dateToIsoString = function dateToIsoString(input) {
3494
+ if (!input || !isValid(input)) {
3495
+ return undefined;
3496
+ }
3497
+ return input.toISOString();
3498
+ };
3474
3499
  /**
3475
3500
  * Use this if you initialise a date without a timezone to set it to utc correctly
3476
3501
  * eg.
@@ -3486,6 +3511,9 @@ var stringToDate = function stringToDate(input, strFormat) {
3486
3511
  * ``` setUTCDate(new Date(2022, 10, 12, 15, 30)) ```
3487
3512
  */
3488
3513
  var setUTCDate = function setUTCDate(inDate) {
3514
+ if (!inDate || !isValid(inDate)) {
3515
+ return undefined;
3516
+ }
3489
3517
  var utcDate = new Date(inDate);
3490
3518
  utcDate.setUTCFullYear(inDate.getFullYear(), inDate.getMonth(), inDate.getDate());
3491
3519
  utcDate.setUTCHours(inDate.getHours(), inDate.getMinutes(), inDate.getSeconds(), inDate.getMilliseconds());
@@ -3506,10 +3534,11 @@ var setUTCDate = function setUTCDate(inDate) {
3506
3534
  var dateToString = function dateToString(inDate) {
3507
3535
  var strFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "yyyy-MM-dd'T'HH:mm:ss'Z'";
3508
3536
  var utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3509
- if (utc) {
3510
- return format(new Date(inDate.getUTCFullYear(), inDate.getUTCMonth(), inDate.getUTCDate(), inDate.getUTCHours(), inDate.getUTCMinutes(), inDate.getUTCSeconds()), strFormat);
3537
+ if (!inDate || !isValid(inDate)) {
3538
+ return undefined;
3511
3539
  }
3512
- return format(inDate, strFormat);
3540
+ var formattedDate = utc ? format(new Date(inDate.getUTCFullYear(), inDate.getUTCMonth(), inDate.getUTCDate(), inDate.getUTCHours(), inDate.getUTCMinutes(), inDate.getUTCSeconds()), strFormat) : format(inDate, strFormat);
3541
+ return formattedDate;
3513
3542
  };
3514
3543
  /**
3515
3544
  * Find out if a date is between two other dates.
@@ -3585,6 +3614,36 @@ var add = function add(date, duration) {
3585
3614
  var sub = function sub(date, duration) {
3586
3615
  return sub$1(date, duration);
3587
3616
  };
3617
+ /**
3618
+ * Finds the number of years between to dates
3619
+ *
3620
+ * @param dateLeft - the later date
3621
+ * @param dateRight - the earlier date
3622
+ * @returns {number} the number of minutes
3623
+ */
3624
+ var differenceInYears = function differenceInYears(dateLeft, dateRight) {
3625
+ return differenceInYears$1(dateLeft, dateRight);
3626
+ };
3627
+ /**
3628
+ * Finds the number of months between to dates
3629
+ *
3630
+ * @param dateLeft - the later date
3631
+ * @param dateRight - the earlier date
3632
+ * @returns {number} the number of minutes
3633
+ */
3634
+ var differenceInMonths = function differenceInMonths(dateLeft, dateRight) {
3635
+ return differenceInMonths$1(dateLeft, dateRight);
3636
+ };
3637
+ /**
3638
+ * Finds the number of days between to dates
3639
+ *
3640
+ * @param dateLeft - the later date
3641
+ * @param dateRight - the earlier date
3642
+ * @returns {number} the number of minutes
3643
+ */
3644
+ var differenceInDays = function differenceInDays(dateLeft, dateRight) {
3645
+ return differenceInDays$1(dateLeft, dateRight);
3646
+ };
3588
3647
  /**
3589
3648
  * Finds the number of minuts between to dates
3590
3649
  *
@@ -3607,6 +3666,16 @@ var differenceInHours = function differenceInHours(dateLeft, dateRight, rounding
3607
3666
  roundingMethod: roundingMethod
3608
3667
  }) : differenceInHours$1(dateLeft, dateRight);
3609
3668
  };
3669
+ /**
3670
+ * Finds the number of seconds between to dates
3671
+ *
3672
+ * @param dateLeft - the later date
3673
+ * @param dateRight - the earlier date
3674
+ * @returns {number} the number of minutes
3675
+ */
3676
+ var differenceInSeconds = function differenceInSeconds(dateLeft, dateRight) {
3677
+ return differenceInSeconds$1(dateLeft, dateRight);
3678
+ };
3610
3679
  /**
3611
3680
  *
3612
3681
  * @param date - the date that should be before the other one to return true
@@ -3629,14 +3698,29 @@ var isAfter = function isAfter(date, dateToCompare) {
3629
3698
  return isAfter$1(date, dateToCompare);
3630
3699
  };
3631
3700
  /**
3632
- * Parsing string to a date, setting tz to UTC even if it's missing
3701
+ * Gracefully parsing string to a date, setting tz to UTC even if it's missing or input is invalid
3702
+ * Note: use getUtcFromString() to convert a string to a date with stricter returns
3633
3703
  * @param dateStr - string containing date
3634
- * @returns {Date} - Date in UTC
3704
+ * @returns {Date} - Date in UTC, or current date when something invalid is passed.
3635
3705
  */
3636
3706
  var utc = function utc(dateStr) {
3637
- if (dateStr === undefined) {
3707
+ if (!dateStr) {
3638
3708
  return createDate();
3639
3709
  }
3710
+ if (hasOffset(dateStr)) {
3711
+ return isoStringToDate(dateStr, false) || createDate();
3712
+ }
3713
+ return isoStringToDate(dateStr) || createDate();
3714
+ };
3715
+ /**
3716
+ * Parsing string to a date. Stricter check, will return undefined when dateString is invalid.
3717
+ * @param dateStr - string containing date
3718
+ * @returns {Date} - Date in UTC, undefined when not valid
3719
+ */
3720
+ var getUtcFromString = function getUtcFromString(dateStr) {
3721
+ if (!dateStr) {
3722
+ return undefined;
3723
+ }
3640
3724
  if (hasOffset(dateStr)) {
3641
3725
  return isoStringToDate(dateStr, false);
3642
3726
  }
@@ -3652,7 +3736,7 @@ var getOffsetStr = function getOffsetStr(input) {
3652
3736
  };
3653
3737
  /**
3654
3738
  * Check if a date object is valid
3655
- * @param {Date} date - date to be checked
3739
+ * @param {Date | number} date - date to be checked
3656
3740
  * @returns {boolean} - True if valid
3657
3741
  */
3658
3742
  var isValid = function isValid(date) {
@@ -3695,6 +3779,25 @@ var parseCustomDateString = function parseCustomDateString(dateStr) {
3695
3779
  }
3696
3780
  return new Date(dateStr);
3697
3781
  };
3782
+ /**
3783
+ * Returns Date in UTC
3784
+ * @returns {Date} - Date in UTC
3785
+ */
3786
+ var getNowUtc = function getNowUtc() {
3787
+ return createDate();
3788
+ };
3789
+ /**
3790
+ * Returns current time as string
3791
+ * @param {string} strFormat - [default: "yyyy-MM-dd'T'HH:mm:ss'Z'"] format of string
3792
+ * @param {boolean} utc - [default: true] true to return in utc otherwise return in local timezone
3793
+ *
3794
+ * @returns {string} - formatted date string
3795
+ */
3796
+ var getCurrentTimeAsString = function getCurrentTimeAsString() {
3797
+ var strFormat = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "yyyy-MM-dd'T'HH:mm:ss'Z'";
3798
+ var utc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3799
+ return dateToString(getNowUtc(), strFormat, utc);
3800
+ };
3698
3801
  /**
3699
3802
  * Set date values to a given date (by default it is assumed you are passing the new values in UTC).
3700
3803
  * @param date - the dater to be changed
@@ -3753,25 +3856,34 @@ var index = /*#__PURE__*/Object.freeze({
3753
3856
  __proto__: null,
3754
3857
  isoStringToDate: isoStringToDate,
3755
3858
  stringToDate: stringToDate,
3859
+ dateToIsoString: dateToIsoString,
3756
3860
  setUTCDate: setUTCDate,
3757
3861
  dateToString: dateToString,
3758
3862
  isBetween: isBetween,
3759
3863
  createDate: createDate,
3760
3864
  add: add,
3761
3865
  sub: sub,
3866
+ differenceInYears: differenceInYears,
3867
+ differenceInMonths: differenceInMonths,
3868
+ differenceInDays: differenceInDays,
3762
3869
  differenceInMinutes: differenceInMinutes,
3763
3870
  differenceInHours: differenceInHours,
3871
+ differenceInSeconds: differenceInSeconds,
3764
3872
  isBefore: isBefore,
3765
3873
  isAfter: isAfter,
3766
3874
  utc: utc,
3875
+ getUtcFromString: getUtcFromString,
3767
3876
  isValid: isValid,
3768
3877
  unix: unix,
3769
3878
  fromUnix: fromUnix,
3770
3879
  parseCustomDateString: parseCustomDateString,
3880
+ getNowUtc: getNowUtc,
3881
+ getCurrentTimeAsString: getCurrentTimeAsString,
3771
3882
  set: set,
3772
3883
  isEqual: isEqual,
3773
3884
  startOfDay: startOfDay,
3774
- parseISO: parseISO
3885
+ parseISO: parseISO,
3886
+ isWithinInterval: isWithinInterval
3775
3887
  });
3776
3888
 
3777
3889
  /* *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/shared",
3
- "version": "9.8.0",
3
+ "version": "9.9.0",
4
4
  "description": "GeoWeb shared library with shared components and utils for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,22 +1,22 @@
1
1
  /// <reference types="react" />
2
2
  import { ResizableProps } from 're-resizable';
3
- export type DraggablePosition = {
3
+ export interface DraggablePosition {
4
4
  x: number;
5
5
  y: number;
6
- };
7
- export type Position = {
6
+ }
7
+ export interface Position {
8
8
  top: number;
9
9
  left?: number;
10
10
  right?: number;
11
- };
12
- export type DraggableSize = {
11
+ }
12
+ export interface DraggableSize {
13
13
  width: number;
14
14
  height: number;
15
- };
16
- export type Size = {
15
+ }
16
+ export interface Size {
17
17
  width?: number | string;
18
18
  height?: number | string;
19
- };
19
+ }
20
20
  export interface ResizableComponentProps extends Omit<ResizableProps, 'size'> {
21
21
  startSize?: Size;
22
22
  setSize?: (size: Size) => void;
@@ -6,12 +6,12 @@ export declare const getPosition: (menuPosition: MenuPosition) => {
6
6
  anchorOrigin: PopoverOrigin;
7
7
  transformOrigin: PopoverOrigin;
8
8
  };
9
- type MenuItemType = {
9
+ interface MenuItemType {
10
10
  text: string;
11
11
  action: (event: React.MouseEvent) => void;
12
12
  icon?: React.ReactNode;
13
13
  isDisabled?: boolean;
14
- };
14
+ }
15
15
  interface ToggleMenuProps {
16
16
  buttonTestId?: string;
17
17
  menuPosition?: MenuPosition;
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { SelectProps } from '@mui/material';
3
- type ListELement = {
3
+ interface ListELement {
4
4
  value: string;
5
- };
5
+ }
6
6
  interface TooltipSelectProps extends SelectProps {
7
7
  tooltip: string;
8
8
  list?: ListELement[];
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- type ShortCut = {
2
+ interface ShortCut {
3
3
  title: string;
4
4
  description: React.ReactNode;
5
5
  descriptionMac?: React.ReactNode;
6
- };
6
+ }
7
7
  type Platform = 'windows' | 'mac';
8
8
  export declare const shortcuts: ShortCut[];
9
9
  export declare const getShortcutList: (shortcutList: ShortCut[], platform?: Platform) => ShortCut[];
@@ -4,7 +4,7 @@ export interface ConfigType {
4
4
  GW_AUTH_LOGOUT_URL?: string;
5
5
  GW_AUTH_TOKEN_URL?: string;
6
6
  GW_AUTH_CLIENT_ID?: string;
7
- GW_INFRA_BASE_URL?: string;
7
+ GW_BE_VERSION_BASE_URL?: string;
8
8
  GW_APP_URL?: string;
9
9
  GW_INITIAL_PRESETS_FILENAME?: string;
10
10
  GW_CAP_CONFIGURATION_FILENAME?: string;
@@ -1,4 +1,4 @@
1
- import { parseISO, isEqual, Duration, startOfDay } from 'date-fns';
1
+ import { parseISO, isEqual, Duration, startOfDay, isWithinInterval } from 'date-fns';
2
2
  export interface DateValues {
3
3
  year?: number;
4
4
  month?: number;
@@ -61,7 +61,7 @@ export interface DateValues {
61
61
  * ``` isoStringToDate("2022-5-10T20:32:00+00:00") ```
62
62
  * ``` isoStringToDate("2022-5-10T20:32:00:00Z", false) ```
63
63
  */
64
- export declare const isoStringToDate: (input: string, utc?: boolean) => Date;
64
+ export declare const isoStringToDate: (input: string, utc?: boolean) => Date | undefined;
65
65
  /**
66
66
  * Parse a string to a date
67
67
  *
@@ -77,7 +77,8 @@ export declare const isoStringToDate: (input: string, utc?: boolean) => Date;
77
77
  * @example
78
78
  * ``` stringToDate("2022 5 10 20:32", 'yyyy M d HH:mm')) ```
79
79
  */
80
- export declare const stringToDate: (input: string, strFormat: string, utc?: boolean, referenceDate?: Date | number) => Date;
80
+ export declare const stringToDate: (input: string | undefined, strFormat: string, utc?: boolean, referenceDate?: Date | number) => Date | undefined;
81
+ export declare const dateToIsoString: (input: Date | undefined) => string | undefined;
81
82
  /**
82
83
  * Use this if you initialise a date without a timezone to set it to utc correctly
83
84
  * eg.
@@ -92,7 +93,7 @@ export declare const stringToDate: (input: string, strFormat: string, utc?: bool
92
93
  * @example
93
94
  * ``` setUTCDate(new Date(2022, 10, 12, 15, 30)) ```
94
95
  */
95
- export declare const setUTCDate: (inDate: Date) => Date;
96
+ export declare const setUTCDate: (inDate: Date | undefined) => Date | undefined;
96
97
  /**
97
98
  * Format a date to a string
98
99
  *
@@ -105,7 +106,7 @@ export declare const setUTCDate: (inDate: Date) => Date;
105
106
  * @example
106
107
  * ``` dateToString(new Date(2022, 10, 12, 15, 30), 'dd MMM yyyy') ```
107
108
  */
108
- export declare const dateToString: (inDate: Date, strFormat?: string, utc?: boolean) => string;
109
+ export declare const dateToString: (inDate: Date | undefined, strFormat?: string, utc?: boolean) => string | undefined;
109
110
  /**
110
111
  * Find out if a date is between two other dates.
111
112
  *
@@ -156,6 +157,30 @@ export declare const add: (date: Date | number, duration: Duration) => Date;
156
157
  * @returns {Date} the new Date
157
158
  */
158
159
  export declare const sub: (date: Date | number, duration: Duration) => Date;
160
+ /**
161
+ * Finds the number of years between to dates
162
+ *
163
+ * @param dateLeft - the later date
164
+ * @param dateRight - the earlier date
165
+ * @returns {number} the number of minutes
166
+ */
167
+ export declare const differenceInYears: (dateLeft: Date | number, dateRight: Date | number) => number;
168
+ /**
169
+ * Finds the number of months between to dates
170
+ *
171
+ * @param dateLeft - the later date
172
+ * @param dateRight - the earlier date
173
+ * @returns {number} the number of minutes
174
+ */
175
+ export declare const differenceInMonths: (dateLeft: Date | number | string, dateRight: Date | number | string) => number;
176
+ /**
177
+ * Finds the number of days between to dates
178
+ *
179
+ * @param dateLeft - the later date
180
+ * @param dateRight - the earlier date
181
+ * @returns {number} the number of minutes
182
+ */
183
+ export declare const differenceInDays: (dateLeft: Date | number | string, dateRight: Date | number | string) => number;
159
184
  /**
160
185
  * Finds the number of minuts between to dates
161
186
  *
@@ -172,6 +197,14 @@ export declare const differenceInMinutes: (dateLeft: Date | number, dateRight: D
172
197
  * @returns {number} the number of hours
173
198
  */
174
199
  export declare const differenceInHours: (dateLeft: Date | number, dateRight: Date | number, roundingMethod?: 'ceil' | 'floor' | 'round' | 'trunc') => number;
200
+ /**
201
+ * Finds the number of seconds between to dates
202
+ *
203
+ * @param dateLeft - the later date
204
+ * @param dateRight - the earlier date
205
+ * @returns {number} the number of minutes
206
+ */
207
+ export declare const differenceInSeconds: (dateLeft: Date | number, dateRight: Date | number) => number;
175
208
  /**
176
209
  *
177
210
  * @param date - the date that should be before the other one to return true
@@ -189,17 +222,24 @@ export declare const isBefore: (date: Date | number, dateToCompare: Date | numbe
189
222
  */
190
223
  export declare const isAfter: (date: Date | number, dateToCompare: Date | number) => boolean;
191
224
  /**
192
- * Parsing string to a date, setting tz to UTC even if it's missing
225
+ * Gracefully parsing string to a date, setting tz to UTC even if it's missing or input is invalid
226
+ * Note: use getUtcFromString() to convert a string to a date with stricter returns
193
227
  * @param dateStr - string containing date
194
- * @returns {Date} - Date in UTC
228
+ * @returns {Date} - Date in UTC, or current date when something invalid is passed.
229
+ */
230
+ export declare const utc: (dateStr?: string | undefined) => Date;
231
+ /**
232
+ * Parsing string to a date. Stricter check, will return undefined when dateString is invalid.
233
+ * @param dateStr - string containing date
234
+ * @returns {Date} - Date in UTC, undefined when not valid
195
235
  */
196
- export declare const utc: (dateStr?: string) => Date;
236
+ export declare const getUtcFromString: (dateStr: string | undefined | null) => Date | undefined;
197
237
  /**
198
238
  * Check if a date object is valid
199
- * @param {Date} date - date to be checked
239
+ * @param {Date | number} date - date to be checked
200
240
  * @returns {boolean} - True if valid
201
241
  */
202
- export declare const isValid: (date: Date) => boolean;
242
+ export declare const isValid: (date: Date | number) => boolean;
203
243
  /**
204
244
  * Get the seconds timestamp of the given date
205
245
  * @param {Date} date - the given date
@@ -213,6 +253,19 @@ export declare const unix: (date: Date | number) => number;
213
253
  */
214
254
  export declare const fromUnix: (unixTime: number) => Date;
215
255
  export declare const parseCustomDateString: (dateStr: string) => Date;
256
+ /**
257
+ * Returns Date in UTC
258
+ * @returns {Date} - Date in UTC
259
+ */
260
+ export declare const getNowUtc: () => Date;
261
+ /**
262
+ * Returns current time as string
263
+ * @param {string} strFormat - [default: "yyyy-MM-dd'T'HH:mm:ss'Z'"] format of string
264
+ * @param {boolean} utc - [default: true] true to return in utc otherwise return in local timezone
265
+ *
266
+ * @returns {string} - formatted date string
267
+ */
268
+ export declare const getCurrentTimeAsString: (strFormat?: string, utc?: boolean) => string;
216
269
  /**
217
270
  * Set date values to a given date (by default it is assumed you are passing the new values in UTC).
218
271
  * @param date - the dater to be changed
@@ -227,4 +280,4 @@ export declare const set: (date: Date, values: DateValues, useLocalTimeZone?: bo
227
280
  * @param {Date} date - second date
228
281
  * @returns {boolean} - True if dates are equal
229
282
  */
230
- export { isEqual, startOfDay, parseISO };
283
+ export { isEqual, startOfDay, parseISO, isWithinInterval };