@opengeoweb/shared 15.2.0 → 15.3.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,8 +6,8 @@ import React, { useRef, useEffect, useState, Component } from 'react';
6
6
  import Draggable from 'react-draggable';
7
7
  import { Resizable } from 're-resizable';
8
8
  import { Resize, BORDER_RADIUS, Options, Close, ChevronLeft, Exclamation, Success, Info, ChevronRight, GeoWebLogo, HamburgerMenu, Admin, useThemeContext, ThemeTypes, ArrowLeft, ArrowRight, KeyOption, KeyCommand, ArrowUp, ArrowDown, ChevronDown, Search, Clear, Cached, Filter as Filter$1 } from '@opengeoweb/theme';
9
- import { throttle, merge, escapeRegExp, debounce } from 'lodash';
10
- 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, roundToNearestMinutes as roundToNearestMinutes$1, isBefore as isBefore$1, isAfter as isAfter$1, isValid as isValid$1, getUnixTime, fromUnixTime, set as set$1, getHours as getHours$1, startOfDay, addMinutes, addHours, setSeconds as setSeconds$1, getDay, getDayOfYear, getMonth, getWeek, getYear, isWithinInterval } from 'date-fns';
9
+ import { throttle, isEqual, merge, escapeRegExp, debounce } from 'lodash';
10
+ import { parseISO, parse, format, isEqual as isEqual$1, 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, roundToNearestMinutes as roundToNearestMinutes$1, isBefore as isBefore$1, isAfter as isAfter$1, isValid as isValid$1, getUnixTime, fromUnixTime, set as set$1, getHours as getHours$1, startOfDay, addMinutes, addHours, setSeconds as setSeconds$1, getDay, getDayOfYear, getMonth, getWeek, getYear, isWithinInterval } from 'date-fns';
11
11
  import { fi as fi$1, nl as nl$1, nb, enGB } from 'date-fns/locale';
12
12
 
