@enact/core 4.5.2 → 4.5.4

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 (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dispatcher/dispatcher.js +8 -27
  3. package/dispatcher/listeners.js +0 -8
  4. package/dispatcher/tests/dispatcher-specs.js +0 -3
  5. package/handle/handle.js +33 -90
  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 +0 -24
  11. package/internal/Registry/Registry.js +0 -7
  12. package/internal/Registry/tests/Registry-specs.js +10 -70
  13. package/internal/deprecate/deprecate.js +8 -22
  14. package/internal/prop-types/prop-types.js +3 -20
  15. package/keymap/index.js +2 -3
  16. package/keymap/keymap.js +10 -18
  17. package/keymap/tests/keymap-specs.js +0 -3
  18. package/kind/computed.js +2 -9
  19. package/kind/kind.js +14 -53
  20. package/kind/styles.js +6 -19
  21. package/kind/tests/computed-specs.js +4 -6
  22. package/kind/tests/kind-specs.js +9 -44
  23. package/kind/tests/styles-specs.js +12 -7
  24. package/kind/util.js +0 -2
  25. package/package.json +7 -1
  26. package/platform/platform.js +51 -57
  27. package/platform/tests/platform-specs.js +2 -2
  28. package/snapshot/snapshot.js +4 -9
  29. package/useChainRefs/tests/useChainRefs-specs.js +0 -14
  30. package/useChainRefs/useChainRefs.js +3 -11
  31. package/useClass/tests/useClass-specs.js +6 -21
  32. package/useClass/useClass.js +0 -8
  33. package/useHandlers/Handlers.js +0 -11
  34. package/useHandlers/tests/useHandlers-specs.js +11 -23
  35. package/useHandlers/useHandlers.js +0 -5
  36. package/usePublicClassNames/tests/usePublicClassNames-specs.js +21 -28
  37. package/usePublicClassNames/usePublicClassNames.js +4 -10
  38. package/util/Job.js +1 -43
  39. package/util/tests/Job-specs.js +0 -14
  40. package/util/tests/util-specs.js +9 -10
  41. package/util/util.js +14 -54
package/handle/handle.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.stopImmediate = exports.stop = exports.returnsTrue = exports.preventDefault = exports.oneOf = exports.not = exports.log = exports.handle = exports.forwardWithPrevent = exports.forwardCustomWithPrevent = exports.forwardCustom = exports.forward = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports["default"] = exports.callOnEvent = exports.call = exports.adaptEvent = void 0;
7
-
8
7
  var _cond = _interopRequireDefault(require("ramda/src/cond"));
9
-
10
8
  var _curry = _interopRequireDefault(require("ramda/src/curry"));
11
-
12
9
  var _keymap = require("../keymap");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
11
  /**
17
12
  * `core/handle` provides a set of utilities to support handling events for `kind()`s and
18
13
  * `React.Component`s. The default export, `handle()`, generates an event handler function from a
@@ -120,6 +115,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
120
115
  * @param {Object<string, any>} context
121
116
  * @returns {any}
122
117
  */
118
+
123
119
  // Accepts an array of handlers, sanitizes them, and returns a handler function
124
120
  // compose(allPass, map(makeSafeHandler));
125
121
  var makeHandler = function makeHandler(handlers) {
@@ -129,26 +125,21 @@ var makeHandler = function makeHandler(handlers) {
129
125
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
130
126
  args[_key] = arguments[_key];
131
127
  }
132
-
133
128
  for (var i = 0; i < handlers.length; i++) {
134
129
  var fn = handlers[i];
135
-
136
130
  if (typeof fn !== 'function' || fn.apply(this, args)) {
137
131
  continue;
138
132
  }
139
-
140
133
  return false;
141
134
  }
142
-
143
135
  return true;
144
136
  };
145
- }; // Loose check to determine if obj is component-ish if it has both props and context members
146
-
137
+ };
147
138
 
139
+ // Loose check to determine if obj is component-ish if it has both props and context members
148
140
  var hasPropsAndContext = function hasPropsAndContext(obj) {
149
141
  return obj && Object.prototype.hasOwnProperty.call(obj, 'props') && Object.prototype.hasOwnProperty.call(obj, 'context');
150
142
  };
