@opengeoweb/shared 2.0.1 → 2.1.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.
@@ -1,2 +1,9 @@
1
1
  import * as React from 'react';
2
- export declare const AlertBanners: () => React.ReactElement;
2
+ declare const _default: {
3
+ title: string;
4
+ };
5
+ export default _default;
6
+ export declare const AlertBanners: {
7
+ (): React.ReactElement;
8
+ storyName: string;
9
+ };
@@ -1,2 +1,6 @@
1
1
  import * as React from 'react';
2
- export declare const ConfirmationDialog: () => React.ReactElement;
2
+ export declare const ConfirmationDialogExample: () => React.ReactElement;
3
+ export declare const ConfirmationDialogSnapshot: {
4
+ (): React.ReactElement;
5
+ storyName: string;
6
+ };
@@ -1,2 +1,14 @@
1
1
  import * as React from 'react';
2
+ declare const _default: {
3
+ title: string;
4
+ };
5
+ export default _default;
2
6
  export declare const CustomSliderComponent: () => React.ReactElement;
7
+ export declare const CustomSliderLightTheme: {
8
+ (): React.ReactElement;
9
+ storyName: string;
10
+ };
11
+ export declare const CustomSliderDarkTheme: {
12
+ (): React.ReactElement;
13
+ storyName: string;
14
+ };
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ interface ErrorBoundaryProps {
3
+ children: React.ReactNode;
4
+ onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
5
+ }
6
+ interface ErrorBoundaryState {
7
+ error?: Error;
8
+ errorInfo?: React.ErrorInfo;
9
+ }
10
+ /**
11
+ * ErrorBoundary
12
+ * Wrap this component around parts of your application. It will catch any uncaught errors and display an alert, and allows you to continue using the rest of your application.
13
+ *
14
+ * @example
15
+ * ``` <ErrorBoundary><ExampleComponent /></ErrorBoundary> ```
16
+ */
17
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
18
+ static defaultProps: {
19
+ onError: () => void;
20
+ };
21
+ private constructor();
22
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
23
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
24
+ render(): React.ReactNode;
25
+ }
26
+ export default ErrorBoundary;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ export declare const ErrorBoundaryDemo: {
3
+ (): React.ReactElement;
4
+ storyName: string;
5
+ };
@@ -0,0 +1 @@
1
+ export { ErrorBoundary } from './ErrorBoundary';
@@ -1,2 +1,9 @@
1
1
  import React from 'react';