13
13
  var en = {
@@ -724,7 +724,10 @@ var DraggableComponent$1 = function DraggableComponent(_ref) {
724
724
  };
725
725
  var onDragStop = function onDragStop(event, pos) {
726
726
  setIsDragging == null || setIsDragging(false);
727
- onStop == null || onStop(event, pos);
727
+ onStop == null || onStop(event, {
728
+ x: pos.x,
729
+ y: pos.y
730
+ });
728
731
  };
729
732
  return jsx(Draggable, Object.assign({
730
733
  bounds: bounds
@@ -1763,9 +1766,9 @@ var useMakeSureContainerStaysInsideWindow = function useMakeSureContainerStaysIn
1763
1766
  /*
1764
1767
  Accepts a value and timeout and will debounce
1765
1768
 
1766
- @param {string} value: value of element
1769
+ @param {S} value: value of element
1767
1770
  @param {timeout} number: timer
1768
- @return {value: string}
1771
+ @return {value: S}
1769
1772
 
1770
1773
  @example:
1771
1774
  const debouncedName = useDebounce('testing', 2000)
@@ -1775,14 +1778,19 @@ var useDebounce = function useDebounce(value, timeout) {
1775
1778
  state = _useState[0],
1776
1779
  setState = _useState[1];
1777
1780
  useEffect(function () {
1781
+ if (timeout <= 0) {
1782
+ return function () {};
1783
+ }
1778
1784
  var handler = setTimeout(function () {
1779
- return setState(value);
1785
+ if (!isEqual(value, state)) {
1786
+ setState(value);
1787
+ }
1780
1788
  }, timeout);
1781
1789
  return function () {
1782
1790
  return clearTimeout(handler);
1783
1791
  };
1784
- }, [value, timeout]);
1785
- return state;
1792
+ }, [value, timeout, state]);
1793
+ return timeout <= 0 ? value : state;
1786
1794
  };
1787
1795
 
1788
1796
  /* *
@@ -2983,7 +2991,7 @@ var useHandleSizeFromOutsideComponent = function useHandleSizeFromOutsideCompone
2983
2991
  }, [isOpen, getBoundsNode]);
2984
2992
  };
2985
2993
 
2986
- var _excluded$7 = ["title", "bounds", "cancel", "headerSize", "startSize", "startPosition", "children", "isOpen", "onClose", "initialMaxHeight", "onChangeSize", "onMouseDown", "onResizeStop", "onDragEnd", "order", "source", "leftHeaderComponent", "rightHeaderComponent", "dragHandleIcon", "closeIcon", "className", "sx"];
2994
+ var _excluded$7 = ["title", "bounds", "cancel", "headerSize", "startSize", "startPosition", "startDraggablePosition", "children", "isOpen", "onClose", "initialMaxHeight", "onChangeSize", "onMouseDown", "onResizeStop", "onDragEnd", "order", "source", "leftHeaderComponent", "rightHeaderComponent", "dragHandleIcon", "closeIcon", "className", "sx", "resetPositionOnOpen"];
2987
2995
  // calculate dialog size and position to 85% of screensize
2988
2996
  var calculateDialogSizeAndPosition = function calculateDialogSizeAndPosition() {
2989
2997
  var width = window.innerWidth * 0.85;
@@ -3050,6 +3058,11 @@ var DraggableComponent = function DraggableComponent(_ref) {
3050
3058
  right: undefined,
3051
3059
  top: undefined
3052
3060
  } : _ref$startPosition,
3061
+ _ref$startDraggablePo = _ref.startDraggablePosition,
3062
+ startDraggablePosition = _ref$startDraggablePo === void 0 ? {
3063
+ x: 0,
3064
+ y: 0
3065
+ } : _ref$startDraggablePo,
3053
3066
  children = _ref.children,
3054
3067
  _ref$isOpen = _ref.isOpen,
3055
3068
  isOpen = _ref$isOpen === void 0 ? true : _ref$isOpen,
@@ -3078,22 +3091,34 @@ var DraggableComponent = function DraggableComponent(_ref) {
3078
3091
  className = _ref.className,
3079
3092
  _ref$sx = _ref.sx,
3080
3093
  sx = _ref$sx === void 0 ? {} : _ref$sx,
3094
+ _ref$resetPositionOnO = _ref.resetPositionOnOpen,
3095
+ resetPositionOnOpen = _ref$resetPositionOnO === void 0 ? false : _ref$resetPositionOnO,
3081
3096
  props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3082
3097
  var zIndex = (source === 'app' ? BASE_Z_INDEX : 1000) + order;
3083
3098
  var elevation = BASE_ELEVATION + order;
3084
3099
  var nodeRef = React.useRef(null);
3085
- var _React$useState = React.useState({
3086
- x: 0,
3087
- y: 0
3100
+ var _React$useState = React.useState(function () {
3101
+ return Object.assign({}, startDraggablePosition);
3088
3102
  }),
3089
3103
  position = _React$useState[0],
3090
3104
  setPosition = _React$useState[1];
3105
+ var wasOpenRef = React.useRef(isOpen);
3091
3106
  var _React$useState2 = React.useState(startSize),
3092
3107
  size = _React$useState2[0],
3093
3108
  setSize = _React$useState2[1];
3094
3109
  var _React$useState3 = React.useState(false),
3095
3110
  isDragging = _React$useState3[0],
3096
3111
  setIsDragging = _React$useState3[1];
3112
+ React.useLayoutEffect(function () {
3113
+ var isOpening = isOpen && !wasOpenRef.current;
3114
+ if (isOpening && resetPositionOnOpen) {
3115
+ setPosition({
3116
+ x: startDraggablePosition.x,
3117
+ y: startDraggablePosition.y
3118
+ });
3119
+ }
3120
+ wasOpenRef.current = isOpen;
3121
+ }, [isOpen, resetPositionOnOpen, startDraggablePosition]);
3097
3122
  var isRightAligned = (startPosition == null ? void 0 : startPosition.right) !== null && (startPosition == null ? void 0 : startPosition.right) !== undefined;
3098
3123
  var onStopDrag = React.useCallback(function (_event, position) {
3099
3124
  setPosition(position);
@@ -3120,7 +3145,15 @@ var DraggableComponent = function DraggableComponent(_ref) {
3120
3145
  }, [onChangeSize, position, isRightAligned]);
3121
3146
  var onStopResize = function onStopResize(_event, direction, node, delta) {
3122
3147
  setIsDragging(false);
3123
- setPosition(calculateNewPosition(position, isRightAligned, direction, delta));
3148
+ var newPosition = calculateNewPosition(position, isRightAligned, direction, delta);
3149
+ setPosition(newPosition);
3150
+ var _node$getBoundingClie2 = node.getBoundingClientRect(),
3151
+ width = _node$getBoundingClie2.width,
3152
+ height = _node$getBoundingClie2.height;
3153
+ onDragEnd(newPosition, {
3154
+ width: width,
3155
+ height: height
3156
+ });
3124
3157
  onResizeStop(_event, direction, node, delta);
3125
3158
  };
3126
3159
  var toolcontainerId = React.useRef(Date.now().toString()).current;
@@ -5286,6 +5319,30 @@ var isAxiosAuthError = function isAxiosAuthError(error) {
5286
5319
  }
5287
5320
  return false;
5288
5321
  };
5322
+ var isAuthStatusCode = function isAuthStatusCode(status) {
5323
+ return status === 401 || status === 403;
5324
+ };
5325
+ var isAuthError = function isAuthError(error) {
5326
+ if (isAxiosAuthError(error)) {
5327
+ return true;
5328
+ }
5329
+ var fetchLikeError = error;
5330
+ var cause = fetchLikeError.cause;
5331
+ if (typeof cause === 'number') {
5332
+ return isAuthStatusCode(cause);
5333
+ }
5334
+ if (cause && typeof cause === 'object') {
5335
+ var status = cause.status;
5336
+ if (typeof status === 'number' && isAuthStatusCode(status)) {
5337
+ return true;
5338
+ }
5339
+ var statusCode = cause.statusCode;
5340
+ if (typeof statusCode === 'number' && isAuthStatusCode(statusCode)) {
5341
+ return true;
5342
+ }
5343
+ }
5344
+ return error.message === '401' || error.message === '403';
5345
+ };
5289
5346
  var getAxiosErrorMessage = function getAxiosErrorMessage(error) {
5290
5347
  var data = error.response && error.response.data;
5291
5348
  if (data && typeof data === 'string') {
@@ -5571,7 +5628,7 @@ var isBetween = function isBetween(date, from, to, inclusivity) {
5571
5628
  }
5572
5629
  var isBeforeEqual = inclusivity.startsWith('[');
5573
5630
  var isAfterEqual = inclusivity[1] === ']';
5574
- return (isBeforeEqual ? isEqual(from, date) || isBefore(from, date) : isBefore(from, date)) && (isAfterEqual ? isEqual(to, date) || isAfter(to, date) : isAfter(to, date));
5631
+ return (isBeforeEqual ? isEqual$1(from, date) || isBefore(from, date) : isBefore(from, date)) && (isAfterEqual ? isEqual$1(to, date) || isAfter(to, date) : isAfter(to, date));
5575
5632
  };
5576
5633
  /**
5577
5634
  * Creates a new Date object with the specified date and time, or the current date and time if no arguments are provided.
@@ -5779,6 +5836,14 @@ var isValid = function isValid(date) {
5779
5836
  var unix = function unix(date) {
5780
5837
  return getUnixTime(date);
5781
5838
  };
5839
+ /**
5840
+ * Get the seconds timestamp based on the given iso string.
5841
+ * @param {string} date - the given date as iso string
5842
+ * @returns the timestamp in seconds since the Unix Epoch on January 1st, 1970 at UTC.
5843
+ */
5844
+ var unixFromISOString = function unixFromISOString(date) {
5845
+ return date ? parseISO(date).getTime() / 1000 : NaN;
5846
+ };
5782
5847
  /**
5783
5848
  * Return the Date object for a given timestamp
5784
5849
  * @param {number} unixTime - timestamp
@@ -6080,7 +6145,7 @@ var index = /*#__PURE__*/Object.freeze({
6080
6145
  isAfter: isAfter,
6081
6146
  isBefore: isBefore,
6082
6147
  isBetween: isBetween,
6083
- isEqual: isEqual,
6148
+ isEqual: isEqual$1,
6084
6149
  isValid: isValid,
6085
6150
  isValidIsoDateString: isValidIsoDateString,
6086
6151
  isWithinInterval: isWithinInterval,
@@ -6100,6 +6165,7 @@ var index = /*#__PURE__*/Object.freeze({
6100
6165
  stringToDate: stringToDate,
6101
6166
  sub: sub,
6102
6167
  unix: unix,
6168
+ unixFromISOString: unixFromISOString,
6103
6169
  utc: utc
6104
6170
  });
6105
6171
 
@@ -6353,4 +6419,4 @@ var SystemScope = {
6353
6419
  system: 'system'
6354
6420
  };
6355
6421
 
6356
- export { AlertBanner, AlertIcon, AppHeader, AppLayout, Avatar, CanvasComponent, ConfirmationButtons, ConfirmationDialog, ConfirmationServiceProvider, CustomAccordion, CustomDialog, CustomDialogHeader, CustomIconButton, CustomSlider, CustomToggleButton, CustomTooltip, DEBOUNCE_TIMEOUT, DEFAULT_ERROR_MESSAGE, DEFAULT_FILTER_HEIGHT, DraggableComponent$1 as Draggable, ErrorBoundary, Filter, FilterChip, FilterOption, LastUpdateTime, PROJECTION, ResizeComponent as Resizable, SHARED_NAMESPACE, SearchField$1 as SearchField, SearchFieldButton, SearchHighlight, SessionStorageKey, StatusTag, StorybookDocsWrapper, StyledSelect, SwitchButton, SystemScope, ToggleMenu, ToolContainer, DraggableComponent as ToolContainerDraggable, ToolFooter, ToolHeader, TooltipSelect, UserMenu, UserMenuItemCheatSheet, MenuItemTheme as UserMenuItemTheme, adjustPosition, calculateDialogSizeAndPosition, calculateStartSize, index as dateUtils, defaultDelay, getAxiosErrorMessage, getAxiosWarningMessage, getErrorMessage, getInitials, getLastUpdateTitle, getPosition, getWarningMessage, isAxiosAuthError, isAxiosError, loadAllTranslations, pollingIntervalTimeout, renderCounter, safelyInitI18nForTestsAndStories, sessionStorageProvider, sharedTranslations, showPrompt, sliderHeaderStyle, tooltipContainerStyles, useConfirmationDialog, useControlledTooltip, useDebounce, useDialogActions, useIsMounted, useMakeSureContainerStaysInsideWindow, usePoller, usePreventBrowserClose, usePrevious, useResizeObserver, useScrollingInIsolation, useUserMenu, useWheelStopPropagation };
6422
+ export { AlertBanner, AlertIcon, AppHeader, AppLayout, Avatar, CanvasComponent, ConfirmationButtons, ConfirmationDialog, ConfirmationServiceProvider, CustomAccordion, CustomDialog, CustomDialogHeader, CustomIconButton, CustomSlider, CustomToggleButton, CustomTooltip, DEBOUNCE_TIMEOUT, DEFAULT_ERROR_MESSAGE, DEFAULT_FILTER_HEIGHT, DraggableComponent$1 as Draggable, ErrorBoundary, Filter, FilterChip, FilterOption, LastUpdateTime, PROJECTION, ResizeComponent as Resizable, SHARED_NAMESPACE, SearchField$1 as SearchField, SearchFieldButton, SearchHighlight, SessionStorageKey, StatusTag, StorybookDocsWrapper, StyledSelect, SwitchButton, SystemScope, ToggleMenu, ToolContainer, DraggableComponent as ToolContainerDraggable, ToolFooter, ToolHeader, TooltipSelect, UserMenu, UserMenuItemCheatSheet, MenuItemTheme as UserMenuItemTheme, adjustPosition, calculateDialogSizeAndPosition, calculateStartSize, index as dateUtils, defaultDelay, getAxiosErrorMessage, getAxiosWarningMessage, getErrorMessage, getInitials, getLastUpdateTitle, getPosition, getWarningMessage, isAuthError, isAxiosAuthError, isAxiosError, loadAllTranslations, pollingIntervalTimeout, renderCounter, safelyInitI18nForTestsAndStories, sessionStorageProvider, sharedTranslations, showPrompt, sliderHeaderStyle, tooltipContainerStyles, useConfirmationDialog, useControlledTooltip, useDebounce, useDialogActions, useIsMounted, useMakeSureContainerStaysInsideWindow, usePoller, usePreventBrowserClose, usePrevious, useResizeObserver, useScrollingInIsolation, useUserMenu, useWheelStopPropagation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/shared",
3
- "version": "15.2.0",
3
+ "version": "15.3.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": {
@@ -8,7 +8,7 @@
8
8
  "url": "git@gitlab.com:opengeoweb/opengeoweb.git"
9
9
  },
10
10
  "dependencies": {
11
- "@opengeoweb/theme": "15.2.0",
11
+ "@opengeoweb/theme": "15.3.0",
12
12
  "react-draggable": "^4.4.6",
13
13
  "re-resizable": "^6.9.11",
14
14
  "lodash": "^4.17.21",
@@ -12,6 +12,7 @@ export declare const calculateDialogSizeAndPosition: () => {
12
12
  export declare const calculateStartSize: (minSize: DraggableSize, prefSize: DraggableSize, startPosition: Position) => DraggableSize;
13
13
  interface DraggableComponentProps extends Omit<ResizableComponentProps, 'bounds'> {
14
14
  startPosition?: Position;
15
+ startDraggablePosition?: DraggablePosition;
15
16
  onStartResize?: () => void;
16
17
  isOpen?: boolean;
17
18
  onClose?: () => void;
@@ -30,6 +31,7 @@ interface DraggableComponentProps extends Omit<ResizableComponentProps, 'bounds'
30
31
  dragHandleIcon?: React.ReactNode;
31
32
  closeIcon?: React.ReactNode;
32
33
  sx?: SxProps;
34
+ resetPositionOnOpen?: boolean;
33
35
  }
34
36
  export declare const calculateNewPosition: (position: DraggablePosition, isRightAligned: boolean, handle: string, delta: NumberSize) => DraggablePosition;
35
37
  export type Source = 'app' | 'module';
@@ -1 +1 @@
1
- export declare const useDebounce: (value: string, timeout: number) => string;
1
+ export declare const useDebounce: <S>(value: S, timeout: number) => S;
@@ -44,7 +44,19 @@ export interface VerticalProfileDomain {
44
44
  axes: VerticalProfileAxes;
45
45
  referencing?: Referencing[];
46
46
  }
47
- export type CoverageDomain = VerticalProfileDomain | PointDomain | PointSeriesDomain;
47
+ interface GridAxes {
48
+ x: SingleValueAxis;
49
+ y: SingleValueAxis;
50
+ z: AxisValues;
51
+ t?: SingleTimeValueAxis;
52
+ }
53
+ export interface GridDomain {
54
+ type: 'Domain';
55
+ domainType: 'Grid';
56
+ axes: GridAxes;
57
+ referencing?: Referencing[];
58
+ }
59
+ export type CoverageDomain = VerticalProfileDomain | PointDomain | PointSeriesDomain | GridDomain;
48
60
  interface NdArray {
49
61
  type: 'NdArray';
50
62
  dataType: 'float' | 'integer' | 'string';
@@ -53,6 +53,7 @@ export interface SoundingsCollection {
53
53
  url: string;
54
54
  description: string;
55
55
  parameterMappings?: Record<string, string>;
56
+ windSpeedUnit?: string;
56
57
  }
57
58
  export type Coordinates = [number, number];
58
59
  export interface SourceSelection {
@@ -61,6 +62,7 @@ export interface SourceSelection {
61
62
  isChecked?: boolean;
62
63
  verticalRange?: string;
63
64
  parameterMappings?: Record<string, string>;
65
+ windSpeedUnit?: string;
64
66
  name?: string;
65
67
  }
66
68
  export interface TimeSeriesService {
@@ -2,6 +2,7 @@ import type { AxiosError } from 'axios';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "An error has occurred";
3
3
  export declare const isAxiosError: (error: AxiosError | Error) => error is AxiosError;
4
4
  export declare const isAxiosAuthError: (error: AxiosError | Error) => boolean;
5
+ export declare const isAuthError: (error: AxiosError | Error) => boolean;
5
6
  export declare const getAxiosErrorMessage: (error: AxiosError) => string;
6
7
  export declare const getErrorMessage: (error: Error | AxiosError) => string;
7
8
  export declare const getAxiosWarningMessage: (error: AxiosError) => string;
@@ -258,6 +258,12 @@ export declare const isValid: (date: Date | number) => boolean;
258
258
  * @returns the timestamp
259
259
  */
260
260
  export declare const unix: (date: Date | number) => number;
261
+ /**
262
+ * Get the seconds timestamp based on the given iso string.
263
+ * @param {string} date - the given date as iso string
264
+ * @returns the timestamp in seconds since the Unix Epoch on January 1st, 1970 at UTC.
265
+ */
266
+ export declare const unixFromISOString: (date: string) => number;
261
267
  /**
262
268
  * Return the Date object for a given timestamp
263
269
  * @param {number} unixTime - timestamp