@enact/core 4.5.2 → 4.6.1

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 (61) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dispatcher/dispatcher.js +15 -27
  3. package/dispatcher/listeners.js +0 -8
  4. package/dispatcher/tests/dispatcher-specs.js +0 -3
  5. package/handle/handle.js +40 -98
  6. package/handle/tests/handle-specs.js +21 -42
  7. package/hoc/hoc.js +2 -13
  8. package/hoc/tests/hoc-specs.js +0 -23
  9. package/internal/ApiDecorator/ApiDecorator.js +4 -34
  10. package/internal/ApiDecorator/tests/ApiDecorator-specs.js +69 -40
  11. package/internal/Registry/Registry.js +0 -7
  12. package/internal/Registry/tests/Registry-specs.js +26 -78
  13. package/internal/deprecate/deprecate.js +9 -22
  14. package/internal/deprecate/tests/deprecate-specs.js +38 -0
  15. package/internal/prop-types/prop-types.js +3 -20
  16. package/internal/prop-types/tests/prop-types-specs.js +265 -0
  17. package/keymap/index.js +2 -3
  18. package/keymap/keymap.js +10 -18
  19. package/keymap/tests/keymap-specs.js +0 -3
  20. package/kind/computed.js +2 -9
  21. package/kind/kind.js +14 -53
  22. package/kind/styles.js +6 -19
  23. package/kind/tests/computed-specs.js +4 -6
  24. package/kind/tests/kind-specs.js +9 -44
  25. package/kind/tests/styles-specs.js +12 -7
  26. package/kind/util.js +0 -2
  27. package/package.json +8 -2
  28. package/platform/platform.js +51 -57
  29. package/platform/tests/platform-specs.js +31 -3
  30. package/snapshot/snapshot.js +4 -9
  31. package/snapshot/tests/snapshot-specs.js +56 -0
  32. package/useChainRefs/tests/useChainRefs-specs.js +0 -14
  33. package/useChainRefs/useChainRefs.js +3 -11
  34. package/useClass/tests/useClass-specs.js +6 -21
  35. package/useClass/useClass.js +0 -8
  36. package/useHandlers/Handlers.js +0 -11
  37. package/useHandlers/tests/useHandlers-specs.js +11 -23
  38. package/useHandlers/useHandlers.js +0 -5
  39. package/usePublicClassNames/tests/usePublicClassNames-specs.js +21 -28
  40. package/usePublicClassNames/usePublicClassNames.js +4 -10
  41. package/util/Job.js +1 -43
  42. package/util/tests/Job-specs.js +48 -14
  43. package/util/tests/util-specs.js +125 -10
  44. package/util/util.js +15 -54
  45. package/dispatcher/dispatcher.d.ts +0 -21
  46. package/handle/handle.d.ts +0 -618
  47. package/hoc/hoc.d.ts +0 -44
  48. package/index.d.ts +0 -0
  49. package/internal/ApiDecorator/ApiDecorator.d.ts +0 -0
  50. package/internal/Registry/Registry.d.ts +0 -0
  51. package/internal/deprecate/deprecate.d.ts +0 -0
  52. package/internal/prop-types/prop-types.d.ts +0 -0
  53. package/keymap/index.d.ts +0 -37
  54. package/kind/kind.d.ts +0 -90
  55. package/platform/platform.d.ts +0 -45
  56. package/snapshot/snapshot.d.ts +0 -32
  57. package/useChainRefs/useChainRefs.d.ts +0 -0
  58. package/useClass/useClass.d.ts +0 -0
  59. package/useHandlers/useHandlers.d.ts +0 -0
  60. package/usePublicClassNames/usePublicClassNames.d.ts +0 -0
  61. package/util/util.d.ts +0 -162
@@ -4,66 +4,58 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.platform = exports.parseUserAgent = exports.detect = exports["default"] = void 0;
7
-
8
7
  var _uniq = _interopRequireDefault(require("ramda/src/uniq"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
-
14
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
-
16
11
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
-
18
12
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
-
20
13
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
21
-
22
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
-
24
15
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
-
26
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
-
28
17
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
-
30
18
  var hasGesture = function hasGesture() {
31
19
  return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1));
32
20
  };