151
-
152
143
  var named = function named(fn, name) {
153
144
  if (process.env.NODE_ENV !== "production") {
154
145
  try {
@@ -157,35 +148,30 @@ var named = function named(fn, name) {
157
148
  writeable: false,
158
149
  enumerable: false
159
150
  });
160
- } catch (err) {// unable to set name of function
151
+ } catch (err) {
152
+ // unable to set name of function
161
153
  }
162
154
  }
163
-
164
155
  return fn;
165
156
  };
166
-
167
157
  var bindAs = function bindAs(fn, obj, name) {
168
158
  var namedFunction = name ? named(fn, name) : fn;
169
159
  var bound = namedFunction.bind(obj);
170
-
171
160
  if (name) {
172
161
  obj[name] = bound;
173
162
  }
174
-
175
163
  return bound;
176
164
  };
177
-
178
165
  var decorateHandleFunction = function decorateHandleFunction(fn) {
179
166
  fn.named = function (name) {
180
167
  return named(fn, name);
181
168
  };
182
-
183
169
  fn.bindAs = function (obj, name) {
184
170
  return bindAs(fn, obj, name);
185
171
  };
186
-
187
172
  return fn;
188
173
  };
174
+
189
175
  /**
190
176
  * Allows generating event handlers by chaining input functions to filter or short-circuit the
191
177
  * handling flow. Any input function that returns a falsy value will stop the chain.
@@ -202,23 +188,21 @@ var decorateHandleFunction = function decorateHandleFunction(fn) {
202
188
  * @memberof core/handle
203
189
  * @public
204
190
  */
205
-
206
-
207
191
  var handle = function handle() {
208
192
  for (var _len2 = arguments.length, handlers = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
209
193
  handlers[_key2] = arguments[_key2];
210
194
  }
195
+ var h = makeHandler(handlers);
211
196
 
212
- var h = makeHandler(handlers); // In order to support binding either handle (handle.bind(this)) or a handler
197
+ // In order to support binding either handle (handle.bind(this)) or a handler
213
198
  // (a = handle(), a.bind(this)), we cache `this` here and use it as the fallback for props and
214
199
  // context if fn() doesn't have its own `this`.
215
-
216
200
  var _outer = this;
217
-
218
201
  var fn = function prepareHandleArgs(ev, props, context) {
219
- var caller = null; // if handle() was bound to a class, use its props and context. otherwise, we accept
220
- // incoming props/context as would be provided by computed/handlers from kind()
202
+ var caller = null;
221
203
 
204
+ // if handle() was bound to a class, use its props and context. otherwise, we accept
205
+ // incoming props/context as would be provided by computed/handlers from kind()
222
206
  if (hasPropsAndContext(this)) {
223
207
  caller = this;
224
208
  props = this.props;
@@ -228,31 +212,26 @@ var handle = function handle() {
228
212
  props = _outer.props;
229
213
  context = _outer.context;
230
214
  }
231
-
232
215
  return h.call(caller, ev, props, context);
233
216
  };
234
-
235
217
  fn["finally"] = function (cleanup) {
236
218
  return decorateHandleFunction(function handleWithFinally(ev, props, context) {
237
219
  var result = false;
238
-
239
220
  if (hasPropsAndContext(this)) {
240
221
  props = this.props;
241
222
  context = this.context;
242
223
  }
243
-
244
224
  try {
245
225
  result = fn.call(this, ev, props, context);
246
226
  } finally {
247
227
  cleanup.call(this, ev, props, context);
248
228
  }
249
-
250
229
  return result;
251
230
  });
252
231
  };
253
-
254
232
  return decorateHandleFunction(fn);
255
233
  };
234
+
256
235
  /**
257
236
  * Calls the first handler whose condition passes. Each branch must be passed as an array with the
258
237
  * first element being the condition function and the second being the handler function. The same
@@ -276,17 +255,14 @@ var handle = function handle() {
276
255
  * @memberof core/handle
277
256
  * @public
278
257
  */
279
-
280
-
281
258
  exports.handle = handle;
282
-
283
259
  var oneOf = handle.oneOf = function () {
284
260
  for (var _len3 = arguments.length, handlers = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
285
261
  handlers[_key3] = arguments[_key3];
286
262
  }
287
-
288
263
  return handle.call(this, (0, _cond["default"])(handlers));
289
264
  };
265
+
290
266
  /**
291
267
  * A function that always returns `true`. Optionally accepts a `handler` function which is called
292
268
  * before returning `true`.
@@ -313,24 +289,20 @@ var oneOf = handle.oneOf = function () {
313
289
  * @memberof core/handle
314
290
  * @public
315
291
  */
316
-
317
-
318
292
  exports.oneOf = oneOf;
319
-
320
293
  var returnsTrue = handle.returnsTrue = function (handler) {
321
294
  if (handler && typeof handler === 'function') {
322
295
  return named(function () {
323
296
  for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
324
297
  args[_key4] = arguments[_key4];
325
298
  }
326
-
327
299
  handler.apply(this, args);
328
300
  return true;
329
301
  }, 'returnsTrue');
330
302
  }
331
-
332
303
  return true;
333
304
  };
