@zohodesk/utils 1.3.15 → 1.3.17

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.
Files changed (64) hide show
  1. package/README.md +16 -29
  2. package/es/StringUtils.js +2 -6
  3. package/es/abbreviateNumber.js +1 -4
  4. package/es/compileClassNames.js +4 -9
  5. package/es/constantProps/constant.js +3 -0
  6. package/es/createTemplateLiteral.js +2 -10
  7. package/es/crud/ArrayManager.js +62 -0
  8. package/es/crud/ObjectManager.js +53 -0
  9. package/es/crud/arrayCRUD.js +71 -0
  10. package/es/crud/objectCRUD.js +45 -0
  11. package/es/deepEqual.js +26 -0
  12. package/es/eventListenerUtils.js +24 -0
  13. package/es/getCompliedClassName.js +1 -6
  14. package/es/getCompliedCustomId.js +5 -7
  15. package/es/getCurrentTime.js +18 -0
  16. package/es/index.js +3 -1
  17. package/es/loadResource.js +1 -2
  18. package/es/mergeStyle.js +1 -3
  19. package/es/uniqueNumber.js +1 -2
  20. package/lib/ErrorBoundary.js +78 -0
  21. package/lib/StringUtils.js +343 -0
  22. package/lib/abbreviateNumber.js +51 -0
  23. package/lib/accessKeyCodes.js +26 -0
  24. package/lib/applyOpenToCustomize.js +41 -0
  25. package/lib/combineCustomStyle.js +52 -0
  26. package/lib/compileClassNames.js +45 -0
  27. package/lib/constantProps/constant.js +14 -0
  28. package/lib/constantProps/index.js +18 -0
  29. package/lib/constantProps/uiProps.js +71 -0
  30. package/lib/contextFactory.js +23 -0
  31. package/lib/createTemplateLiteral.js +84 -0
  32. package/lib/crud/ArrayManager.js +91 -0
  33. package/lib/crud/ObjectManager.js +81 -0
  34. package/lib/crud/arrayCRUD.js +110 -0
  35. package/lib/crud/objectCRUD.js +66 -0
  36. package/lib/dataTypes.js +42 -0
  37. package/lib/debounce.js +33 -0
  38. package/lib/deepEqual.js +39 -0
  39. package/lib/disCustomStyleProps.js +46 -0
  40. package/lib/eventListenerUtils.js +36 -0
  41. package/lib/getCompliedClassName.js +24 -0
  42. package/lib/getCompliedCustomId.js +37 -0
  43. package/lib/getCurrentTime.js +25 -0
  44. package/lib/getCustomBoundingClientRect.js +18 -0
  45. package/lib/index.js +135 -0
  46. package/lib/isTouchDevice.js +16 -0
  47. package/lib/jsonToQueryString.js +13 -0
  48. package/lib/loadResource.js +63 -0
  49. package/lib/mergeStyle.js +65 -0
  50. package/lib/objectUtils.js +14 -0
  51. package/lib/omit.js +20 -0
  52. package/lib/props/automationProps.js +19 -0
  53. package/lib/props/customReducerPropTypes.js +17 -0
  54. package/lib/props/customStyleProps.js +21 -0
  55. package/lib/props/generalAriaProps.js +17 -0
  56. package/lib/props/tagAttributeProps.js +58 -0
  57. package/lib/props/tagGeneralAttributeProps.js +58 -0
  58. package/lib/props/uiProps.js +138 -0
  59. package/lib/reducerHandler.js +42 -0
  60. package/lib/renderNode.js +44 -0
  61. package/lib/replaceAtFirst.js +12 -0
  62. package/lib/replaceAtLast.js +10 -0
  63. package/lib/uniqueNumber.js +22 -0
  64. package/package.json +29 -11
package/README.md CHANGED
@@ -1,38 +1,25 @@
1
- # DOT - Util Collections
1
+ # @zohodesk/utils
2
2
 