2
- export declare const StatusTags: () => React.ReactElement;
2
+ declare const _default: {
3
+ title: string;
4
+ };
5
+ export default _default;
6
+ export declare const StatusTags: {
7
+ (): React.ReactElement;
8
+ storyName: string;
9
+ };
@@ -5,3 +5,11 @@ declare const _default: {
5
5
  export default _default;
6
6
  export declare const ThemeLight: () => React.ReactElement;
7
7
  export declare const ThemeDark: () => React.ReactElement;
8
+ export declare const ThemeLightSnapShot: {
9
+ (): React.ReactElement;
10
+ storyName: string;
11
+ };
12
+ export declare const ThemeDarkSnapShot: {
13
+ (): React.ReactElement;
14
+ storyName: string;
15
+ };
@@ -5,3 +5,11 @@ declare const _default: {
5
5
  export default _default;
6
6
  export declare const ThemeLight: () => React.ReactElement;
7
7
  export declare const ThemeDark: () => React.ReactElement;
8
+ export declare const ThemeLightSnapShot: {
9
+ (): React.ReactElement;
10
+ storyName: string;
11
+ };
12
+ export declare const ThemeDarkSnapShot: {
13
+ (): React.ReactElement;
14
+ storyName: string;
15
+ };
@@ -1,8 +1,6 @@
1
- export * from './AlertBanner/AlertBanner.stories';
2
- export * from './StatusTag/StatusTag.stories';
3
1
  export * from './AppHeader/AppHeader.stories';
4
2
  export * from './ConfirmationDialog/ConfirmationDialog.stories';
5
- export * from './CustomSlider/CustomSlider.stories';
3
+ export * from './ErrorBoundary/ErrorBoundary.stories';
6
4
  declare const _default: {
7
5
  title: string;
8
6
  };
@@ -4,6 +4,7 @@ export * from './AlertBanner';
4
4
  export * from './AppLayout';
5
5
  export * from './AppHeader';
6
6
  export * from './DraggableResizable';
7
+ export * from './ErrorBoundary';
7
8
  export * from './UserMenu';
8
9
  export * from './ToolContainer';
9
10
  export * from './CustomSlider';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/shared",
3
- "version": "2.0.1",
3
+ "version": "2.1.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": {
@@ -14,13 +14,13 @@
14
14
  "peerDependencies": {
15
15
  "react": "16.14.0",
16
16
  "@material-ui/lab": "^4.0.0-alpha.56",
17
- "@opengeoweb/theme": "2.0.1",
17
+ "@opengeoweb/theme": "2.1.0",
18
18
  "@material-ui/core": "^4.11.0",
19
19
  "@material-ui/icons": "^4.9.1",
20
20
  "react-draggable": "^4.4.3",
21
21
  "re-resizable": "^6.9.0",
22
22
  "lodash": "^4.17.20",
23
- "@opengeoweb/form-fields": "2.0.1",
23
+ "@opengeoweb/form-fields": "2.1.0",
24
24
  "react-hook-form": "^6.12.1",
25
25
  "@material-ui/pickers": "^3.2.10",
26
26
  "@date-io/moment": "^1.3.13",
package/shared.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { Box, Typography, makeStyles, Dialog, DialogTitle, IconButton, DialogContent, DialogActions, Button, SvgIcon, Grid, useTheme, Avatar, Paper, ClickAwayListener, MenuList, MenuItem, RadioGroup, FormControlLabel, Radio, List, ListItem, Tabs, Tab, Backdrop, withStyles, Slider } from '@material-ui/core';
3
+ import { Box, Typography, makeStyles, Dialog, DialogTitle, IconButton, DialogContent, DialogActions, Button, SvgIcon, Grid, useTheme, Link, Avatar, Paper, ClickAwayListener, MenuList, MenuItem, RadioGroup, FormControlLabel, Radio, List, ListItem, Tabs, Tab, Backdrop, withStyles, Slider } from '@material-ui/core';
4
4
  import { Close, DragIndicator } from '@material-ui/icons';
5
5
  import { useFormContext } from 'react-hook-form';
6
6
  import { isEmpty, errorMessages } from '@opengeoweb/form-fields';
@@ -172,7 +172,8 @@ var ConfirmationDialog = function ConfirmationDialog(_a) {
172
172
  onClick: function onClick() {
173
173
  return onClose('CANCELLED');
174
174
  },
175
- autoFocus: true
175
+ autoFocus: true,
176
+ disableRipple: true
176
177
  }, cancelLabel), /*#__PURE__*/React.createElement(Button, {
177
178
  "data-testid": "conformationDialog-confirm",
178
179
  color: "secondary",
@@ -181,6 +182,28 @@ var ConfirmationDialog = function ConfirmationDialog(_a) {
181
182
  }, confirmLabel)));
182
183
  };
183
184
 
185
+ function _classCallCheck(instance, Constructor) {
186
+ if (!(instance instanceof Constructor)) {
187
+ throw new TypeError("Cannot call a class as a function");
188
+ }
189
+ }
190
+
191
+ function _defineProperties(target, props) {
192
+ for (var i = 0; i < props.length; i++) {
193
+ var descriptor = props[i];
194
+ descriptor.enumerable = descriptor.enumerable || false;
195
+ descriptor.configurable = true;
196
+ if ("value" in descriptor) descriptor.writable = true;
197
+ Object.defineProperty(target, descriptor.key, descriptor);
198
+ }
199
+ }
200
+
201
+ function _createClass(Constructor, protoProps, staticProps) {
202
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
203
+ if (staticProps) _defineProperties(Constructor, staticProps);
204
+ return Constructor;
205
+ }
206
+
184
207
  function _defineProperty(obj, key, value) {
185
208
  if (key in obj) {
186
209
  Object.defineProperty(obj, key, {
@@ -196,6 +219,85 @@ function _defineProperty(obj, key, value) {
196
219
  return obj;
197
220
  }
198
221
 
222
+ function _inherits(subClass, superClass) {
223
+ if (typeof superClass !== "function" && superClass !== null) {
224
+ throw new TypeError("Super expression must either be null or a function");
225
+ }
226
+
227
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
228
+ constructor: {
229
+ value: subClass,
230
+ writable: true,
231
+ configurable: true
232
+ }
233
+ });
234
+ if (superClass) _setPrototypeOf(subClass, superClass);
235
+ }
236
+
237
+ function _getPrototypeOf(o) {
238
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
239
+ return o.__proto__ || Object.getPrototypeOf(o);
240
+ };
241
+ return _getPrototypeOf(o);
242
+ }
243
+
244
+ function _setPrototypeOf(o, p) {
245
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
246
+ o.__proto__ = p;
247
+ return o;
248
+ };
249
+
250
+ return _setPrototypeOf(o, p);
251
+ }
252
+
253
+ function _isNativeReflectConstruct() {
254
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
255
+ if (Reflect.construct.sham) return false;
256
+ if (typeof Proxy === "function") return true;
257
+
258
+ try {
259
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
260
+ return true;
261
+ } catch (e) {
262
+ return false;
263
+ }
264
+ }
265
+
266
+ function _assertThisInitialized(self) {
267
+ if (self === void 0) {
268
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
269
+ }
270
+
271
+ return self;
272
+ }
273
+
274
+ function _possibleConstructorReturn(self, call) {
275
+ if (call && (typeof call === "object" || typeof call === "function")) {
276
+ return call;
277
+ }
278
+
279
+ return _assertThisInitialized(self);
280
+ }
281
+
282
+ function _createSuper(Derived) {
283
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
284
+
285
+ return function _createSuperInternal() {
286
+ var Super = _getPrototypeOf(Derived),
287
+ result;
288
+
289
+ if (hasNativeReflectConstruct) {
290
+ var NewTarget = _getPrototypeOf(this).constructor;
291
+
292
+ result = Reflect.construct(Super, arguments, NewTarget);
293
+ } else {
294
+ result = Super.apply(this, arguments);
295
+ }
296
+
297
+ return _possibleConstructorReturn(this, result);
298
+ };
299
+ }
300
+
199
301
  function _slicedToArray(arr, i) {
200
302
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
201
303
  }
@@ -906,6 +1008,89 @@ var ResizeComponent = function ResizeComponent(_a) {
906
1008
  }, props), children);