305
+
334
306
  /**
335
307
  * Calls a named function on the event and returns `true`.
336
308
  *
@@ -353,8 +325,6 @@ var returnsTrue = handle.returnsTrue = function (handler) {
353
325
  * @memberof core/handle
354
326
  * @private
355
327
  */
356
-
357
-
358
328
  exports.returnsTrue = returnsTrue;
359
329
  var callOnEvent = handle.callOnEvent = (0, _curry["default"])(function (methodName, ev) {
360
330
  if (ev[methodName]) {
@@ -364,9 +334,9 @@ var callOnEvent = handle.callOnEvent = (0, _curry["default"])(function (methodNa
364
334
  // on its proxy so we check the native event as well.
365
335
  ev.nativeEvent[methodName]();
366
336
  }
367
-
368
337
  return true;
369
338
  });
339
+
370
340
  /**
371
341
  * Allows handling to continue if the value of `prop` on the event strictly equals `value`
372
342
  *
@@ -390,11 +360,11 @@ var callOnEvent = handle.callOnEvent = (0, _curry["default"])(function (methodNa
390
360
  * @memberof core/handle
391
361
  * @public
392
362
  */
393
-
394
363
  exports.callOnEvent = callOnEvent;
395
364
  var forEventProp = handle.forEventProp = (0, _curry["default"])(function (prop, value, ev) {
396
365
  return ev[prop] === value;
397
366
  });
367
+
398
368
  /**
399
369
  * Forwards the event to a function at `name` on `props`. If the specified prop is `undefined` or
400
370
  * is not a function, it is ignored. The return value of the forwarded function is ignored and
@@ -420,17 +390,15 @@ var forEventProp = handle.forEventProp = (0, _curry["default"])(function (prop,
420
390
  * @memberof core/handle
421
391
  * @public
422
392
  */
423
-
424
393
  exports.forEventProp = forEventProp;
425
394
  var forward = handle.forward = (0, _curry["default"])(named(function (name, ev, props) {
426
395
  var fn = props && props[name];
427
-
428
396
  if (typeof fn === 'function') {
429
397
  fn(ev);
430
398
  }
431
-
432
399
  return true;
433
400
  }, 'forward'));
401
+
434
402
  /**
435
403
  * Calls `event.preventDefault()` and returns `true`.
436
404
  *
@@ -451,10 +419,9 @@ var forward = handle.forward = (0, _curry["default"])(named(function (name, ev,
451
419
  * @memberof core/handle
452
420
  * @public
453
421
  */
454
-
455
422
  exports.forward = forward;
456
-
457
423
  var _preventDefault = handle.preventDefault = callOnEvent('preventDefault');
424
+
458
425
  /**
459
426
  * Forwards the event to a function at `name` on `props` with capability to prevent default
460
427
  * behavior. If the specified prop is `undefined` or is not a function, it is ignored. Returns
@@ -480,21 +447,19 @@ var _preventDefault = handle.preventDefault = callOnEvent('preventDefault');
480
447
  * @memberof core/handle
481
448
  * @private
482
449
  */
483
-
484
-
485
450
  exports.preventDefault = _preventDefault;
486
451
  var forwardWithPrevent = handle.forwardWithPrevent = (0, _curry["default"])(named(function (name, ev, props) {
487
452
  var prevented = false;
488
453
  var wrappedEvent = Object.assign({}, ev, {
489
454
  preventDefault: function preventDefault() {
490
455
  prevented = true;
491
-
492
456
  _preventDefault(ev);
493
457
  }
494
458
  });
495
459
  forward(name, wrappedEvent, props);
496
460
  return !prevented;
497
461
  }, 'forwardWithPrevent'));
462
+
498
463
  /**
499
464
  * Calls `event.stopPropagation()` and returns `true`
500
465
  *
@@ -516,9 +481,9 @@ var forwardWithPrevent = handle.forwardWithPrevent = (0, _curry["default"])(name
516
481
  * @memberof core/handle
517
482
  * @public
518
483
  */
519
-
520
484
  exports.forwardWithPrevent = forwardWithPrevent;
521
485
  var stop = handle.stop = named(callOnEvent('stopPropagation'), 'stop');
486
+
522
487
  /**
523
488
  * Calls `event.stopImmediatePropagation()` and returns `true`
524
489
  *
@@ -540,9 +505,9 @@ var stop = handle.stop = named(callOnEvent('stopPropagation'), 'stop');
540
505
  * @memberof core/handle
541
506
  * @public
542
507
  */
543
-
544
508
  exports.stop = stop;
545
509
  var stopImmediate = handle.stopImmediate = callOnEvent('stopImmediatePropagation');
510
+
546
511
  /**
547
512
  * Allows event handling to continue if `event.keyCode === value`.
548
513
  *
@@ -565,9 +530,9 @@ var stopImmediate = handle.stopImmediate = callOnEvent('stopImmediatePropagation
565
530
  * @memberof core/handle
566
531
  * @public
567
532
  */
568
-
569
533
  exports.stopImmediate = stopImmediate;
570
534
  var forKeyCode = handle.forKeyCode = forEventProp('keyCode');
535
+
571
536
  /**
572
537
  * Allows handling to continue if the event's keyCode is mapped to `name` within
573
538
  * {@link core/keymap}.
@@ -592,11 +557,11 @@ var forKeyCode = handle.forKeyCode = forEventProp('keyCode');
592
557
  * @memberof core/handle
593
558
  * @public
594
559
  */
595
-
596
560
  exports.forKeyCode = forKeyCode;
597
561
  var forKey = handle.forKey = (0, _curry["default"])(function (name, ev) {
598
562
  return (0, _keymap.is)(name, ev.keyCode);
599
563
  });
564
+
600
565
  /**
601
566
  * Allows handling to continue if the value of `prop` on the props strictly equals `value`.
602
567
  *
@@ -621,11 +586,11 @@ var forKey = handle.forKey = (0, _curry["default"])(function (name, ev) {
621
586
  * @memberof core/handle
622
587
  * @public
623
588
  */
624
-
625
589
  exports.forKey = forKey;
626
590
  var forProp = handle.forProp = (0, _curry["default"])(function (prop, value, ev, props) {
627
591
  return props[prop] === value;
628
592
  });
593
+
629
594
  /**
630
595
  * Logs the event, props, and context optionally preceded by a custom message. Will only log in
631
596
  * development mode.
@@ -650,22 +615,19 @@ var forProp = handle.forProp = (0, _curry["default"])(function (prop, value, ev,
650
615
  * @memberof core/handle
651
616
  * @public
652
617
  */
653
-
654
618
  exports.forProp = forProp;
655
619
  var log = handle.log = (0, _curry["default"])(function (message, ev) {
656
620
  if (process.env.NODE_ENV !== "production") {
657
621
  var _console;
658
-
659
622
  for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
660
623
  args[_key5 - 2] = arguments[_key5];
661
624
  }
662
-
663
625
  // eslint-disable-next-line no-console
664
626
  (_console = console).log.apply(_console, [message, ev].concat(args));
665
627
  }
666
-
667
628
  return true;
668
629
  });
630
+
669
631
  /**
670
632
  * Invokes a method by name on the component to which {@link core/handle.handle} is bound.
671
633
  *
@@ -704,18 +666,16 @@ var log = handle.log = (0, _curry["default"])(function (message, ev) {
704
666
  * @memberof core/handle
705
667
  * @public
706
668
  */
707
-
708
669
  exports.log = log;
709
-
710
670
  var call = function call(method) {
711
671
  return named(function () {
712
672
  if (this && this[method]) {
713
673
  return this[method].apply(this, arguments);
714
674
  }
715
-
716
675
  return false;
717
676
  }, 'call');
718
677
  };
678
+
719
679
  /**
720
680
  * Adapts an event with `adapter` before calling `handler`.
721
681
  *
@@ -746,18 +706,16 @@ var call = function call(method) {
746
706
  * @memberof core/handle
747
707
  * @public
748
708
  */
749
-
750
-
751
709
  exports.call = call;
752
710
  var adaptEvent = handle.adaptEvent = (0, _curry["default"])(function (adapter, handler) {
753
711
  return named(function (ev) {
754
712
  for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
755
713
  args[_key6 - 1] = arguments[_key6];
756
714
  }
757
-
758
715
  return handler.call.apply(handler, [this, adapter.call.apply(adapter, [this, ev].concat(args))].concat(args));
759
716
  }, 'adaptEvent');
760
717
  });