33
-
34
21
  var hasTouch = function hasTouch() {
35
22
  return Boolean('TouchEvent' in window || 'ontouchstart' in window || window.navigator.msMaxTouchPoints || window.navigator.msManipulationViewsEnabled && window.navigator.maxTouchPoints);
36
- }; // Adapted from https://patrickhlauke.github.io/touch/touchscreen-detection/
23
+ };
24
+
25
+ // Adapted from https://patrickhlauke.github.io/touch/touchscreen-detection/
37
26
  // I've omitted the touch event fallback since that is covered by hasTouch and we're less concerned
38
27
  // with legacy browsers used in touchscreen environments.
39
-
40
-
41
28
  var hasTouchScreen = function hasTouchScreen() {
42
- return (// if Pointer Events are supported, just check maxTouchPoints
43
- window.PointerEvent && 'maxTouchPoints' in window.navigator && window.navigator.maxTouchPoints > 0 || // check for any-pointer:coarse which mostly means touchscreen
29
+ return (
30
+ // if Pointer Events are supported, just check maxTouchPoints
31
+ window.PointerEvent && 'maxTouchPoints' in window.navigator && window.navigator.maxTouchPoints > 0 ||
32
+ // check for any-pointer:coarse which mostly means touchscreen
44
33
  window.matchMedia && window.matchMedia('(any-pointer:coarse)').matches
45
34
  );
46
35
  };
47
-
48
36
  var webOSVersion = {
49
37
  38: 3,
50
38
  53: 4,
51
39
  68: 5,
52
40
  79: 6
53
41
  };
54
- var platforms = [// Windows Phone 7 - 10
42
+ var platforms = [
43
+ // Windows Phone 7 - 10
55
44
  {
56
45
  platform: 'windowsPhone',
57
46
  regex: /Windows Phone (?:OS )?(\d+)[.\d]+/
58
- }, // Android 4+ using Chrome
47
+ },
48
+ // Android 4+ using Chrome
59
49
  {
60
50
  platform: 'androidChrome',
61
51
  regex: /Android .* Chrome\/(\d+)[.\d]+/
62
- }, // Android 2 - 4
52
+ },
53
+ // Android 2 - 4
63
54
  {
64
55
  platform: 'android',
65
56
  regex: /Android(?:\s|\/)(\d+)/
66
- }, // Kindle Fire
57
+ },
58
+ // Kindle Fire
67
59
  // Force version to 2, (desktop mode does not list android version)
68
60
  {
69
61
  platform: 'android',
@@ -72,7 +64,8 @@ var platforms = [// Windows Phone 7 - 10
72
64
  extra: {
73
65
  silk: 1
74
66
  }
75
- }, // Kindle Fire HD (Silk versions 2 or 3)
67
+ },
68
+ // Kindle Fire HD (Silk versions 2 or 3)
76
69
  // Force version to 4
77
70
  {
78
71
  platform: 'android',
@@ -88,24 +81,29 @@ var platforms = [// Windows Phone 7 - 10
88
81
  extra: {
89
82
  silk: 3
90
83
  }
91
- }, // IE 8 - 10
84
+ },
85
+ // IE 8 - 10
92
86
  {
93
87
  platform: 'ie',
94
88
  regex: /MSIE (\d+)/
95
- }, // IE 11
89
+ },
90
+ // IE 11
96
91
  {
97
92
  platform: 'ie',
98
93
  regex: /Trident\/.*; rv:(\d+)/
99
- }, // Edge
94
+ },
95
+ // Edge
100
96
  {
101
97
  platform: 'edge',
102
98
  regex: /Edge\/(\d+)/
103
- }, // iOS 3 - 5
99
+ },
100
+ // iOS 3 - 5
104
101
  // Apple likes to make this complicated