907
1009
  };
908
1010
 
1011
+ /**
1012
+ * ErrorBoundary
1013
+ * Wrap this component around parts of your application. It will catch any uncaught errors and display an alert, and allows you to continue using the rest of your application.
1014
+ *
1015
+ * @example
1016
+ * ``` <ErrorBoundary><ExampleComponent /></ErrorBoundary> ```
1017
+ */
1018
+
1019
+ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
1020
+ _inherits(ErrorBoundary, _React$Component);
1021
+
1022
+ var _super = _createSuper(ErrorBoundary);
1023
+
1024
+ function ErrorBoundary(props) {
1025
+ var _this;
1026
+
1027
+ _classCallCheck(this, ErrorBoundary);
1028
+
1029
+ _this = _super.call(this, props);
1030
+ _this.state = {
1031
+ error: null,
1032
+ errorInfo: null
1033
+ };
1034
+ return _this;
1035
+ }
1036
+
1037
+ _createClass(ErrorBoundary, [{
1038
+ key: "componentDidCatch",
1039
+ value: function componentDidCatch(error, errorInfo) {
1040
+ var onError = this.props.onError;
1041
+ this.setState({
1042
+ error: error,
1043
+ errorInfo: errorInfo
1044
+ });
1045
+ onError(error, errorInfo);
1046
+ }
1047
+ }, {
1048
+ key: "render",
1049
+ value: function render() {
1050
+ var _this$state = this.state,
1051
+ error = _this$state.error,
1052
+ errorInfo = _this$state.errorInfo;
1053
+ var children = this.props.children;
1054
+
1055
+ if (error) {
1056
+ return /*#__PURE__*/React.createElement("div", {
1057
+ style: {
1058
+ whiteSpace: 'pre-wrap'
1059
+ }
1060
+ }, /*#__PURE__*/React.createElement(AlertBanner, {
1061
+ severity: "error",
1062
+ title: "Woops, an error has occurred. Please report the error shown below and reload the page if needed.",
1063
+ info: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("br", null), error.toString(), /*#__PURE__*/React.createElement("br", null), errorInfo && errorInfo.componentStack, /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Link, {
1064
+ underline: "always",
1065
+ style: {
1066
+ cursor: 'pointer'
1067
+ },
1068
+ onClick: function onClick() {
1069
+ return window.location.reload();
1070
+ }
1071
+ }, "Reload page"))
1072
+ }));
1073
+ }
1074
+
1075
+ return children;
1076
+ }
1077
+ }], [{
1078
+ key: "getDerivedStateFromError",
1079
+ value: function getDerivedStateFromError(error) {
1080
+ return {
1081
+ error: error
1082
+ };
1083
+ }
1084
+ }]);
1085
+
1086
+ return ErrorBoundary;
1087
+ }(React.Component);
1088
+ ErrorBoundary.defaultProps = {
1089
+ onError: function onError() {
1090
+ return null;
1091
+ }
1092
+ };
1093
+
909
1094
  /* *
910
1095
  * Licensed under the Apache License, Version 2.0 (the "License");
911
1096
  * you may not use this file except in compliance with the License.
@@ -2217,4 +2402,4 @@ var getAxiosErrorMessage = function getAxiosErrorMessage(error) {
2217
2402
  return 'An error has occurred';
2218
2403
  };
2219
2404
 
2220
- export { AlertBanner, AppHeader, AppLayout, ConfirmationDialog, ConfirmationServiceProvider, CustomSlider, DraggableComponent$1 as Draggable, HIDDEN_INPUT_HELPER_IS_DRAFT, ResizeComponent as Resizable, StatusTag, ToolContainer, DraggableComponent as ToolContainerDraggable, ToolFooter, ToolHeader, UserMenu, UserMenuItemCheatSheet, MenuItemTheme as UserMenuItemTheme, getAxiosErrorMessage, getInitials, isAxiosError, showPrompt, sliderStyles, useConfirmationDialog, useDialogActions, useDraftFormHelpers, useIsMounted, usePoller, usePreventBrowserClose, usePrevious, useUserMenu };
2405
+ export { AlertBanner, AppHeader, AppLayout, ConfirmationDialog, ConfirmationServiceProvider, CustomSlider, DraggableComponent$1 as Draggable, ErrorBoundary, HIDDEN_INPUT_HELPER_IS_DRAFT, ResizeComponent as Resizable, StatusTag, ToolContainer, DraggableComponent as ToolContainerDraggable, ToolFooter, ToolHeader, UserMenu, UserMenuItemCheatSheet, MenuItemTheme as UserMenuItemTheme, getAxiosErrorMessage, getInitials, isAxiosError, showPrompt, sliderStyles, useConfirmationDialog, useDialogActions, useDraftFormHelpers, useIsMounted, usePoller, usePreventBrowserClose, usePrevious, useUserMenu };
package/shared.umd.js CHANGED
@@ -42,6 +42,22 @@
42
42
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
43
43
  PERFORMANCE OF THIS SOFTWARE.
44
44
  ***************************************************************************** */