718
+
761
719
  /**
762
720
  * Creates a handler that will forward the event to a function at `name` on `props`.
763
721
  *
@@ -791,34 +749,29 @@ var adaptEvent = handle.adaptEvent = (0, _curry["default"])(function (adapter, h
791
749
  * @memberof core/handle
792
750
  * @public
793
751
  */
794
-
795
752
  exports.adaptEvent = adaptEvent;
796
-
797
753
  var forwardCustom = handle.forwardCustom = function (name, adapter) {
798
754
  return handle(adaptEvent(function (ev) {
799
755
  for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
800
756
  args[_key7 - 1] = arguments[_key7];
801
757
  }
758
+ var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
802
759
 
803
- var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null; // Handle either no adapter or a non-object return from the adapter
804
-
760
+ // Handle either no adapter or a non-object return from the adapter
805
761
  if (!customEventPayload || typeof customEventPayload !== 'object') {
806
762
  customEventPayload = {};
807
763
  }
808
-
809
764
  customEventPayload.type = name;
810
-
811
765
  if (typeof customEventPayload.preventDefault !== 'function' && typeof (ev === null || ev === void 0 ? void 0 : ev.preventDefault) === 'function') {
812
766
  customEventPayload.preventDefault = ev.preventDefault.bind(ev);
813
767
  }
814
-
815
768
  if (typeof customEventPayload.stopPropagation !== 'function' && typeof (ev === null || ev === void 0 ? void 0 : ev.stopPropagation) === 'function') {
816
769
  customEventPayload.stopPropagation = ev.stopPropagation.bind(ev);
817
770
  }
818
-
819
771
  return customEventPayload;
820
772
  }, forward(name))).named('forwardCustom');