105
102
  {
106
103
  platform: 'ios',
107
104
  regex: /iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/
108
- }, // LG webOS
105
+ },
106
+ // LG webOS
109
107
  {
110
108
  platform: 'webos',
111
109
  regex: /Web0S;.*Safari\/537.41/,
@@ -117,12 +115,14 @@ var platforms = [// Windows Phone 7 - 10
117
115
  }, {
118
116
  platform: 'webos',
119
117
  regex: /Web0S;.*Chrome\/(\d+)/
120
- }, // LG webOS of indeterminate versionre
118
+ },
119
+ // LG webOS of indeterminate versionre
121
120
  {
122
121
  platform: 'webos',
123
122
  regex: /Web0S;/,
124
123
  forceVersion: -1
125
- }, // LuneOS
124
+ },
125
+ // LuneOS
126
126
  {
127
127
  platform: 'webos',
128
128
  regex: /LuneOS/,
@@ -130,7 +130,8 @@ var platforms = [// Windows Phone 7 - 10
130
130
  extra: {
131
131
  luneos: 1
132
132
  }
133
- }, // Palm/HP/Open webOS
133
+ },
134
+ // Palm/HP/Open webOS
134
135
  {
135
136
  platform: 'webos',
136
137
  regex: /WebAppManager|Isis|webOS\./,
@@ -159,47 +160,52 @@ var platforms = [// Windows Phone 7 - 10
159
160
  extra: {
160
161
  legacy: 3
161
162
  }
162
- }, // desktop Safari
163
+ },
164
+ // desktop Safari
163
165
  {
164
166
  platform: 'safari',
165
167
  regex: /Version\/(\d+)[.\d]+\s+Safari/
166
- }, // desktop Chrome
168
+ },
169
+ // desktop Chrome
167
170
  {
168
171
  platform: 'chrome',
169
172
  regex: /Chrome\/(\d+)[.\d]+/
170
- }, // Firefox on Android
173
+ },
174
+ // Firefox on Android
171
175
  {
172
176
  platform: 'androidFirefox',
173
177
  regex: /Android;.*Firefox\/(\d+)/
174
- }, // FirefoxOS
178
+ },
179
+ // FirefoxOS
175
180
  {
176
181
  platform: 'firefoxOS',
177
182
  regex: /Mobile;.*Firefox\/(\d+)/
178
- }, // desktop Firefox
183
+ },
184
+ // desktop Firefox
179
185
  {
180
186
  platform: 'firefox',
181
187
  regex: /Firefox\/(\d+)/
182
- }, // Blackberry Playbook
188
+ },
189
+ // Blackberry Playbook
183
190
  {
184
191
  platform: 'blackberry',
185
192
  regex: /PlayBook/i,
186
193
  forceVersion: 2
187
- }, // Blackberry 10+
194
+ },
195
+ // Blackberry 10+
188
196
  {
189
197
  platform: 'blackberry',
190
198
  regex: /BB1\d;.*Version\/(\d+\.\d+)/
191
- }, // Tizen
199
+ },
200
+ // Tizen
192
201
  {
193
202
  platform: 'tizen',
194
203
  regex: /Tizen (\d+)/
195
204
  }];
196
-
197
205
  var ua = function ua() {
198
206
  return window.navigator ? window.navigator.userAgent : '';
199
207
  };
200
-
201
208
  var _platform;