45
+ /* global Reflect, Promise */
46
+
47
+ var extendStatics = function(d, b) {
48
+ extendStatics = Object.setPrototypeOf ||
49
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
50
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
51
+ return extendStatics(d, b);
52
+ };
53
+
54
+ function __extends(d, b) {
55
+ if (typeof b !== "function" && b !== null)
56
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
57
+ extendStatics(d, b);
58
+ function __() { this.constructor = d; }
59
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
60
+ }
45
61
 
46
62
  var __assign = function() {
47
63
  __assign = Object.assign || function __assign(t) {
@@ -208,7 +224,8 @@
208
224
  onClick: function onClick() {
209
225
  return onClose('CANCELLED');
210
226
  },
211
- autoFocus: true
227
+ autoFocus: true,
228
+ disableRipple: true
212
229
  }, cancelLabel), /*#__PURE__*/React__namespace.createElement(core.Button, {
213
230
  "data-testid": "conformationDialog-confirm",
214
231
  color: "secondary",
@@ -853,6 +870,81 @@
853
870
  }, props), children);
854
871
  };
855
872
 
873
+ /**
874
+ * ErrorBoundary
875
+ * Wrap this component around parts of your application. It will catch any uncaught errors and display an alert, and allows you to continue using the rest of your application.
876
+ *
877
+ * @example
878
+ * ``` <ErrorBoundary><ExampleComponent /></ErrorBoundary> ```
879
+ */
880
+
881
+ var ErrorBoundary =
882
+ /** @class */
883
+ function (_super) {
884
+ __extends(ErrorBoundary, _super);
885
+
886
+ function ErrorBoundary(props) {
887
+ var _this = _super.call(this, props) || this;
888
+
889
+ _this.state = {
890
+ error: null,
891
+ errorInfo: null
892
+ };
893
+ return _this;
894
+ }
895
+
896
+ ErrorBoundary.getDerivedStateFromError = function (error) {
897
+ return {
898
+ error: error
899
+ };
900
+ };
901
+
902
+ ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
903
+ var onError = this.props.onError;
904
+ this.setState({
905
+ error: error,
906
+ errorInfo: errorInfo
907
+ });
908
+ onError(error, errorInfo);
909
+ };
910
+
911
+ ErrorBoundary.prototype.render = function () {
912
+ var _a = this.state,
913
+ error = _a.error,
914
+ errorInfo = _a.errorInfo;
915
+ var children = this.props.children;
916
+
917
+ if (error) {
918
+ return /*#__PURE__*/React__namespace.createElement("div", {
919
+ style: {
920
+ whiteSpace: 'pre-wrap'
921
+ }
922
+ }, /*#__PURE__*/React__namespace.createElement(AlertBanner, {
923
+ severity: "error",
924
+ title: "Woops, an error has occurred. Please report the error shown below and reload the page if needed.",
925
+ info: /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("br", null), error.toString(), /*#__PURE__*/React__namespace.createElement("br", null), errorInfo && errorInfo.componentStack, /*#__PURE__*/React__namespace.createElement("br", null), /*#__PURE__*/React__namespace.createElement("br", null), /*#__PURE__*/React__namespace.createElement(core.Link, {
926
+ underline: "always",
927
+ style: {
928
+ cursor: 'pointer'
929
+ },
930
+ onClick: function onClick() {
931
+ return window.location.reload();
932
+ }
933
+ }, "Reload page"))
934
+ }));
935
+ }
936
+
937
+ return children;
938
+ };
939
+
940
+ ErrorBoundary.defaultProps = {
941
+ onError: function onError() {
942
+ return null;
943
+ }
944
+ };
945
+ return ErrorBoundary;
946
+ }(React__namespace.Component);
947
+
856
948
  /* *
857
949
  * Licensed under the Apache License, Version 2.0 (the "License");
858
950
  * you may not use this file except in compliance with the License.
@@ -2203,6 +2295,7 @@
2203
2295
  exports.ConfirmationServiceProvider = ConfirmationServiceProvider;
2204
2296
  exports.CustomSlider = CustomSlider;
2205
2297
  exports.Draggable = DraggableComponent$1;
2298
+ exports.ErrorBoundary = ErrorBoundary;
2206
2299
  exports.HIDDEN_INPUT_HELPER_IS_DRAFT = HIDDEN_INPUT_HELPER_IS_DRAFT;
2207
2300
  exports.Resizable = ResizeComponent;
2208
2301
  exports.StatusTag = StatusTag;