3
- In this package, We provide lots of util fuctions for web devlopment
3
+ Common JavaScript utilities for DOT web development. This package is part of the **DOT System** (**D**esign **O**ptimization **T**hinking).
4
4
 
5
- # 1.3.15
5
+ ## Installation
6
6
 
7
- - **renderNodeUtils**
8
- - `renderNode` function added to render content that can be either a function or a React element.
9
- - `isRenderable` function added to check if the content is renderable (either a function or a valid React element).
10
-
11
- # 1.3.14
12
-
13
- - **StringUtils**
14
- - String Utils Methods added
7
+ ```bash
8
+ npm install @zohodesk/utils
9
+ ```
15
10
 
16
- # 1.3.13
11
+ ## Usage
17
12
 
18
- - `mergeStyle` issue fix
13
+ Import the utilities you need from `@zohodesk/utils` and use them across your app for shared helpers, including:
19
14
 
20
- # 1.3.12
15
+ - Class name and style helpers
16
+ - Event and timing utilities
17
+ - Small React and DOM-related helpers
21
18
 
22
- - `mergeStyle` functionality updated. Composed classes will also update if it is inside that file.
23
19
  ```js
24
- // Before
25
- const style = mergeStyle(
26
- { a: '1', b: '1 2' },
27
- { a: 'a' }
28
- );
29
- // style = { a: '1 a', b: '1 2' }
30
-
31
- // After
32
- const style = mergeStyle(
33
- { a: '1', b: '1 2' },
34
- { a: 'a' }
35
- );
36
- // style = { a: '1 a', b: '1 a 2' }
20
+ import * as utils from '@zohodesk/utils';
37
21
  ```
