@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
@@ -1,10 +1,59 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("react");
4
-
5
4
  var _util = require("../util");
6
-
7
5
  describe('util', function () {
6
+ describe('cap', function () {
7
+ test('should return a capitalized string', function () {
8
+ expect((0, _util.cap)('abc')).toBe('Abc');
9
+ });
10
+ });
11
+ describe('clamp', function () {
12
+ test('should return a value between a min value and a max value', function () {
13
+ expect((0, _util.clamp)(10, 20, 15)).toBe(15);
14
+ expect((0, _util.clamp)(10, 20, 0)).toBe(10);
15
+ expect((0, _util.clamp)(10, 20, 30)).toBe(20);
16
+ expect((0, _util.clamp)(10, 20, 10)).toBe(10);
17
+ expect((0, _util.clamp)(10, 20, 20)).toBe(20);
18
+ expect((0, _util.clamp)(20, 10, 10)).toBe(20); // special case
19
+ });
20
+ });
21
+
22
+ describe('coerceArray', function () {
23
+ test('should return an array', function () {
24
+ expect((0, _util.coerceArray)(['a'])).toEqual(['a']);
25
+ expect((0, _util.coerceArray)('a')).toEqual(['a']);
26
+ });
27
+ });
28
+ describe('coerceFunction', function () {
29
+ test('should return a function', function () {
30
+ var _coerceFunction;
31
+ expect(typeof (0, _util.coerceFunction)(function () {
32
+ return 'function';
33
+ })).toEqual('function');
34
+ expect(typeof (0, _util.coerceFunction)('value')).toEqual('function');
35
+ expect((_coerceFunction = (0, _util.coerceFunction)('value')) === null || _coerceFunction === void 0 ? void 0 : _coerceFunction()).toEqual('value');
36
+ });
37
+ });
38
+ describe('extractAriaProps', function () {
39
+ test('should extract aria-related props as a return object', function () {
40
+ var testProps = {
41
+ role: 'button',
42
+ 'aria-hidden': true,
43
+ value: 'value'
44
+ };
45
+ var expected = {
46
+ role: 'button',
47
+ 'aria-hidden': true
48
+ };
49
+ var remaining = {
50
+ value: 'value'
51
+ };
52
+ var actual = (0, _util.extractAriaProps)(testProps);
53
+ expect(actual).toMatchObject(expected);
54
+ expect(testProps).toMatchObject(remaining);
55
+ });
56
+ });
8
57
  describe('isRenderable', function () {
9
58
  test('should return {true} for function', function () {
10
59
  var expected = true;
@@ -35,11 +84,10 @@ describe('util', function () {
35
84
  describe('memoize', function () {
36
85
  test('should memoize function', function () {
37
86
  var obj = {},
38
- testMethod = function testMethod(key) {
39
- obj[key] = (obj[key] || 0) + 1;
40
- },
41
- memoizedTest = (0, _util.memoize)(testMethod);
42
-
87
+ testMethod = function testMethod(key) {
88
+ obj[key] = (obj[key] || 0) + 1;
89
+ },
90
+ memoizedTest = (0, _util.memoize)(testMethod);
43
91
  expect(obj).not.toHaveProperty('a');
44
92
  memoizedTest('a');
45
93
  expect(obj).toHaveProperty('a', 1);
@@ -56,6 +104,52 @@ describe('util', function () {
56
104
  expect(expected).toEqual(actual);
57
105
  });
58
106
  });
107
+ describe('mergeClassNameMaps', function () {
108
+ var baseMap = {
109
+ 'class-base-only': 'real-class-base-only',
110
+ 'class-shared': 'real-class-shared-base',
111
+ 'class-shared-another': 'real-class-shared-another-base'
112
+ };
113
+ var additiveMap = {
114
+ 'class-shared': 'real-class-shared-additive',
115
+ 'class-shared-another': 'real-class-shared-another-additive',
116
+ 'class-additive-only': 'real-class-additive-only'
117
+ };
118
+
119
+ // Helper function to get an object from the proxy object that has only getters for properties to make testing easier
120
+ var getResultFromProxy = function getResultFromProxy(proxy) {
121
+ var keys = ['class-base-only', 'class-shared', 'class-shared-another', 'class-additive-only'];
122
+ var obj = {};
123
+ for (var i = 0; i < keys.length; i++) {
124
+ if (keys[i] !== proxy[keys[i]]) {
125
+ obj[keys[i]] = proxy[keys[i]];
126
+ }
127
+ }
128
+ return obj;
129
+ };
130
+ test('should return a base map if an additive map is not given', function () {
131
+ var actual = (0, _util.mergeClassNameMaps)(baseMap);
132
+ expect(actual).toEqual(baseMap);
133
+ });
134
+ test('should return a merged map containing shared class names', function () {
135
+ var expected = {
136
+ 'class-base-only': 'real-class-base-only',
137
+ 'class-shared': 'real-class-shared-base real-class-shared-additive',
138
+ 'class-shared-another': 'real-class-shared-another-base real-class-shared-another-additive'
139
+ };
140
+ var actual = getResultFromProxy((0, _util.mergeClassNameMaps)(baseMap, additiveMap));
141
+ expect(actual).toEqual(expected);
142
+ });
143
+ test('should return a merged map containing allowed matching class names', function () {
144
+ var expected = {
145
+ 'class-base-only': 'real-class-base-only',
146
+ 'class-shared': 'real-class-shared-base real-class-shared-additive',
147
+ 'class-shared-another': 'real-class-shared-another-base'
148
+ };
149
+ var actual = getResultFromProxy((0, _util.mergeClassNameMaps)(baseMap, additiveMap, ['class-shared']));
150
+ expect(actual).toEqual(expected);
151
+ });
152
+ });
59
153
  describe('mapAndFilterChildren', function () {
60
154
  test('Returns null if null passed', function () {
61
155
  var expected = null;
@@ -82,8 +176,8 @@ describe('util', function () {
82
176
  expect(actual).toEqual(expected);
83
177
  });
84
178
  test('Does not call filter with nullish or false entries', function () {
85
- var spy = jest.fn(); // eslint-disable-next-line no-undefined
86
-
179
+ var spy = jest.fn();
180
+ // eslint-disable-next-line no-undefined
87
181
  var children = [1, 2, null, 3, undefined, false];
88
182
  (0, _util.mapAndFilterChildren)(children, spy);
89
183
  var expected = 3;
@@ -111,11 +205,32 @@ describe('util', function () {
111
205
  test('should forward value and index to callback', function () {
112
206
  var spy = jest.fn();
113
207
  (0, _util.mapAndFilterChildren)([1], spy);
114
- var expected = [1, // value
208
+ var expected = [1,
209
+ // value
115
210
  0 // index
116
211
  ];
212
+
117
213
  var actual = spy.mock.calls[0];
118
214
  expect(expected).toEqual(actual);
119
215
  });
120
216
  });
217
+ describe('shallowEqual', function () {
218
+ var child = {
219
+ name: 'child'
220
+ };
221
+ test('should return `true` if the values of all keys are strictly equal', function () {
222
+ expect((0, _util.shallowEqual)(child, child)).toBe(true);
223
+ expect((0, _util.shallowEqual)(child, null)).toBe(false);
224
+ var fakeChild = {
225
+ name: 'fake'
226
+ };
227
+ expect((0, _util.shallowEqual)(child, fakeChild)).toBe(false);
228
+ fakeChild.name = 'child';
229
+ expect((0, _util.shallowEqual)(child, fakeChild)).toBe(true);
230
+ child.toString = function () {
231
+ child.toString.apply(child, arguments);
232
+ };
233
+ expect((0, _util.shallowEqual)(child, fakeChild)).toBe(false);
234
+ });
235
+ });
121
236
  });
package/util/util.js CHANGED
@@ -10,25 +10,15 @@ Object.defineProperty(exports, "Job", {
10
10
  }
11
11
  });
12
12
  exports.shallowEqual = exports.perfNow = exports.mergeClassNameMaps = exports.memoize = exports.mapAndFilterChildren = exports.isRenderable = exports.extractAriaProps = exports.coerceFunction = exports.coerceArray = exports.clamp = exports.cap = void 0;
13
-
14
13
  var _always = _interopRequireDefault(require("ramda/src/always"));
15
-
16
14
  var _is = _interopRequireDefault(require("ramda/src/is"));
17
-
18
15
  var _unless = _interopRequireDefault(require("ramda/src/unless"));
19
-
20
16
  var _react = require("react");
21
-
22
17
  var ReactIs = _interopRequireWildcard(require("react-is"));
23
-
24
18
  var _Job = _interopRequireDefault(require("./Job"));
25
-
26
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
-
32
22
  /**
33
23
  * A collection of utility methods.
34
24
  *
@@ -60,6 +50,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
60
50
  var cap = function cap(str) {
61
51
  return str.slice(0, 1).toUpperCase() + str.slice(1);
62
52
  };
53
+
63
54
  /**
64
55
  * Limits `value` to be between `min` and `max`.
65
56
  *
@@ -74,15 +65,13 @@ var cap = function cap(str) {
74
65
  * @memberof core/util
75
66
  * @public
76
67
  */
77
-
78
-
79
68
  exports.cap = cap;
80
-
81
69
  var clamp = function clamp(min, max, value) {
82
70
  if (min > max || value < min) return min;
83
71
  if (value > max) return max;
84
72
  return value;
85
73
  };
74
+
86
75
  /**
87
76
  * If `arg` is a function, return it. Otherwise returns a function that returns `arg`.
88
77
  *
@@ -98,10 +87,9 @@ var clamp = function clamp(min, max, value) {
98
87
  * @memberof core/util
99
88
  * @public
100
89
  */
101
-
102
-
103
90
  exports.clamp = clamp;
104
91
  var coerceFunction = (0, _unless["default"])((0, _is["default"])(Function), _always["default"]);
92
+
105
93
  /**
106
94
  * If `arg` is array-like, return it. Otherwise returns a single element array containing `arg`.
107
95
  *
@@ -119,12 +107,11 @@ var coerceFunction = (0, _unless["default"])((0, _is["default"])(Function), _alw
119
107
  * @memberof core/util
120
108
  * @public
121
109
  */
122
-
123
110
  exports.coerceFunction = coerceFunction;
124
-
125
111
  var coerceArray = function coerceArray(array) {
126
112
  return Array.isArray(array) ? array : [array];
127
113
  };
114
+
128
115
  /**
129
116
  * Loosely determines if `tag` is a renderable component (either a string or a function).
130
117
  *
@@ -135,13 +122,11 @@ var coerceArray = function coerceArray(array) {
135
122
  * @memberof core/util
136
123
  * @public
137
124
  */
138
-
139
-
140
125
  exports.coerceArray = coerceArray;
141
-
142
126
  var isRenderable = function isRenderable(tag) {
143
127
  return ReactIs.isValidElementType(tag);
144
128
  };
129
+
145
130
  /**
146
131
  * Removes ARIA-related props from `props` and returns them in a new object.
147
132
  *
@@ -155,10 +140,7 @@ var isRenderable = function isRenderable(tag) {
155
140
  * @memberof core/util
156
141
  * @public
157
142
  */
158
-
159
-
160
143
  exports.isRenderable = isRenderable;
161
-
162
144
  var extractAriaProps = function extractAriaProps(props) {
163
145
  var aria = {};
164
146
  Object.keys(props).forEach(function (key) {
@@ -169,6 +151,7 @@ var extractAriaProps = function extractAriaProps(props) {
169
151
  });
170
152
  return aria;
171
153
  };
154
+
172
155
  /**
173
156
  * Gets the current timestamp of either `window.performance.now` or `Date.now`
174
157
  *
@@ -178,10 +161,8 @@ var extractAriaProps = function extractAriaProps(props) {
178
161
  * @memberof core/util
179
162
  * @public
180
163
  */
181
-
182
-
164
+ /* istanbul ignore next */
183
165
  exports.extractAriaProps = extractAriaProps;
184
-
185
166
  var perfNow = function perfNow() {
186
167
  if (typeof window === 'object') {
187
168
  return window.performance.now();
@@ -189,6 +170,7 @@ var perfNow = function perfNow() {
189
170
  return Date.now();
190
171
  }
191
172
  };
173
+
192
174
  /**
193
175
  * Merges two class name maps into one.
194
176
  *
@@ -218,23 +200,18 @@ var perfNow = function perfNow() {
218
200
  * @memberof core/util
219
201
  * @public
220
202
  */
221
-
222
-
223
203
  exports.perfNow = perfNow;
224
-
225
204
  var mergeClassNameMaps = function mergeClassNameMaps(baseMap, additiveMap, allowedClassNames) {
226
205
  var css = baseMap;
227
-
228
206
  if (baseMap && additiveMap) {
229
- allowedClassNames = allowedClassNames || Object.keys(additiveMap); // if the props includes a css map, merge them together now
230
-
207
+ allowedClassNames = allowedClassNames || Object.keys(additiveMap);
208
+ // if the props includes a css map, merge them together now
231
209
  css = Object.assign({}, baseMap);
232
210
  allowedClassNames.forEach(function (key) {
233
211
  if (baseMap[key] && additiveMap[key]) {
234
212
  css[key] = baseMap[key] + ' ' + additiveMap[key];
235
213
  }
236
214
  });
237
-
238
215
  if (process.env.NODE_ENV === 'test') {
239
216
  return new Proxy({}, {
240
217
  get: function get(target, key) {
@@ -244,9 +221,9 @@ var mergeClassNameMaps = function mergeClassNameMaps(baseMap, additiveMap, allow
244
221
  });
245
222
  }
246
223
  }
247
-
248
224
  return css;
249
225
  };
226
+
250
227
  /**
251
228
  * Creates a function that memoizes the result of `fn`.
252
229
  *
@@ -260,15 +237,11 @@ var mergeClassNameMaps = function mergeClassNameMaps(baseMap, additiveMap, allow
260
237
  * @memberof core/util
261
238
  * @public
262
239
  */
263
-
264
-
265
240
  exports.mergeClassNameMaps = mergeClassNameMaps;
266
-
267
241
  var memoize = function memoize(fn) {
268
242
  var cache = {};
269
243
  return function () {
270
244
  var n = arguments.length <= 0 ? undefined : arguments[0];
271
-
272
245
  if (n in cache) {
273
246
  return cache[n];
274
247
  } else {
@@ -278,6 +251,7 @@ var memoize = function memoize(fn) {
278
251
  }
279
252
  };
280
253
  };
254
+
281
255
  /**
282
256
  * Maps over the `children`, discarding any `null` children before and after calling the callback.
283
257
  *
@@ -296,29 +270,25 @@ var memoize = function memoize(fn) {
296
270
  * @see https://reactjs.org/docs/react-api.html#reactchildrenmap
297
271
  * @public
298
272
  */
299
-
300
-
301
273
  exports.memoize = memoize;
302
-
303
274
  var mapAndFilterChildren = function mapAndFilterChildren(children, callback, filter) {
304
275
  var result = _react.Children.map(children, function (child) {
305
276
  if (child != null) {
306
277
  for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
307
278
  rest[_key - 1] = arguments[_key];
308
279
  }
309
-
310
280
  return callback.apply(void 0, [child].concat(rest));
311
281
  } else {
312
282
  return child;
313
283
  }
314
284
  });
315
-
316
285
  if (result && filter) {
317
286
  return result.filter(filter);
318
287
  } else {
319
288
  return result;
320
289
  }
321
290
  };
291
+
322
292
  /**
323
293
  * Performs shallow comparison for given objects.
324
294
  *
@@ -330,37 +300,28 @@ var mapAndFilterChildren = function mapAndFilterChildren(children, callback, fil
330
300
  * @memberof core/util
331
301
  * @public
332
302
  */
333
-
334
-
335
303
  exports.mapAndFilterChildren = mapAndFilterChildren;
336
-
337
304
  var shallowEqual = function shallowEqual(a, b) {
338
305
  if (Object.is(a, b)) {
339
306
  return true;
340
307
  }
341
-
342
308
  if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
343
309
  return false;
344
310
  }
345
-
346
311
  var aKeys = Object.keys(a);
347
- var bKeys = Object.keys(b); // early bail out if the objects have a different number of keys
312
+ var bKeys = Object.keys(b);
348
313
 
314
+ // early bail out if the objects have a different number of keys
349
315
  if (aKeys.length !== bKeys.length) {
350
316
  return false;
351
317
  }
352
-
353
318
  var hasOwn = Object.prototype.hasOwnProperty.bind(b);
354
-
355
319
  for (var i = 0; i < aKeys.length; i++) {
356
320
  var prop = aKeys[i];
357
-
358
321
  if (!hasOwn(prop) || !Object.is(a[prop], b[prop])) {
359
322
  return false;
360
323
  }
361
324
  }
362
-
363
325
  return true;
364
326
  };
365
-
366
327
  exports.shallowEqual = shallowEqual;
@@ -1,21 +0,0 @@
1
- // Type definitions for core/dispatcher
2
-
3
- type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4
- type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
5
-
6
- /**
7
- * Adds a new global event listener. Duplicate event handlers will be discarded.
8
- */
9
- export function on(name: string, fn: Function, target: React.ReactNode): void;
10
- /**
11
- * Removes a global event listener.
12
- */
13
- export function off(name: string, fn: Function, target: React.ReactNode): void;
14
- /**
15
- * Adds a new global event listener that removes itself after handling one event.
16
- */
17
- export function once(
18
- name: string,
19
- fn: Function,
20
- target?: React.ReactNode
21
- ): Function;