202
-
203
209
  var parseUserAgent = function parseUserAgent(userAgent) {
204
210
  var plat = {
205
211
  gesture: hasGesture(),
@@ -208,38 +214,31 @@ var parseUserAgent = function parseUserAgent(userAgent) {
208
214
  touchscreen: hasTouchScreen(),
209
215
  unknown: true
210
216
  };
211
-
212
217
  for (var i = 0, p, m, v; p = platforms[i]; i++) {
213
218
  m = p.regex.exec(userAgent);
214
-
215
219
  if (m) {
216
220
  plat.unknown = false;
217
-
218
221
  if ('forceVersion' in p) {
219
222
  v = p.forceVersion;
220
223
  } else if (p.platform === 'webos') {
221
224
  v = webOSVersion[m[1]] || -1;
222
-
223
225
  if (v >= 7 || v === -1) {
224
226
  plat.chrome = Number(m[1]);
225
227
  }
226
228
  } else {
227
229
  v = Number(m[1]);
228
230
  }
229
-
230
231
  plat[p.platform] = v;
231
-
232
232
  if (p.extra) {
233
233
  plat = _objectSpread(_objectSpread({}, plat), p.extra);
234
234
  }
235
-
236
235
  plat.platformName = p.platform;
237
236
  break;
238
237
  }
239
238
  }
240
-
241
239
  return plat;
242
240
  };
241
+
243
242
  /**
244
243
  * @typedef {Object} PlatformDescription
245
244
  * @property {Object} [extra] - Additional information about the detected platform
@@ -262,10 +261,7 @@ var parseUserAgent = function parseUserAgent(userAgent) {
262
261
  * @memberof core/platform
263
262
  * @public
264
263
  */
265
-
266
-
267
264
  exports.parseUserAgent = parseUserAgent;
268
-
269
265
  var detect = function detect() {
270
266
  if (_platform) {
271
267
  // if we've already determined the platform, we'll use that determination
@@ -278,10 +274,10 @@ var detect = function detect() {
278
274
  unknown: true
279
275
  };
280
276
  }
281
-
282
277
  var userAgent = ua();
283
278
  return _platform = parseUserAgent(userAgent);
284
279
  };
280
+
285
281
  /**
286
282
  * Provides basic information about the running platform.
287
283
  *
@@ -289,8 +285,6 @@ var detect = function detect() {
289
285
  * @memberof core/platform
290
286
  * @public
291
287
  */
292
-
293
-
294
288
  exports.detect = detect;
295
289
  var platform = {};
296
290
  exports.platform = platform;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _platform = require("../platform");
4
-
5
4
  describe('platform', function () {
6
- describe('webOS', function () {
5
+ describe('parseUserAgent for webOS', function () {
7
6
  // From http://webostv.developer.lge.com/discover/specifications/web-engine/
8
7
  var webOSTVNext = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 WebAppManager';
9
8
  var webOSTV6 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3440.106 Safari/537.36 WebAppManager';
@@ -11,8 +10,9 @@ describe('platform', function () {
11
10
  var webOSTV4 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.1785.34 Safari/537.36 WebAppManager';
12
11
  var webOSTV3 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.1.1 Chrome/38.0.2125.122 Safari/537.36 WebAppManager';
13
12
  var webOSTV2 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen WebAppManager Safari/538.2';
14
- var webOSTV1 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.41 (KHTML, like Gecko) Large Screen WebAppManager Safari/537.41'; // From https://developers.whatismybrowser.com/useragents/explore/operating_system_name/webos/
13
+ var webOSTV1 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.41 (KHTML, like Gecko) Large Screen WebAppManager Safari/537.41';
15
14
 
15
+ // From https://developers.whatismybrowser.com/useragents/explore/operating_system_name/webos/
16
16
  var LuneOS2 = 'Mozilla/5.0 (LuneOS, like webOS/3.0.5; Tablet) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.9.2 Chrome/56.0.2924.103 Safari/537.36';
17
17
  var LuneOS1 = 'Mozilla/5.0 (LuneOS, like webOS/3.0.5; Tablet) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.6.2 Chrome/45.0.2454.103 Safari/537.36';
18
18
  var webOS10 = 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Geko) Version/1.0 Safari/525.27.1 Pre/1.0';
@@ -106,4 +106,32 @@ describe('platform', function () {
106
106
  expect((0, _platform.parseUserAgent)(webOS2)).toMatchObject(expected);
107
107
  });
108
108
  });
109
+ describe('parseUserAgent for User-Agent Reduction', function () {
110
+ var testVersion = '113';
111
+ var uaGenerator = function uaGenerator(unifiedPlatform) {
112
+ var deviceCompatibility = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
113
+ var majorVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : testVersion;
114
+ return "Mozilla/5.0 (".concat(unifiedPlatform, ") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/").concat(majorVersion, ".0.0.0 ").concat(deviceCompatibility, " Safari/537.36");
115
+ };
116
+ var testCases = [[uaGenerator('Macintosh; Intel Mac OS X 10_15_7'), 'chrome'], [uaGenerator('Windows NT 10.0; Win64; x64'), 'chrome'], [uaGenerator('X11; Linux x86_64'), 'chrome'], [uaGenerator('X11; CrOS x86_64 14541.0.0'), 'chrome'], [uaGenerator('Fuchsia'), 'chrome'], [uaGenerator('Linux; Android 10; K', 'Mobile'), 'androidChrome']];
117
+ test("should return object including chrome ".concat(testVersion), function () {
118
+ for (var i = 0; i < testCases.length; i++) {
119
+ var _parseUserAgent, _parseUserAgent$testC;
120
+ expect((_parseUserAgent = (0, _platform.parseUserAgent)(testCases[i][0])) === null || _parseUserAgent === void 0 ? void 0 : (_parseUserAgent$testC = _parseUserAgent[testCases[i][1]]) === null || _parseUserAgent$testC === void 0 ? void 0 : _parseUserAgent$testC.toString()).toBe(testVersion);
121
+ }
122
+ });
123
+ });
124
+ describe('platform', function () {
125
+ test('should return `true` for `node` if window does not exist', function () {
126
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(function () {});
127
+ expect(_platform.platform['node']).toBe(true);
128
+ windowSpy.mockRestore();
129
+ });
130
+ test('should return `true` for `unknown` in the testing environment', function () {
131
+ // The first access invokes detecting based on user agent value
132
+ expect(_platform.platform['unknown']).toBe(true);
133
+ // The second access makes the module to return already detected platform information
134
+ expect(_platform.platform['unknown']).toBe(true);
135
+ });
136
+ });
109
137
  });
@@ -7,11 +7,8 @@ exports["default"] = void 0;
7
7
  exports.isWindowReady = isWindowReady;
8
8
  exports.onWindowReady = onWindowReady;
9
9
  exports.windowReady = windowReady;
10
-
11
10
  var _invariant = _interopRequireDefault(require("invariant"));
12
-
13
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
-
15
12
  /**
16
13
  * Utilities to facilitate integration with v8 snapshot builds
17
14
  *
@@ -21,7 +18,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
21
18
  * @exports windowReady
22
19
  * @public
23
20
  */
21
+
24
22
  var windowCallbacks = [];
23
+
25
24
  /**
26
25
  * Determines if the `window` is available
27
26
  *
@@ -31,10 +30,10 @@ var windowCallbacks = [];
31
30
  * @memberof core/snapshot
32
31
  * @public
33
32
  */
34
-
35
33
  function isWindowReady() {
36
34
  return typeof window !== 'undefined';
37
35
  }
36
+
38
37
  /**
39
38
  * Executes a callback, such as registering event handlers, when a valid `window` is available.
40
39
  *
@@ -56,8 +55,6 @@ function isWindowReady() {
56
55
  * @memberof core/snapshot
57
56
  * @public
58
57
  */
59
-
60
-
61
58
  function onWindowReady(callback) {
62
59
  if (isWindowReady()) {
63
60
  callback();
@@ -65,6 +62,7 @@ function onWindowReady(callback) {
65
62
  windowCallbacks.push(callback);
66
63
  }
67
64
  }
65
+
68
66
  /**
69
67
  * Executes all queued window callbacks.
70
68
  *
@@ -76,14 +74,11 @@ function onWindowReady(callback) {
76
74
  * @memberof core/snapshot
77
75
  * @public
78
76
  */
79
-
80
-
81
77
  function windowReady() {
82
78
  !isWindowReady() ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'windowReady cannot be run until the window is available') : (0, _invariant["default"])(false) : void 0;
83
79
  windowCallbacks.forEach(function (f) {
84
80
  return f();
85
81
  });
86
82
  }
87
-
88
83
  var _default = onWindowReady;
89
84
  exports["default"] = _default;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _snapshot = require("../snapshot");
4
+ function returnsUndefined() {}
5
+ describe('snapshot', function () {
6
+ describe('isWindowReady', function () {
7
+ test('should return `true` if window is ready', function () {
8
+ var expected = true;
9
+ var actual = (0, _snapshot.isWindowReady)();
10
+ expect(actual).toBe(expected);
11
+ });
12
+ test('should return `false` if window is not ready', function () {
13
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(returnsUndefined);
14
+ var expected = false;
15
+ var actual = (0, _snapshot.isWindowReady)();
16
+ expect(actual).toBe(expected);
17
+ windowSpy.mockRestore();
18
+ });
19
+ });
20
+ describe('onWindowReady', function () {
21
+ test('should call a given callback function immediately if window is ready', function () {
22
+ var spy = jest.fn();
23
+ (0, _snapshot.onWindowReady)(spy);
24
+ expect(spy).toHaveBeenCalled();
25
+ });
26
+ test('should not call a given callback function if window is not ready', function () {
27
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(returnsUndefined);
28
+ var spy = jest.fn();
29
+ (0, _snapshot.onWindowReady)(spy);
30
+ expect(spy).not.toHaveBeenCalled();
31
+ windowSpy.mockRestore();
32
+ });
33
+ });
34
+ describe('windowReady', function () {
35
+ test('should call queued callbacks if window is ready', function () {
36
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(returnsUndefined);
37
+ var spy = jest.fn();
38
+ (0, _snapshot.onWindowReady)(spy);
39
+ (0, _snapshot.onWindowReady)(spy);
40
+ expect(spy).not.toHaveBeenCalled();
41
+ windowSpy.mockRestore();
42
+ (0, _snapshot.windowReady)();
43
+ expect(spy).toHaveBeenCalledTimes(2);
44
+ });
45
+ test('should throw an error if window is not ready', function () {
46
+ var consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
47
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(returnsUndefined);
48
+ var spy = jest.fn();
49
+ (0, _snapshot.onWindowReady)(spy);
50
+ expect(_snapshot.windowReady).toThrow('windowReady cannot be run until the window is available');
51
+ expect(spy).not.toHaveBeenCalled();
52
+ consoleErrorMock.mockRestore();
53
+ windowSpy.mockRestore();
54
+ });
55
+ });
56
+ });
@@ -1,38 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  require("@testing-library/jest-dom");
4
-
5
4
  var _react = require("@testing-library/react");
6
-
7
5
  var _react2 = require("react");
8
-
9
6
  var _useChainRefs = _interopRequireDefault(require("../useChainRefs"));
10
-
11
7
  var _jsxRuntime = require("react/jsx-runtime");
12
-
13
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
-
15
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
-
17
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
-
19
11
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
-
21
12
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
22
-
23
13
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
-
25
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
26
-
27
15
  describe('useChainRefs', function () {
28
16
  function Component(props) {
29
17
  var ref = _useChainRefs["default"].apply(void 0, _toConsumableArray(props.refs));
30
-
31
18
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
32
19
  ref: ref
33
20
  });
34
21
  }
35
-
36
22
  test('should call a single functional ref', function () {
37
23
  var ref = jest.fn();
38
24
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
@@ -6,13 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.chainRefs = chainRefs;
7
7
  exports["default"] = void 0;
8
8
  exports.useChainRefs = useChainRefs;
9
-
10
9
  var _react = require("react");
11
-
12
10
  var _warning = _interopRequireDefault(require("warning"));
13
-
14
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
12
  /**
17
13
  * Updates multiple reference callbacks or objects
18
14
  *
@@ -21,6 +17,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
21
17
  * @exports chainRefs
22
18
  * @private
23
19
  */
20
+
24
21
  // Safely handles functional and object refs (and ignores invalid refs)
25
22
  function updateRef(ref, node) {
26
23
  if (ref) {
@@ -34,6 +31,7 @@ function updateRef(ref, node) {
34
31
  }
35
32
  }
36
33
  }
34
+
37
35
  /**
38
36
  * Creates a reference callback that updates each of the provided references
39
37
  *
@@ -42,19 +40,17 @@ function updateRef(ref, node) {
42
40
  * @returns {Function} A callback that updates each reference
43
41
  * @public
44
42
  */
45
-
46
-
47
43
  function chainRefs() {
48
44
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
49
45
  refs[_key] = arguments[_key];
50
46
  }
51
-
52
47
  return function (node) {
53
48
  refs.forEach(function (ref) {
54
49
  return updateRef(ref, node);
55
50
  });
56
51
  };
57
52
  }
53
+
58
54
  /**
59
55
  * Creates a memoized reference callback that updates each of the provided references
60
56
  *
@@ -63,16 +59,12 @@ function chainRefs() {
63
59
  * @returns {Function} A memoized callback that updates each reference
64
60
  * @public
65
61
  */
66
-
67
-
68
62
  function useChainRefs() {
69
63
  for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
70
64
  refs[_key2] = arguments[_key2];
71
65
  }
72
-
73
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
74
67
  return (0, _react.useCallback)(chainRefs.apply(void 0, refs), refs);
75
68
  }
76
-
77
69
  var _default = useChainRefs;
78
70
  exports["default"] = _default;
@@ -1,28 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  require("@testing-library/jest-dom");
4
-
5
4
  var _react = require("@testing-library/react");
6
-
7
5
  var _useClass = _interopRequireDefault(require("../useClass"));
8
-
9
6
  var _jsxRuntime = require("react/jsx-runtime");
10
-
11
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
-
13
8
  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); } }
14
-
15
9
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
-
17
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
11
  describe('useClass', function () {
20
12
  var Class = /*#__PURE__*/_createClass(function Class(arg) {
21
13
  _classCallCheck(this, Class);
22
-
23
14
  this.arg = arg;
24
15
  });
25
-
26
16
  function Component(props) {
27
17
  var instance = (0, _useClass["default"])(Class, props.arg);
28
18
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -31,33 +21,28 @@ describe('useClass', function () {
31
21
  "data-fromprops": props.arg
32
22
  });
33
23
  }
34
-
35
24
  test('should pass arg to Class', function () {
36
25
  var arg = 'arg';
37
26
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
38
27
  arg: arg
39
28
  }));
40
-
41
29
  var div = _react.screen.getByTestId('div');
42
-
43
30
  expect(div).toHaveAttribute('data-fromclass', arg);
44
31
  });