38
- - `compileClassNames` code optimized. Will not support other than object as argument.
22
+
23
+ ## Changelog
24
+
25
+ See [CHANGELOG.md](https://unpkg.com/@zohodesk/utils/CHANGELOG.md) for details on release history and updates.
package/es/StringUtils.js CHANGED
@@ -138,9 +138,7 @@ export function reverseString(string) {
138
138
  * @returns {string} The truncated string.
139
139
  */
140
140
 
141
- export function truncate(string) {
142
- let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
143
-
141
+ export function truncate(string, maxLength = 1) {
144
142
  if (!isStringEmpty() && string.length > maxLength) {
145
143
  return string.slice(0, maxLength) + '...';
146
144
  }
@@ -197,9 +195,7 @@ export function toSnakeCase(string) {
197
195
  * @returns {string} The concatenated string with the specified delimiter.
198
196
  */
199
197
 
200
- export function joinArray(array) {
201
- let delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ', ';
202
-
198
+ export function joinArray(array, delimiter = ', ') {
203
199
  if (Array.isArray(array)) {
204
200
  return array.join(delimiter);
205
201
  }
@@ -7,10 +7,7 @@
7
7
  * @param {number} options.decimals
8
8
  * @returns
9
9
  */
10
- export default function abbreviateNumber() {
11
- let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
12
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13
-
10
+ export default function abbreviateNumber(count = 0, options = {}) {
14
11
  if (typeof count === 'string') {
15
12
  count = parseInt(count);
16
13
  }
@@ -1,9 +1,9 @@
1
1
  import dataTypes, { isDataTypeOf } from "./dataTypes";
2
2
  import { hasOwnProperty } from "./objectUtils";
3
3
 
4
- const collectClassNames = function (processedClassNameList) {
5
- for (let index = 0; index < (arguments.length <= 1 ? 0 : arguments.length - 1); index++) {
6
- let classInfo = index + 1 < 1 || arguments.length <= index + 1 ? undefined : arguments[index + 1];
4
+ const collectClassNames = (processedClassNameList, ...classinfoList) => {
5
+ for (let index = 0; index < classinfoList.length; index++) {
6
+ let classInfo = classinfoList[index];
7
7
 
8
8
  if (!classInfo) {
9
9
  continue;
@@ -17,13 +17,8 @@ const collectClassNames = function (processedClassNameList) {
17
17
  }
18
18
  };
19
19
 
20
- export default function compileClassNames() {
20
+ export default function compileClassNames(...classinfoList) {
21
21
  let resultClassNameList = [];
22
-
23
- for (var _len = arguments.length, classinfoList = new Array(_len), _key = 0; _key < _len; _key++) {
24
- classinfoList[_key] = arguments[_key];
25
- }
26
-
27
22
  collectClassNames(resultClassNameList, ...classinfoList);
28
23
  return resultClassNameList.filter(a => a !== '').join(' ');
29
24
  }
@@ -0,0 +1,3 @@
1
+ export const DUMMY_OBJECT = Object.freeze({});
2
+ export const DUMMY_ARRAY = Object.freeze([]);
3
+ export const DUMMY_FUNCTION = () => {};
@@ -1,13 +1,5 @@
1
- export default function createTemplateLiteral(templateStrings) {
2
- for (var _len = arguments.length, expressionKeys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3
- expressionKeys[_key - 1] = arguments[_key];
4
- }
5
-
6
- return function () {
7
- for (var _len2 = arguments.length, expressionValues = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
8
- expressionValues[_key2] = arguments[_key2];
9
- }
10
-
1
+ export default function createTemplateLiteral(templateStrings, ...expressionKeys) {
2
+ return (...expressionValues) => {
11
3
  let resultString = [templateStrings[0]];
12
4
  expressionKeys.forEach(function (expressionKey, i) {
13
5
  let expressionValue = expressionValues[i];
@@ -0,0 +1,62 @@
1
+ import { appendToArray, deleteFromArrayOfObjectById, deleteFromArrayByItem, updateArrayOfObjectItemById, updateArrayItemByItem, emptyArray } from "./arrayCRUD";
2
+ import { DUMMY_ARRAY } from "../constantProps/constant";
3
+
4
+ class ArrayManager {
5
+ constructor(initialArray = DUMMY_ARRAY) {
6
+ this.array = initialArray;
7
+ }
8
+
9
+ addValue(item) {
10
+ this.array = appendToArray({
11
+ array: this.array,
12
+ item
13
+ });
14
+ return this.array;
15
+ }
16
+
17
+ removeValueById(id) {
18
+ this.array = deleteFromArrayOfObjectById({
19
+ arrayOfObject: this.array,
20
+ id
21
+ });
22
+ return this.array;
23
+ }
24
+
25
+ removeValueByItem(item) {
26
+ this.array = deleteFromArrayByItem({
27
+ array: this.array,
28
+ item
29
+ });
30
+ return this.array;
31
+ }
32
+
33
+ clearValue() {
34
+ this.array = emptyArray();
35
+ return this.array;
36
+ }
37
+
38
+ updateValueById(id, newItem) {
39
+ this.array = updateArrayOfObjectItemById({
40
+ arrayOfObject: this.array,
41
+ id,
42
+ newItem
43
+ });
44
+ return this.array;
45
+ }
46
+
47
+ updateValueByItem(currentItem, newItem) {
48
+ this.array = updateArrayItemByItem({
49
+ array: this.array,
50
+ currentItem,
51
+ newItem
52
+ });
53
+ return this.array;
54
+ }
55
+
56
+ getValue() {
57
+ return this.array;
58
+ }
59
+
60
+ }
61
+
62
+ export default ArrayManager;
@@ -0,0 +1,53 @@
1
+ import { emptyObject, mergeObjects, updateObjectValueByKey, removeObjectByKey, removeObjectByKeys } from "./objectCRUD";
2
+ import { DUMMY_OBJECT } from "../constantProps/constant";
3
+
4
+ class ObjectManager {
5
+ constructor(initialObject = DUMMY_OBJECT) {
6
+ this.object = initialObject;
7
+ }
8
+
9
+ setValue(newObject) {
10
+ this.object = mergeObjects({
11
+ object: this.object,
12
+ newObject
13
+ });
14
+ return this.object;
15
+ }
16
+
17
+ clearValue() {
18
+ this.object = emptyObject();
19
+ return this.object;
20
+ }
21
+
22
+ updateValueByKey(key, value) {
23
+ this.object = updateObjectValueByKey({
24
+ object: this.object,
25
+ key,
26
+ value
27
+ });
28
+ return this.object;
29
+ }
30
+
31
+ removeValueByKeys(keys) {
32
+ this.object = removeObjectByKeys({
33
+ object: this.object,
34
+ keys
35
+ });
36
+ return this.object;
37
+ }
38
+
39
+ removeValueByKey(key) {
40
+ this.object = removeObjectByKey({
41
+ object: this.object,
42
+ key
43
+ });
44
+ return this.object;
45
+ }
46
+
47
+ getValue() {
48
+ return this.object;
49
+ }
50
+
51
+ }
52
+
53
+ export default ObjectManager;
@@ -0,0 +1,71 @@
1
+ import { DUMMY_ARRAY } from "../constantProps/constant";
2
+ import { deepEqual } from "../deepEqual";
3
+ export const appendToArray = ({
4
+ array,
5
+ item
6
+ }) => {
7
+ return [...array, item];
8
+ };
9
+ export const updateArrayOfObjectItemById = ({
10
+ arrayOfObject,
11
+ id,
12
+ newItem
13
+ }) => {
14
+ let found = false;
15
+ return arrayOfObject.map(object => {
16
+ if (!found && id !== undefined && object.id === id) {
17
+ found = true;
18
+ return Array.isArray(newItem) ? [...newItem] : typeof newItem === 'object' ? { ...object,
19
+ ...newItem
20
+ } : newItem;
21
+ }
22
+
23
+ return object;
24
+ });
25
+ };
26
+ export const updateArrayItemByItem = ({
27
+ array,
28
+ currentItem,
29
+ newItem
30
+ }) => {
31
+ let found = false;
32
+ return array.map(arrayItem => {
33
+ if (!found && currentItem !== undefined && deepEqual(arrayItem, currentItem)) {
34
+ found = true;
35
+ return newItem;
36
+ }
37
+
38
+ return arrayItem;
39
+ });
40
+ };
41
+ export const deleteFromArrayOfObjectById = ({
42
+ arrayOfObject,
43
+ id
44
+ }) => {
45
+ let found = false;
46
+ return arrayOfObject.filter(object => {
47
+ if (!found && id !== undefined && object.id === id) {
48
+ found = true;
49
+ return false;
50
+ }
51
+
52
+ return true;
53
+ });
54
+ };
55
+ export const deleteFromArrayByItem = ({
56
+ array,
57
+ currentItem
58
+ }) => {
59
+ let found = false;
60
+ return array.filter(arrayItem => {
61
+ if (!found && currentItem !== undefined && deepEqual(arrayItem, currentItem)) {
62
+ found = true;
63
+ return false;
64
+ }
65
+
66
+ return true;
67
+ });
68
+ };
69
+ export const emptyArray = () => {
70
+ return DUMMY_ARRAY;
71
+ };
@@ -0,0 +1,45 @@
1
+ import { DUMMY_OBJECT } from "../constantProps/constant";
2
+ export const mergeObjects = ({
3
+ object,
4
+ newObject
5
+ }) => {
6
+ return { ...object,
7
+ ...newObject
8
+ };
9
+ };
10
+ export const emptyObject = () => {
11
+ return DUMMY_OBJECT;
12
+ };
13
+ export const updateObjectValueByKey = ({
14
+ object,
15
+ key,
16
+ value
17
+ }) => {
18
+ return { ...object,
19
+ [key]: value
20
+ };
21
+ };
22
+ export const removeObjectByKeys = ({
23
+ object,
24
+ keys
25
+ }) => {
26
+ const newObject = { ...object
27
+ };
28
+
29
+ if (Array.isArray(keys)) {
30
+ keys.forEach(key => {
31
+ delete newObject[key];
32
+ });
33
+ }
34
+
35
+ return newObject;
36
+ };
37
+ export const removeObjectByKey = ({
38
+ object,
39
+ key
40
+ }) => {
41
+ const newObject = { ...object
42
+ };
43
+ delete newObject[key];
44
+ return newObject;
45
+ };
@@ -0,0 +1,26 @@
1
+ export const deepEqual = (a, b) => {
2
+ if (a === b) {
3
+ return true;
4
+ }
5
+
6
+ if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) {
7
+ if (Array.isArray(a) !== Array.isArray(b)) {
8
+ return false;
9
+ }
10
+
11
+ const keysA = Object.keys(a);
12
+ const keysB = Object.keys(b);
13
+
14
+ if (keysA.length !== keysB.length) {
15
+ return false;
16
+ }
17
+
18
+ return keysA.every(key => deepEqual(a[key], b[key]));
19
+ }
20
+
21
+ if (typeof a === 'function' && typeof b === 'function') {
22
+ return a.toString().replace(/\s+/g, '') === b.toString().replace(/\s+/g, '');
23
+ }
24
+
25
+ return false;
26
+ };
@@ -0,0 +1,24 @@
1
+ export const addCustomEventListener = ({
2
+ eventName,
3
+ callback,
4
+ targetElement,
5
+ options
6
+ }) => {
7
+ if (!targetElement || typeof targetElement.addEventListener !== 'function') {
8
+ throw new Error('addCustomEventListener: targetElement is not a valid EventTarget. ' + 'Received: ' + String(targetElement));
9
+ }
10
+
11
+ targetElement.addEventListener(eventName, callback, options);
12
+ };
13
+ export const removeCustomEventListener = ({
14
+ eventName,
15
+ callback,
16
+ targetElement,
17
+ options
18
+ }) => {
19
+ if (!targetElement || typeof targetElement.removeEventListener !== 'function') {
20
+ throw new Error('removeCustomEventListener: targetElement is not a valid EventTarget. ' + 'Received: ' + String(targetElement));
21
+ }
22
+
23
+ targetElement.removeEventListener(eventName, callback, options);
24
+ };
@@ -1,11 +1,6 @@
1
1
  import compileClassNames from "./compileClassNames";
2
- export default (function (customClassName) {
2
+ export default ((customClassName, ...props) => {
3
3
  let isPlainClassName = typeof customClassName === "string" ? true : false;
4
-
5
- for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6
- props[_key - 1] = arguments[_key];
7
- }
8
-
9
4
  return compileClassNames(...props, {
10
5
  [customClassName]: !!isPlainClassName
11
6
  });
@@ -1,10 +1,8 @@
1
- export default (function (_ref, defaultCustomId) {
2
- let {
3
- customId,
4
- customIdPrefix = "",
5
- customIdSuffix = ""
6
- } = _ref;
7
- let otherCustomOption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1
+ export default (({
2
+ customId,
3
+ customIdPrefix = "",
4
+ customIdSuffix = ""
5
+ }, defaultCustomId, otherCustomOption = []) => {
8
6
  let returnId = customId;
9
7
 
10
8
  if (typeof defaultCustomId === "function") {
@@ -0,0 +1,18 @@
1
+ export default function getCurrentTime() {
2
+ const now = new Date();
3
+ const hours = now.getHours();
4
+ const minutes = now.getMinutes().toString().padStart(2, '0');
5
+ const seconds = now.getSeconds().toString().padStart(2, '0');
6
+ const ampm = hours >= 12 ? 'PM' : 'AM';
7
+ const formattedHours = hours % 12 || 12; // Convert 24-hour time to 12-hour format
8
+
9
+ const hours24 = hours.toString().padStart(2, '0');
10
+ return {
11
+ format12h: `${formattedHours}:${minutes}:${seconds} ${ampm}`,
12
+ format24h: `${hours24}:${minutes}:${seconds}`,
13
+ hours: hours,
14
+ minutes: parseInt(minutes),
15
+ seconds: parseInt(seconds),
16
+ meridiem: ampm
17
+ };
18
+ }
package/es/index.js CHANGED
@@ -8,4 +8,6 @@ export { default as compileClassNames } from "./compileClassNames";
8
8
  export { default as ErrorBoundary } from "./ErrorBoundary";
9
9
  export { default as loadResource } from "./loadResource";
10
10
  export { default as accessKeyCodes, accessKeyNames } from "./accessKeyCodes";
11
- export { default as renderNode, isRenderable } from "./renderNode";
11
+ export { default as renderNode, isRenderable } from "./renderNode";
12
+ export { default as getCurrentTime } from "./getCurrentTime";
13
+ export { addCustomEventListener, removeCustomEventListener } from "./eventListenerUtils";
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
2
 
3
3
  /* use promise and remove callback */
4
- export default function loadResource(url, type, id, callback) {
5
- let needDefer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
4
+ export default function loadResource(url, type, id, callback, needDefer = true) {
6
5
  return new Promise(resolve => {
7
6
  let css;
8
7
  let script;
package/es/mergeStyle.js CHANGED
@@ -1,9 +1,7 @@
1
1
  const REPLACER_SYMBOL = '$'; // $ startWith is used for replace the existing style.
2
2
  // all other will be append
3
3
 
4
- export default function mergeStyle(defaultStyle) {
5
- let customStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
- let additionalStyle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
4
+ export default function mergeStyle(defaultStyle, customStyle = {}, additionalStyle = []) {
7
5
  // if(!Object.keys(defaultStyle).includes('base')) {
8
6
  // throw new Error(`STYLE CUSTOMIZATION RULE - Your style sheet should have "base" class name for customization`);
9
7
  // }
@@ -1,5 +1,4 @@
1
- export default function uniqueNumber() {
2
- let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1
+ export default function uniqueNumber(prefix = '') {
3
2
  //let randomId = (Date.now() + Math.random()).toString(36);
4
3
  var date = Date.now(); // If created at same millisecond as previous
5
4
 
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
+
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
+
20
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
21
+
22
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
+
24
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
25
+
26
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
27
+
28
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
+
30
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
31
+
32
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
+
34
+ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
35
+ _inherits(ErrorBoundary, _React$Component);
36
+
37
+ var _super = _createSuper(ErrorBoundary);
38
+
39
+ function ErrorBoundary(props) {
40
+ var _this;
41
+
42
+ _classCallCheck(this, ErrorBoundary);
43
+
44
+ _this = _super.call(this, props);
45
+ _this.state = {
46
+ hasError: false
47
+ };
48
+ return _this;
49
+ }
50
+
51
+ _createClass(ErrorBoundary, [{
52
+ key: "componentDidCatch",
53
+ value: function componentDidCatch(error, errorInfo) {
54
+ console.log(error, errorInfo);
55
+ }
56
+ }, {
57
+ key: "render",
58
+ value: function render() {
59
+ if (this.state.hasError) {
60
+ return this.props.renderFallback(this.state.error);
61
+ }
62
+
63
+ return this.props.children;
64
+ }
65
+ }], [{
66
+ key: "getDerivedStateFromError",
67
+ value: function getDerivedStateFromError(error) {
68
+ return {
69
+ hasError: true,
70
+ error: error
71
+ };
72
+ }
73
+ }]);
74
+
75
+ return ErrorBoundary;
76
+ }(_react["default"].Component);
77
+
78
+ exports["default"] = ErrorBoundary;