821
773
  };
774
+
822
775
  /**
823
776
  * Creates a handler that will forward the event to a function at `name` on `props` with capability
824
777
  * to prevent default behavior. If the specified prop is `undefined` or is not a function, it is
@@ -860,45 +813,38 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
860
813
  * @memberof core/handle
861
814
  * @private
862
815
  */
863
-
864
-
865
816
  exports.forwardCustom = forwardCustom;
866
817
  var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) {
867
818
  var prevented = false;
868
-
869
819
  var adapterWithPrevent = function adapterWithPrevent(ev) {
870
820
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
871
821
  args[_key8 - 1] = arguments[_key8];
872
822
  }
873
-
874
823
  var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
875
- var existingPreventDefault = null; // Handle either no adapter or a non-object return from the adapter
824
+ var existingPreventDefault = null;
876
825
 
826
+ // Handle either no adapter or a non-object return from the adapter
877
827
  if (!customEventPayload || typeof customEventPayload !== 'object') {
878
828
  customEventPayload = {};
879
829
  }
880
-
881
830
  if (typeof customEventPayload.preventDefault === 'function') {
882
831
  existingPreventDefault = customEventPayload.preventDefault;
883
832
  } else if (typeof ev.preventDefault === 'function') {
884
833
  existingPreventDefault = ev.preventDefault.bind(ev);
885
834
  }
886
-
887
835
  customEventPayload.preventDefault = function () {
888
836
  prevented = true;
889
-
890
837
  if (typeof existingPreventDefault === 'function') {
891
838
  existingPreventDefault();
892
839
  }
893
840
  };
894
-
895
841
  return customEventPayload;
896
842
  };
897
-
898
843
  return handle(forwardCustom(name, adapterWithPrevent), function () {
899
844
  return !prevented;
900
845
  });
901
846
  }, 'forwardCustomWithPrevent');
847
+
902
848
  /**
903
849
  * Accepts a handler and returns the logical complement of the value returned from the handler.
904
850
  *
@@ -924,15 +870,12 @@ var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function
924
870
  * @memberof core/handle
925
871
  * @public
926
872
  */
927
-
928
873
  exports.forwardCustomWithPrevent = forwardCustomWithPrevent;
929
-
930
874
  var not = handle.not = function (handler) {
931
875
  return function () {
932
876
  return !handler.apply(void 0, arguments);
933
877
  };
934
878
  };
935
-
936
879
  exports.not = not;
937
880
  var _default = handle;
938
881
  exports["default"] = _default;