45
32
  test('should use the same instance of Class across renders', function () {
46
33
  var arg = 'arg';
47
-
48
34
  var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
49
- arg: arg
50
- })),
51
- rerender = _render.rerender;
52
-
35
+ arg: arg
36
+ })),
37
+ rerender = _render.rerender;
53
38
  var div = _react.screen.getByTestId('div');
54
-
55
39
  expect(div).toHaveAttribute('data-fromprops', arg);
56
40
  rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
57
41
  arg: "changed"
58
- })); // verify that the children still reflects the class value set at construction but the prop
59
- // value was updated when props were updated
42
+ }));
60
43
 
44
+ // verify that the children still reflects the class value set at construction but the prop
45
+ // value was updated when props were updated
61
46
  expect(div).toHaveAttribute('data-fromclass', arg);
62
47
  expect(div).toHaveAttribute('data-fromprops', 'changed');
63
48
  });
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  exports.useClass = useClass;
8
-
9
8
  var _react = require("react");
10
-
11
9
  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
12
-
13
10
  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; } }
14
-
15
11
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
-
17
12
  /**
18
13
  * Creates one instance of the class, `Ctor` with the provided `args`, for the life of the
19
14
  * component.
@@ -44,14 +39,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
44
39
  */
45
40
  function useClass(Ctor) {
46
41
  var ref = (0, _react.useRef)(null);
47
-
48
42
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
49
43
  args[_key - 1] = arguments[_key];
50
44
  }
51
-
52
45
  ref.current = ref.current || _construct(Ctor, args);
53
46
  return ref.current;
54
47
  }
55
-
56
48
  var _default = useClass;
57
49
  exports["default"] = _default;