@commercetools-uikit/utils 15.11.2 → 15.13.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.
@@ -8,7 +8,7 @@ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/ins
8
8
  var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
9
9
  var isPropValid = require('@emotion/is-prop-valid');
10
10
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
11
- var warning$2 = require('warning');
11
+ var react = require('react');
12
12
  var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
13
13
 
14
14
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -18,7 +18,6 @@ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInsta
18
18
  var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
19
19
  var isPropValid__default = /*#__PURE__*/_interopDefault(isPropValid);
20
20
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
21
- var warning__default = /*#__PURE__*/_interopDefault(warning$2);
22
21
  var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
23
22
 
24
23
  var regexpData$1 = /^data-/;
@@ -62,25 +61,60 @@ function isNumberish(number) {
62
61
  return !/[^(\-?)\d,.\s]/.test(number);
63
62
  }
64
63
 
65
- function warnDeprecatedComponent(componentName) {
64
+ // "Assertions require every name in the call target to be declared with an explicit type annotation."
65
+ // See https://github.com/microsoft/TypeScript/pull/33622#issuecomment-575301357
66
+
67
+ var isProduction = process.env.NODE_ENV === 'production'; // Throw an error if the condition fails
68
+ // Strip out error messages for production
69
+ // > Not providing an inline default argument for message as the result is smaller
70
+
71
+ var warning = function warning(condition, message) {
66
72
  var _context;
67
73
 
68
- var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
74
+ var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Warning';
69
75
 
70
- var message = _concatInstanceProperty__default["default"](_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
76
+ if (isProduction || condition) {
77
+ return;
78
+ }
71
79
 
72
- process.env.NODE_ENV !== "production" ? warning__default["default"](false, message) : void 0;
73
- }
80
+ console.warn(_concatInstanceProperty__default["default"](_context = "".concat(prefix, ": ")).call(_context, message));
81
+ };
82
+ var useWarning = function useWarning(condition, message) {
83
+ react.useEffect(function () {
84
+ process.env.NODE_ENV !== "production" ? warning(condition, message) : void 0; // eslint-disable-next-line react-hooks/exhaustive-deps
85
+ }, []);
86
+ };
87
+
88
+ var getMessage$1 = function getMessage(componentName, additionalMessage) {
89
+ var _context;
90
+
91
+ return _concatInstanceProperty__default["default"](_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
92
+ };
93
+
94
+ var warnDeprecatedComponent = function warnDeprecatedComponent(componentName) {
95
+ var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
96
+ return process.env.NODE_ENV !== "production" ? warning(false, getMessage$1(componentName, additionalMessage)) : void 0;
97
+ };
98
+ var useWarnDeprecatedComponent = function useWarnDeprecatedComponent(componentName) {
99
+ var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
100
+ return useWarning(false, getMessage$1(componentName, additionalMessage));
101
+ };
74
102
 
75
- function warnDeprecatedProp(propName, componentName) {
103
+ var getMessage = function getMessage(propName, componentName) {
76
104
  var _context, _context2;
77
105
 
78
106
  var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
107
+ return _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" component has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
108
+ };
79
109
 
80
- var message = _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
81
-
82
- process.env.NODE_ENV !== "production" ? warning__default["default"](false, message) : void 0;
83
- }
110
+ var warnDeprecatedProp = function warnDeprecatedProp(condition, propName, componentName) {
111
+ var additionalMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
112
+ process.env.NODE_ENV !== "production" ? warning(condition, getMessage(propName, componentName, additionalMessage)) : void 0;
113
+ };
114
+ var useWarnDeprecatedProp = function useWarnDeprecatedProp(condition, propName, componentName) {
115
+ var additionalMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
116
+ useWarning(condition, getMessage(propName, componentName, additionalMessage));
117
+ };
84
118
 
85
119
  // Whenever a field requires a unique id, this factory can be used
86
120
  // to create a function returning unique ids.
@@ -179,34 +213,8 @@ var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.do
179
213
  var SafeHTMLElement = canUseDOM ? window.HTMLElement : {};
180
214
  var SafeHTMLElement$1 = SafeHTMLElement;
181
215
 
182
- // To avoid getting the following error, we type the entire function.
183
- // "Assertions require every name in the call target to be declared with an explicit type annotation."
184
- // See https://github.com/microsoft/TypeScript/pull/33622#issuecomment-575301357
185
- var isProduction = process.env.NODE_ENV === 'production'; // @TODO: allow consumer to set the prefix e.g `[ Text.Body ]`
186
-
187
- var prefix = 'Warning'; // Throw an error if the condition fails
188
- // Strip out error messages for production
189
- // > Not providing an inline default argument for message as the result is smaller
190
-
191
- var warning = function warning(condition, message) {
192
- if (isProduction) {
193
- return;
194
- }
195
-
196
- if (condition) {
197
- return;
198
- } // Condition not passed
199
- // When not in production we allow the message to pass through
200
- // *This block will be removed in production builds*
201
-
202
-
203
- throw new Error("".concat(prefix, ": ").concat(message || ''));
204
- };
205
-
206
- var warning$1 = warning;
207
-
208
216
  // NOTE: This string will be replaced on build time with the package version.
209
- var version = "15.11.2";
217
+ var version = "15.13.0";
210
218
 
211
219
  exports.SafeHTMLElement = SafeHTMLElement$1;
212
220
  exports.canUseDOM = canUseDOM;
@@ -217,7 +225,10 @@ exports.filterInvalidAttributes = filterInvalidAttributes;
217
225
  exports.getFieldId = getFieldId$1;
218
226
  exports.isNumberish = isNumberish;
219
227
  exports.parseTime = parseTime$1;
228
+ exports.useWarnDeprecatedComponent = useWarnDeprecatedComponent;
229
+ exports.useWarnDeprecatedProp = useWarnDeprecatedProp;
230
+ exports.useWarning = useWarning;
220
231
  exports.version = version;
221
232
  exports.warnDeprecatedComponent = warnDeprecatedComponent;
222
233
  exports.warnDeprecatedProp = warnDeprecatedProp;
223
- exports.warning = warning$1;
234
+ exports.warning = warning;
@@ -8,7 +8,7 @@ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/ins
8
8
  var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
9
9
  var isPropValid = require('@emotion/is-prop-valid');
10
10
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
11
- require('warning');
11
+ var react = require('react');
12
12
  var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
13
13
 
14
14
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -61,21 +61,47 @@ function isNumberish(number) {
61
61
  return !/[^(\-?)\d,.\s]/.test(number);
62
62
  }
63
63
 
64
- function warnDeprecatedComponent(componentName) {
64
+ // Strip out error messages for production
65
+ // > Not providing an inline default argument for message as the result is smaller
66
+
67
+ var warning = function warning(condition, message) {
68
+
69
+ {
70
+ return;
71
+ }
72
+ };
73
+ var useWarning = function useWarning(condition, message) {
74
+ react.useEffect(function () {
75
+ }, []);
76
+ };
77
+
78
+ var getMessage$1 = function getMessage(componentName, additionalMessage) {
65
79
  var _context;
66
80
 
67
- var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
81
+ return _concatInstanceProperty__default["default"](_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
82
+ };
68
83
 
69
- _concatInstanceProperty__default["default"](_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
70
- }
84
+ var warnDeprecatedComponent = function warnDeprecatedComponent(componentName) {
85
+ return void 0;
86
+ };
87
+ var useWarnDeprecatedComponent = function useWarnDeprecatedComponent(componentName) {
88
+ var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
89
+ return useWarning(false, getMessage$1(componentName, additionalMessage));
90
+ };
71
91
 
72
- function warnDeprecatedProp(propName, componentName) {
92
+ var getMessage = function getMessage(propName, componentName) {
73
93
  var _context, _context2;
74
94
 
75
95
  var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
96
+ return _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" component has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
97
+ };
76
98
 
77
- _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
78
- }
99
+ var warnDeprecatedProp = function warnDeprecatedProp(condition, propName, componentName) {
100
+ };
101
+ var useWarnDeprecatedProp = function useWarnDeprecatedProp(condition, propName, componentName) {
102
+ var additionalMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
103
+ useWarning(condition, getMessage(propName, componentName, additionalMessage));
104
+ };
79
105
 
80
106
  // Whenever a field requires a unique id, this factory can be used
81
107
  // to create a function returning unique ids.
@@ -174,20 +200,8 @@ var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.do
174
200
  var SafeHTMLElement = canUseDOM ? window.HTMLElement : {};
175
201
  var SafeHTMLElement$1 = SafeHTMLElement;
176
202
 
177
- // To avoid getting the following error, we type the entire function.
178
- // Strip out error messages for production
179
- // > Not providing an inline default argument for message as the result is smaller
180
-
181
- var warning = function warning(condition, message) {
182
- {
183
- return;
184
- }
185
- };
186
-
187
- var warning$1 = warning;
188
-
189
203
  // NOTE: This string will be replaced on build time with the package version.
190
- var version = "15.11.2";
204
+ var version = "15.13.0";
191
205
 
192
206
  exports.SafeHTMLElement = SafeHTMLElement$1;
193
207
  exports.canUseDOM = canUseDOM;
@@ -198,7 +212,10 @@ exports.filterInvalidAttributes = filterInvalidAttributes;
198
212
  exports.getFieldId = getFieldId$1;
199
213
  exports.isNumberish = isNumberish;
200
214
  exports.parseTime = parseTime$1;
215
+ exports.useWarnDeprecatedComponent = useWarnDeprecatedComponent;
216
+ exports.useWarnDeprecatedProp = useWarnDeprecatedProp;
217
+ exports.useWarning = useWarning;
201
218
  exports.version = version;
202
219
  exports.warnDeprecatedComponent = warnDeprecatedComponent;
203
220
  exports.warnDeprecatedProp = warnDeprecatedProp;
204
- exports.warning = warning$1;
221
+ exports.warning = warning;
@@ -4,7 +4,7 @@ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/insta
4
4
  import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
5
5
  import isPropValid from '@emotion/is-prop-valid';
6
6
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
7
- import warning$2 from 'warning';
7
+ import { useEffect } from 'react';
8
8
  import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
9
9
 
10
10
  var regexpData$1 = /^data-/;
@@ -48,25 +48,60 @@ function isNumberish(number) {
48
48
  return !/[^(\-?)\d,.\s]/.test(number);
49
49
  }
50
50
 
51
- function warnDeprecatedComponent(componentName) {
51
+ // "Assertions require every name in the call target to be declared with an explicit type annotation."
52
+ // See https://github.com/microsoft/TypeScript/pull/33622#issuecomment-575301357
53
+
54
+ var isProduction = process.env.NODE_ENV === 'production'; // Throw an error if the condition fails
55
+ // Strip out error messages for production
56
+ // > Not providing an inline default argument for message as the result is smaller
57
+
58
+ var warning = function warning(condition, message) {
52
59
  var _context;
53
60
 
54
- var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
61
+ var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Warning';
55
62
 
56
- var message = _concatInstanceProperty(_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
63
+ if (isProduction || condition) {
64
+ return;
65
+ }
57
66
 
58
- process.env.NODE_ENV !== "production" ? warning$2(false, message) : void 0;
59
- }
67
+ console.warn(_concatInstanceProperty(_context = "".concat(prefix, ": ")).call(_context, message));
68
+ };
69
+ var useWarning = function useWarning(condition, message) {
70
+ useEffect(function () {
71
+ process.env.NODE_ENV !== "production" ? warning(condition, message) : void 0; // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, []);
73
+ };
74
+
75
+ var getMessage$1 = function getMessage(componentName, additionalMessage) {
76
+ var _context;
77
+
78
+ return _concatInstanceProperty(_context = "\"".concat(componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
79
+ };
80
+
81
+ var warnDeprecatedComponent = function warnDeprecatedComponent(componentName) {
82
+ var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
83
+ return process.env.NODE_ENV !== "production" ? warning(false, getMessage$1(componentName, additionalMessage)) : void 0;
84
+ };
85
+ var useWarnDeprecatedComponent = function useWarnDeprecatedComponent(componentName) {
86
+ var additionalMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
87
+ return useWarning(false, getMessage$1(componentName, additionalMessage));
88
+ };
60
89
 
61
- function warnDeprecatedProp(propName, componentName) {
90
+ var getMessage = function getMessage(propName, componentName) {
62
91
  var _context, _context2;
63
92
 
64
93
  var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
94
+ return _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" component has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage ? ' ' + additionalMessage : '');
95
+ };
65
96
 
66
- var message = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage);
67
-
68
- process.env.NODE_ENV !== "production" ? warning$2(false, message) : void 0;
69
- }
97
+ var warnDeprecatedProp = function warnDeprecatedProp(condition, propName, componentName) {
98
+ var additionalMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
99
+ process.env.NODE_ENV !== "production" ? warning(condition, getMessage(propName, componentName, additionalMessage)) : void 0;
100
+ };
101
+ var useWarnDeprecatedProp = function useWarnDeprecatedProp(condition, propName, componentName) {
102
+ var additionalMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
103
+ useWarning(condition, getMessage(propName, componentName, additionalMessage));
104
+ };
70
105
 
71
106
  // Whenever a field requires a unique id, this factory can be used
72
107
  // to create a function returning unique ids.
@@ -165,33 +200,7 @@ var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.do
165
200
  var SafeHTMLElement = canUseDOM ? window.HTMLElement : {};
166
201
  var SafeHTMLElement$1 = SafeHTMLElement;
167
202
 
168
- // To avoid getting the following error, we type the entire function.
169
- // "Assertions require every name in the call target to be declared with an explicit type annotation."
170
- // See https://github.com/microsoft/TypeScript/pull/33622#issuecomment-575301357
171
- var isProduction = process.env.NODE_ENV === 'production'; // @TODO: allow consumer to set the prefix e.g `[ Text.Body ]`
172
-
173
- var prefix = 'Warning'; // Throw an error if the condition fails
174
- // Strip out error messages for production
175
- // > Not providing an inline default argument for message as the result is smaller
176
-
177
- var warning = function warning(condition, message) {
178
- if (isProduction) {
179
- return;
180
- }
181
-
182
- if (condition) {
183
- return;
184
- } // Condition not passed
185
- // When not in production we allow the message to pass through
186
- // *This block will be removed in production builds*
187
-
188
-
189
- throw new Error("".concat(prefix, ": ").concat(message || ''));
190
- };
191
-
192
- var warning$1 = warning;
193
-
194
203
  // NOTE: This string will be replaced on build time with the package version.
195
- var version = "15.11.2";
204
+ var version = "15.13.0";
196
205
 
197
- export { SafeHTMLElement$1 as SafeHTMLElement, canUseDOM, createSequentialId, filterAriaAttributes, filterDataAttributes, filterInvalidAttributes, getFieldId$1 as getFieldId, isNumberish, parseTime$1 as parseTime, version, warnDeprecatedComponent, warnDeprecatedProp, warning$1 as warning };
206
+ export { SafeHTMLElement$1 as SafeHTMLElement, canUseDOM, createSequentialId, filterAriaAttributes, filterDataAttributes, filterInvalidAttributes, getFieldId$1 as getFieldId, isNumberish, parseTime$1 as parseTime, useWarnDeprecatedComponent, useWarnDeprecatedProp, useWarning, version, warnDeprecatedComponent, warnDeprecatedProp, warning };
@@ -2,12 +2,12 @@ export { default as filterDataAttributes } from './filter-data-attributes';
2
2
  export { default as filterAriaAttributes } from './filter-aria-attributes';
3
3
  export { default as filterInvalidAttributes } from './filter-invalid-attributes';
4
4
  export { default as isNumberish } from './is-numberish';
5
- export { default as warnDeprecatedComponent } from './warn-deprecated-component';
6
- export { default as warnDeprecatedProp } from './warn-deprecated-prop';
5
+ export { warnDeprecatedComponent, useWarnDeprecatedComponent, } from './warn-deprecated-component';
6
+ export { warnDeprecatedProp, useWarnDeprecatedProp, } from './warn-deprecated-prop';
7
7
  export { default as createSequentialId } from './create-sequential-id';
8
8
  export { default as getFieldId } from './get-field-id';
9
9
  export { default as parseTime } from './parse-time';
10
10
  export { canUseDOM } from './helpers/exenv';
11
11
  export { default as SafeHTMLElement } from './helpers/safeHTMLElement';
12
- export { default as warning } from './warning';
12
+ export { warning, useWarning } from './warning';
13
13
  export { default as version } from './version';
@@ -1 +1,2 @@
1
- export default function warnDeprecatedComponent(componentName: string, additionalMessage?: string): void;
1
+ export declare const warnDeprecatedComponent: (componentName: string, additionalMessage?: string) => void;
2
+ export declare const useWarnDeprecatedComponent: (componentName: string, additionalMessage?: string) => void;
@@ -1 +1,2 @@
1
- export default function warnDeprecatedProp(propName: string, componentName: string, additionalMessage?: string): void;
1
+ export declare const warnDeprecatedProp: (condition: boolean, propName: string, componentName: string, additionalMessage?: string) => void;
2
+ export declare const useWarnDeprecatedProp: (condition: boolean, propName: string, componentName: string, additionalMessage?: string) => void;
@@ -1,3 +1,4 @@
1
- type TWarningFunction = (condition: unknown, message?: string) => asserts condition is boolean;
2
- declare const warning: TWarningFunction;
3
- export default warning;
1
+ type TWarningFunction = (condition: unknown, message?: string, prefix?: string) => asserts condition is boolean;
2
+ export declare const warning: TWarningFunction;
3
+ export declare const useWarning: (condition: boolean, message: string) => void;
4
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/utils",
3
3
  "description": "A collection of utilities shared across the other packages.",
4
- "version": "15.11.2",
4
+ "version": "15.13.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -19,10 +19,14 @@
19
19
  "module": "dist/commercetools-uikit-utils.esm.js",
20
20
  "files": ["dist"],
21
21
  "dependencies": {
22
- "@babel/runtime": "^7.19.0",
23
- "@babel/runtime-corejs3": "^7.19.1",
24
- "@emotion/is-prop-valid": "1.2.0",
25
- "@types/warning": "^3.0.0",
26
- "warning": "4.0.3"
22
+ "@babel/runtime": "^7.20.13",
23
+ "@babel/runtime-corejs3": "^7.20.13",
24
+ "@emotion/is-prop-valid": "1.2.0"
25
+ },
26
+ "devDependencies": {
27
+ "react": "17.0.2"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "17.x"
27
31
  }
28
32
  }