@enact/core 4.7.0 → 4.7.2

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  The following is a curated list of changes in the Enact core module, newest changes on the top.
4
4
 
5
+ ## [4.7.2] - 2023-07-14
6
+
7
+ ### Fixed
8
+
9
+ - `core/handle.forwardCustom` and `core/handle.forwardCustomWithPrevent` to bind an adapter function properly
10
+
11
+ ## [4.7.1] - 2023-06-02
12
+
13
+ No significant changes.
14
+
15
+ ## [4.5.3] - 2023-04-06
16
+
17
+ No significant changes.
18
+
5
19
  ## [4.7.0] - 2023-04-25
6
20
 
7
21
  ### Deprecated
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install --save @enact/core
14
14
 
15
15
  ## Test
16
16
 
17
- Tests are implemented in mocha and are run with the Karma runner.
17
+ Unit tests are implemented in Testing Library and are run with Jest. To execute them:
18
18
 
19
19
  ```
20
20
  npm test
package/handle/handle.js CHANGED
@@ -751,11 +751,11 @@ var adaptEvent = handle.adaptEvent = (0, _curry["default"])(function (adapter, h
751
751
  */
752
752
  exports.adaptEvent = adaptEvent;
753
753
  var forwardCustom = handle.forwardCustom = function (name, adapter) {
754
- return handle(adaptEvent(function (ev) {
754
+ return named(adaptEvent(function (ev) {
755
755
  for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
756
756
  args[_key7 - 1] = arguments[_key7];
757
757
  }
758
- var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
758
+ var customEventPayload = adapter ? adapter.call.apply(adapter, [this, ev].concat(args)) : null;
759
759
 
760
760
  // Handle either no adapter or a non-object return from the adapter
761
761
  if (!customEventPayload || typeof customEventPayload !== 'object') {
@@ -769,7 +769,7 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
769
769
  customEventPayload.stopPropagation = ev.stopPropagation.bind(ev);
770
770
  }
771
771
  return customEventPayload;
772
- }, forward(name))).named('forwardCustom');
772
+ }, forward(name)), 'forwardCustom');
773
773
  };
774
774
 
775
775
  /**
@@ -814,14 +814,14 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
814
814
  * @private
815
815
  */
816
816
  exports.forwardCustom = forwardCustom;
817
- var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) {
818
- return function (ev) {
817
+ var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = function (name, adapter) {
818
+ return named(function (ev) {
819
819
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
820
820
  args[_key8 - 1] = arguments[_key8];
821
821
  }
822
822
  var prevented = false;
823
- var adapterWithPrevent = function adapterWithPrevent() {
824
- var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
823
+ function adapterWithPrevent() {
824
+ var customEventPayload = adapter ? adapter.call.apply(adapter, [this, ev].concat(args)) : null;
825
825
  var existingPreventDefault = null;
826
826
 
827
827
  // Handle either no adapter or a non-object return from the adapter
@@ -840,10 +840,10 @@ var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function
840
840
  }
841
841
  };
842
842
  return customEventPayload;
843
- };
844
- return forwardCustom(name, adapterWithPrevent).apply(void 0, [ev].concat(args)) && !prevented;
845
- };
846
- }, 'forwardCustomWithPrevent');
843
+ }
844
+ return forwardCustom.call(this, name, adapterWithPrevent.bind(this)).apply(void 0, [ev].concat(args)) && !prevented;
845
+ }, 'forwardCustomWithPrevent');
846
+ };
847
847
 
848
848
  /**
849
849
  * Accepts a handler and returns the logical complement of the value returned from the handler.
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
 
3
+ var _propTypes = _interopRequireDefault(require("prop-types"));
4
+ var _react = require("react");
5
+ var _react2 = require("@testing-library/react");
3
6
  var _handle = require("../handle");
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ 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, _toPropertyKey(descriptor.key), descriptor); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ 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; } }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
4
19
  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; }
5
20
  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; }
6
21
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -445,6 +460,91 @@ describe('handle', function () {
445
460
  var actual = adapter.mock.calls[0];
446
461
  expect(actual).toEqual(expected);
447
462
  });
463
+ test('should support bound adapter function', function () {
464
+ var handler = jest.fn();
465
+ var expected = 'ok';
466
+ var obj = {
467
+ data: expected,
468
+ adapter: function adapter() {
469
+ return {
470
+ value: this === null || this === void 0 ? void 0 : this.data
471
+ };
472
+ }
473
+ };
474
+ var forwarderFn = (0, _handle.forwardCustom)('onCustomEvent', obj.adapter).bind(obj);
475
+ forwarderFn(null, {
476
+ onCustomEvent: handler
477
+ }, null);
478
+ var actual = handler.mock.calls[0][0];
479
+ expect(actual).toEqual(expect.objectContaining({
480
+ value: expected
481
+ }));
482
+ });
483
+ test('should support bound adapter function by call', function () {
484
+ var handler = jest.fn();
485
+ var expected = 'ok';
486
+ var obj = {
487
+ data: expected,
488
+ adapter: function adapter() {
489
+ return {
490
+ value: this === null || this === void 0 ? void 0 : this.data
491
+ };
492
+ }
493
+ };
494
+ var forwarderFn = (0, _handle.forwardCustom)('onCustomEvent', (0, _handle.call)('adapter')).bind(obj);
495
+ forwarderFn(null, {
496
+ onCustomEvent: handler
497
+ }, null);
498
+ var actual = handler.mock.calls[0][0];
499
+ expect(actual).toEqual(expect.objectContaining({
500
+ value: expected
501
+ }));
502
+ });
503
+ test('should support bound adapter function by handle', function () {
504
+ var handler = jest.fn();
505
+ var expected = 'ok';
506
+ var TestComponent = /*#__PURE__*/function (_Component) {
507
+ _inherits(TestComponent, _Component);
508
+ var _super = _createSuper(TestComponent);
509
+ function TestComponent(props) {
510
+ var _this;
511
+ _classCallCheck(this, TestComponent);
512
+ _this = _super.call(this, props);
513
+ _this.data = expected;
514
+ (0, _handle.handle)((0, _handle.forwardCustom)('onCustomEvent', (0, _handle.call)('adapter'))).bindAs(_assertThisInitialized(_this), 'handleCustomEvent');
515
+ return _this;
516
+ }
517
+ _createClass(TestComponent, [{
518
+ key: "componentDidMount",
519
+ value: function componentDidMount() {
520
+ this.handleCustomEvent(null, this.props, this.context);
521
+ }
522
+ }, {
523
+ key: "adapter",
524
+ value: function adapter() {
525
+ return {
526
+ value: this === null || this === void 0 ? void 0 : this.data
527
+ };
528
+ }
529
+ }, {
530
+ key: "render",
531
+ value: function render() {
532
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
533
+ }
534
+ }]);
535
+ return TestComponent;
536
+ }(_react.Component);
537
+ TestComponent.propTypes = {
538
+ onCustomEvent: _propTypes["default"].func
539
+ };
540
+ (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {
541
+ onCustomEvent: handler
542
+ }));
543
+ var actual = handler.mock.calls[0][0];
544
+ expect(actual).toEqual(expect.objectContaining({
545
+ value: expected
546
+ }));
547
+ });
448
548
  });
449
549
  describe('#forwardCustomWithPrevent', function () {
450
550
  test('should pass an object with `type` and `preventDefault` when no adapter is provided', function () {
@@ -524,6 +624,91 @@ describe('handle', function () {
524
624
  var actual = adapter.mock.calls[0];
525
625
  expect(actual).toEqual(expected);
526
626
  });
627
+ test('should support bound adapter function', function () {
628
+ var handler = jest.fn();
629
+ var expected = 'ok';
630
+ var obj = {
631
+ data: expected,
632
+ adapter: function adapter() {
633
+ return {
634
+ value: this === null || this === void 0 ? void 0 : this.data
635
+ };
636
+ }
637
+ };
638
+ var forwarderFn = (0, _handle.forwardCustomWithPrevent)('onCustomEvent', obj.adapter).bind(obj);
639
+ forwarderFn(null, {
640
+ onCustomEvent: handler
641
+ }, null);
642
+ var actual = handler.mock.calls[0][0];
643
+ expect(actual).toEqual(expect.objectContaining({
644
+ value: expected
645
+ }));
646
+ });
647
+ test('should support bound adapter function by call', function () {
648
+ var handler = jest.fn();
649
+ var expected = 'ok';
650
+ var obj = {
651
+ data: expected,
652
+ adapter: function adapter() {
653
+ return {
654
+ value: this === null || this === void 0 ? void 0 : this.data
655
+ };
656
+ }
657
+ };
658
+ var forwarderFn = (0, _handle.forwardCustomWithPrevent)('onCustomEvent', (0, _handle.call)('adapter')).bind(obj);
659
+ forwarderFn(null, {
660
+ onCustomEvent: handler
661
+ }, null);
662
+ var actual = handler.mock.calls[0][0];
663
+ expect(actual).toEqual(expect.objectContaining({
664
+ value: expected
665
+ }));
666
+ });
667
+ test('should support bound adapter function by handle', function () {
668
+ var handler = jest.fn();
669
+ var expected = 'ok';
670
+ var TestComponent = /*#__PURE__*/function (_Component2) {
671
+ _inherits(TestComponent, _Component2);
672
+ var _super2 = _createSuper(TestComponent);
673
+ function TestComponent(props) {
674
+ var _this2;
675
+ _classCallCheck(this, TestComponent);
676
+ _this2 = _super2.call(this, props);
677
+ _this2.data = expected;
678
+ (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)('onCustomEvent', (0, _handle.call)('adapter'))).bindAs(_assertThisInitialized(_this2), 'handleCustomEvent');
679
+ return _this2;
680
+ }
681
+ _createClass(TestComponent, [{
682
+ key: "componentDidMount",
683
+ value: function componentDidMount() {
684
+ this.handleCustomEvent(null, this.props, this.context);
685
+ }
686
+ }, {
687
+ key: "adapter",
688
+ value: function adapter() {
689
+ return {
690
+ value: this === null || this === void 0 ? void 0 : this.data
691
+ };
692
+ }
693
+ }, {
694
+ key: "render",
695
+ value: function render() {
696
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
697
+ }
698
+ }]);
699
+ return TestComponent;
700
+ }(_react.Component);
701
+ TestComponent.propTypes = {
702
+ onCustomEvent: _propTypes["default"].func
703
+ };
704
+ (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {
705
+ onCustomEvent: handler
706
+ }));
707
+ var actual = handler.mock.calls[0][0];
708
+ expect(actual).toEqual(expect.objectContaining({
709
+ value: expected
710
+ }));
711
+ });
527
712
  test('should call the next handler when `preventDefault` from provided props hasn\'t been called', function () {
528
713
  var event = 'onMyClick';
529
714
  var handler = jest.fn();
@@ -7,6 +7,8 @@ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
7
7
  var _Registry = _interopRequireDefault(require("../Registry"));
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
12
  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; }
11
13
  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; }
12
14
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -116,19 +118,21 @@ describe('Registry', function () {
116
118
  return HandlesNotification;
117
119
  }(_react.Component);
118
120
  HandlesNotification.contextType = SomeContext;
119
- test('should increment child on click', function () {
121
+ test('should increment child on click', /*#__PURE__*/_asyncToGenerator(function* () {
122
+ var user = _userEvent["default"].setup();
120
123
  (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
121
124
  "data-testid": "a-btn",
122
125
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
123
126
  "data-testid": "a"
124
127
  })
125
128
  }));
126
- _userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
129
+ yield user.click(_react2.screen.getByTestId('a-btn'));
127
130
  var expected = '1';
128
131
  var child = _react2.screen.getByTestId('a');
129
132
  expect(child).toHaveTextContent(expected);
130
- });
131
- test('should increment both children on top click', function () {
133
+ }));
134
+ test('should increment both children on top click', /*#__PURE__*/_asyncToGenerator(function* () {
135
+ var user = _userEvent["default"].setup();
132
136
  (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
133
137
  "data-testid": "a-btn",
134
138
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
@@ -140,14 +144,15 @@ describe('Registry', function () {
140
144
  })
141
145
  })]
142
146
  }));
143
- _userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
147
+ yield user.click(_react2.screen.getByTestId('a-btn'));
144
148
  var expected = '1';
145
149
  var childA = _react2.screen.getByTestId('a');
146
150
  var childB = _react2.screen.getByTestId('b');
147
151
  expect(childA).toHaveTextContent(expected);
148
152
  expect(childB).toHaveTextContent(expected);
149
- });
150
- test('should increment the deepest child when we click child button', function () {
153
+ }));
154
+ test('should increment the deepest child when we click child button', /*#__PURE__*/_asyncToGenerator(function* () {
155
+ var user = _userEvent["default"].setup();
151
156
  (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
152
157
  "data-testid": "a-btn",
153
158
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
@@ -159,15 +164,16 @@ describe('Registry', function () {
159
164
  })
160
165
  })]
161
166
  }));
162
- _userEvent["default"].click(_react2.screen.getByTestId('b-btn'));
167
+ yield user.click(_react2.screen.getByTestId('b-btn'));
163
168
  var expectedA = '0';
164
169
  var expectedB = '1';
165
170
  var childA = _react2.screen.getByTestId('a');
166
171
  var childB = _react2.screen.getByTestId('b');
167
172
  expect(childA).toHaveTextContent(expectedA);
168
173
  expect(childB).toHaveTextContent(expectedB);
169
- });
170
- test('should support removing children without error', function () {
174
+ }));
175
+ test('should support removing children without error', /*#__PURE__*/_asyncToGenerator(function* () {
176
+ var user = _userEvent["default"].setup();
171
177
  var _render = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
172
178
  "data-testid": "a-btn",
173
179
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
@@ -177,7 +183,7 @@ describe('Registry', function () {
177
183
  })]
178
184
  })),
179
185
  rerender = _render.rerender;
180
- _userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
186
+ yield user.click(_react2.screen.getByTestId('a-btn'));
181
187
 
182
188
  // changing children should be safe and not throw errors when notifying instances
183
189
  rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
@@ -186,9 +192,9 @@ describe('Registry', function () {
186
192
  "data-testid": "c"
187
193
  })
188
194
  }));
189
- _userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
195
+ yield user.click(_react2.screen.getByTestId('a-btn'));
190
196
  var expectedC = '1';
191
197
  var childC = _react2.screen.getByTestId('c');
192
198
  expect(childC).toHaveTextContent(expectedC);
193
- });
199
+ }));
194
200
  });
@@ -15,6 +15,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
15
15
  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; }
16
16
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
17
17
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
18
20
  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; }
19
21
  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; }
20
22
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -119,18 +121,19 @@ describe('kind', function () {
119
121
  var kindDiv = _react.screen.getByTitle('Label');
120
122
  expect(kindDiv).toHaveTextContent(expected);
121
123
  });
122
- test('should support contextType in handlers', function () {
124
+ test('should support contextType in handlers', /*#__PURE__*/_asyncToGenerator(function* () {
123
125
  var onClick = jest.fn();
126
+ var user = _userEvent["default"].setup();
124
127
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
125
128
  onClick: onClick,
126
129
  prop: 1
127
130
  }));
128
131
  var kindDiv = _react.screen.getByTitle('Label');
129
- _userEvent["default"].click(kindDiv);
132
+ yield user.click(kindDiv);
130
133
  var expected = 'initial';
131
134
  var actual = onClick.mock.calls[0][0];
132
135
  expect(actual).toBe(expected);
133
- });
136
+ }));
134
137
  test('should support contextType in computed', function () {
135
138
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
136
139
  prop: 1
@@ -139,7 +142,8 @@ describe('kind', function () {
139
142
  var kindDiv = _react.screen.getByTitle('Label');
140
143
  expect(kindDiv).toHaveAttribute('data-context', expected);
141
144
  });
142
- test('support using hooks within kind instances', function () {
145
+ test('support using hooks within kind instances', /*#__PURE__*/_asyncToGenerator(function* () {
146
+ var user = _userEvent["default"].setup();
143
147
  var Comp = (0, _kind["default"])({
144
148
  name: 'Comp',
145
149
  functional: true,
@@ -160,10 +164,10 @@ describe('kind', function () {
160
164
  });
161
165
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
162
166
  var button = _react.screen.getByTestId('button');
163
- _userEvent["default"].click(button);
167
+ yield user.click(button);
164
168
  var expected = '1';
165
169
  expect(button).toHaveTextContent(expected);
166
- });
170
+ }));
167
171
  describe('inline', function () {
168
172
  test('should support a minimal kind', function () {
169
173
  var Minimal = (0, _kind["default"])({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/core",
3
- "version": "4.7.0",
3
+ "version": "4.7.2",
4
4
  "description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,7 +34,7 @@
34
34
  "classnames": "^2.3.2",
35
35
  "invariant": "^2.2.4",
36
36
  "prop-types": "^15.8.1",
37
- "ramda": "^0.28.0",
37
+ "ramda": "^0.29.0",
38
38
  "react": "^18.2.0",
39
39
  "react-dom": "^18.2.0",
40
40
  "react-is": "^18.2.0",
@@ -55,6 +55,14 @@ var platforms = [
55
55
  platform: 'windowsPhone',
56
56
  regex: /Windows Phone (?:OS )?(\d+)[.\d]+/
57
57
  },
58
+ // Edge
59
+ {
60
+ platform: 'edge',
61
+ regex: /Chrome\/(\d+)[.\d]+.*Edg(?:e|A|iOS)?\/(\d+)[.\d]+/
62
+ }, {
63
+ platform: 'edge',
64
+ regex: /Edg(?:e|A|iOS)?\/(\d+)[.\d]+/
65
+ },
58
66
  // Android 4+ using Chrome
59
67
  {
60
68
  platform: 'androidChrome',
@@ -102,11 +110,6 @@ var platforms = [
102
110
  platform: 'ie',
103
111
  regex: /Trident\/.*; rv:(\d+)/
104
112
  },
105
- // Edge
106
- {
107
- platform: 'edge',
108
- regex: /Edge\/(\d+)/
109
- },
110
113
  // iOS 3 - 5
111
114
  // Apple likes to make this complicated
112
115
  {
@@ -235,6 +238,9 @@ var parseUserAgent = function parseUserAgent(userAgent) {
235
238
  if (v >= 7 || v === -1) {
236
239
  plat.chrome = Number(m[1]);
237
240
  }
241
+ } else if (p.platform === 'edge' && m[2]) {
242
+ plat.chrome = Number(m[1]);
243
+ v = Number(m[2]);
238
244
  } else {
239
245
  v = Number(m[1]);
240
246
  }
@@ -116,6 +116,72 @@ describe('platform', function () {
116
116
  expect(actual).toMatchObject(expected);
117
117
  });
118
118
  });
119
+ describe('parseUserAgent for Edge', function () {
120
+ var edge1 = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42';
121
+ var edge2 = 'Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.76 Mobile Safari/537.36 EdgA/113.0.1774.38';
122
+ var edge3 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 EdgiOS/113.1774.42 Mobile/15E148 Safari/605.1.15';
123
+ var edge4 = 'Mozilla/5.0 (Windows Mobile 10; Android 10.0; Microsoft; Lumia 950XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36 Edge/40.15254.603';
124
+ test('should return edge for Edg', function () {
125
+ var expected = {
126
+ platformName: 'edge'
127
+ };
128
+ var actual = (0, _platform.parseUserAgent)(edge1);
129
+ expect(actual).toMatchObject(expected);
130
+ expected = {
131
+ chrome: 113
132
+ };
133
+ expect(actual).toMatchObject(expected);
134
+ expected = {
135
+ edge: 113
136
+ };
137
+ expect(actual).toMatchObject(expected);
138
+ });
139
+ test('should return edge for EdgA', function () {
140
+ var expected = {
141
+ platformName: 'edge'
142
+ };
143
+ var actual = (0, _platform.parseUserAgent)(edge2);
144
+ expect(actual).toMatchObject(expected);
145
+ expected = {
146
+ chrome: 113
147
+ };
148
+ expect(actual).toMatchObject(expected);
149
+ expected = {
150
+ edge: 113
151
+ };
152
+ expect(actual).toMatchObject(expected);
153
+ });
154
+ test('should return edge for EdgiOS', function () {
155
+ var expected = {
156
+ platformName: 'edge'
157
+ };
158
+ var actual = (0, _platform.parseUserAgent)(edge3);
159
+ expect(actual).toMatchObject(expected);
160
+ expected = {
161
+ chrome: 113
162
+ };
163
+ expect(actual).not.toMatchObject(expected);
164
+ expected = {
165
+ edge: 113
166
+ };
167
+ expect(actual).toMatchObject(expected);
168
+ });
169
+ test('should return edge for Edge', function () {
170
+ var expected = {
171
+ platformName: 'edge'
172
+ };
173
+ var actual = (0, _platform.parseUserAgent)(edge4);
174
+ expect(actual).toMatchObject(expected);
175
+ expected = {
176
+ chrome: 113
177
+ };
178
+ expect(actual).toMatchObject(expected);
179
+ expected = {
180
+ edge: 40
181
+ };
182
+ expect(actual).toMatchObject(expected);
183
+ });
184
+ });
119
185
  describe('parseUserAgent for User-Agent Reduction', function () {
120
186
  var testVersion = '113';
121
187
  var uaGenerator = function uaGenerator(unifiedPlatform) {
package/util/Job.js CHANGED
@@ -33,126 +33,6 @@ var Job = /*#__PURE__*/function () {
33
33
  this.fn = null;
34
34
  this.timeout = null;
35
35
  this.type = null;
36
- this.start = function () {
37
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
38
- args[_key] = arguments[_key];
39
- }
40
- _this.startAfter.apply(_this, [_this.timeout].concat(args));
41
- };
42
- this.startAfter = function (timeout) {
43
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
44
- args[_key2 - 1] = arguments[_key2];
45
- }
46
- _this.stop();
47
- _this.type = 'timeout';
48
- _this.id = setTimeout(function () {
49
- return _this.run(args);
50
- }, timeout);
51
- };
52
- this.stop = function () {
53
- if (_this.id) {
54
- if (_this.type === 'idle') {
55
- window.cancelIdleCallback(_this.id);
56
- } else if (_this.type === 'raf') {
57
- window.cancelAnimationFrame(_this.id);
58
- } else if (_this.type === 'timeout') {
59
- clearTimeout(_this.id);
60
- }
61
- _this.id = _this.type = null;
62
- }
63
- };
64
- this.throttle = function () {
65
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
66
- args[_key3] = arguments[_key3];
67
- }
68
- _this.throttleUntil.apply(_this, [_this.timeout].concat(args));
69
- };
70
- this.throttleUntil = function (timeout) {
71
- if (!_this.id) {
72
- _this.type = 'timeout';
73
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
74
- args[_key4 - 1] = arguments[_key4];
75
- }
76
- _this.run(args);
77
- _this.id = setTimeout(_this.stop, timeout);
78
- }
79
- };
80
- this.idle = function () {
81
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
82
- args[_key5] = arguments[_key5];
83
- }
84
- _this.idleUntil.apply(_this, [null].concat(args));
85
- };
86
- this.idleUntil = function (timeout) {
87
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
88
- args[_key6 - 1] = arguments[_key6];
89
- }
90
- if (typeof window !== 'undefined' && window.requestIdleCallback) {
91
- _this.stop();
92
- _this.type = 'idle';
93
- _this.id = window.requestIdleCallback(function () {
94
- return _this.run(args);
95
- }, {
96
- timeout: timeout
97
- });
98
- } else {
99
- // since we can't request an idle callback, just pass to startAfter()
100
- _this.startAfter.apply(_this, [timeout].concat(args));
101
- }
102
- };
103
- this.startRaf = function () {
104
- for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
105
- args[_key7] = arguments[_key7];
106
- }
107
- _this.startRafAfter.apply(_this, [_this.timeout].concat(args));
108
- };
109
- this.startRafAfter = function (timeout) {
110
- for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
111
- args[_key8 - 1] = arguments[_key8];
112
- }
113
- _this.type = 'raf';
114
- if (typeof window !== 'undefined') {
115
- var time = null;
116
- var callback = function callback(timestamp) {
117
- if (time === null) {
118
- time = timestamp;
119
- }
120
- if (timeout && timestamp - time < timeout) {
121
- _this.id = window.requestAnimationFrame(callback);
122
- } else {
123
- time = null;
124
- _this.run(args);
125
- window.cancelAnimationFrame(_this.id);
126
- _this.id = null;
127
- }
128
- };
129
- _this.id = window.requestAnimationFrame(callback);
130
- } else {
131
- // If requestAnimationFrame is not supported just run the function immediately
132
- _this.run(args);
133
- }
134
- };
135
- this.promise = function (promise) {
136
- !(promise && typeof promise.then === 'function') ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'promise expects a thenable') : (0, _invariant["default"])(false) : void 0;
137
- _this.type = 'promise';
138
- _this.id = promise;
139
- return promise.then(function (result) {
140
- if (_this.id === promise) {
141
- _this.stop();
142
- return _this.run([result]);
143
- }
144
- });
145
- };
146
- this.fn = fn;
147
- this.timeout = _timeout;
148
- }
149
- _createClass(Job, [{
150
- key: "run",
151
- value: function run(args) {
152
- // don't want to inadvertently apply Job's context on `fn`
153
- return this.fn.apply(null, args);
154
- }
155
-
156
36
  /**
157
37
  * Starts the job.
158
38
  *
@@ -163,7 +43,12 @@ var Job = /*#__PURE__*/function () {
163
43
  * @memberof core/util.Job.prototype
164
44
  * @public
165
45
  */
166
-
46
+ this.start = function () {
47
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48
+ args[_key] = arguments[_key];
49
+ }
50
+ _this.startAfter.apply(_this, [_this.timeout].concat(args));
51
+ };
167
52
  /**
168
53
  * Starts the job in `timeout` milliseconds
169
54
  *
@@ -176,7 +61,16 @@ var Job = /*#__PURE__*/function () {
176
61
  * @memberof core/util.Job.prototype
177
62
  * @public
178
63
  */
179
-
64
+ this.startAfter = function (timeout) {
65
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
66
+ args[_key2 - 1] = arguments[_key2];
67
+ }
68
+ _this.stop();
69
+ _this.type = 'timeout';
70
+ _this.id = setTimeout(function () {
71
+ return _this.run(args);
72
+ }, timeout);
73
+ };
180
74
  /**
181
75
  * Stops the job.
182
76
  *
@@ -186,7 +80,18 @@ var Job = /*#__PURE__*/function () {
186
80
  * @memberof core/util.Job.prototype
187
81
  * @public
188
82
  */
189
-
83
+ this.stop = function () {
84
+ if (_this.id) {
85
+ if (_this.type === 'idle') {
86
+ window.cancelIdleCallback(_this.id);
87
+ } else if (_this.type === 'raf') {
88
+ window.cancelAnimationFrame(_this.id);
89
+ } else if (_this.type === 'timeout') {
90
+ clearTimeout(_this.id);
91
+ }
92
+ _this.id = _this.type = null;
93
+ }
94
+ };
190
95
  /**
191
96
  * Executes the job immediately, then prevents any other calls to `throttle()` from running
192
97
  * until the `timeout` configured at construction passes.
@@ -198,7 +103,12 @@ var Job = /*#__PURE__*/function () {
198
103
  * @memberof core/util.Job.prototype
199
104
  * @public
200
105
  */
201
-
106
+ this.throttle = function () {
107
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
108
+ args[_key3] = arguments[_key3];
109
+ }
110
+ _this.throttleUntil.apply(_this, [_this.timeout].concat(args));
111
+ };
202
112
  /**
203
113
  * Executes the job immediately, then prevents any other calls to `throttle()` from running for
204
114
  * `timeout` milliseconds.
@@ -212,7 +122,16 @@ var Job = /*#__PURE__*/function () {
212
122
  * @memberof core/util.Job.prototype
213
123
  * @public
214
124
  */
215
-
125
+ this.throttleUntil = function (timeout) {
126
+ if (!_this.id) {
127
+ _this.type = 'timeout';
128
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
129
+ args[_key4 - 1] = arguments[_key4];
130
+ }
131
+ _this.run(args);
132
+ _this.id = setTimeout(_this.stop, timeout);
133
+ }
134
+ };
216
135
  /**
217
136
  * Executes job when the CPU is idle.
218
137
  *
@@ -223,7 +142,12 @@ var Job = /*#__PURE__*/function () {
223
142
  * @memberof core/util.Job.prototype
224
143
  * @public
225
144
  */
226
-
145
+ this.idle = function () {
146
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
147
+ args[_key5] = arguments[_key5];
148
+ }
149
+ _this.idleUntil.apply(_this, [null].concat(args));
150
+ };
227
151
  /**
228
152
  * Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first.
229
153
  *
@@ -237,7 +161,23 @@ var Job = /*#__PURE__*/function () {
237
161
  * @memberof core/util.Job.prototype
238
162
  * @public
239
163
  */
240
-
164
+ this.idleUntil = function (timeout) {
165
+ for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
166
+ args[_key6 - 1] = arguments[_key6];
167
+ }
168
+ if (typeof window !== 'undefined' && window.requestIdleCallback) {
169
+ _this.stop();
170
+ _this.type = 'idle';
171
+ _this.id = window.requestIdleCallback(function () {
172
+ return _this.run(args);
173
+ }, {
174
+ timeout: timeout
175
+ });
176
+ } else {
177
+ // since we can't request an idle callback, just pass to startAfter()
178
+ _this.startAfter.apply(_this, [timeout].concat(args));
179
+ }
180
+ };
241
181
  /**
242
182
  * Executes job before the next repaint.
243
183
  *
@@ -248,7 +188,12 @@ var Job = /*#__PURE__*/function () {
248
188
  * @memberof core/util.Job.prototype
249
189
  * @public
250
190
  */
251
-
191
+ this.startRaf = function () {
192
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
193
+ args[_key7] = arguments[_key7];
194
+ }
195
+ _this.startRafAfter.apply(_this, [_this.timeout].concat(args));
196
+ };
252
197
  /**
253
198
  * Executes job before the next repaint after a given amount of timeout.
254
199
  *
@@ -260,7 +205,32 @@ var Job = /*#__PURE__*/function () {
260
205
  * @memberof core/util.Job.prototype
261
206
  * @public
262
207
  */
263
-
208
+ this.startRafAfter = function (timeout) {
209
+ for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
210
+ args[_key8 - 1] = arguments[_key8];
211
+ }
212
+ _this.type = 'raf';
213
+ if (typeof window !== 'undefined') {
214
+ var time = null;
215
+ var callback = function callback(timestamp) {
216
+ if (time === null) {
217
+ time = timestamp;
218
+ }
219
+ if (timeout && timestamp - time < timeout) {
220
+ _this.id = window.requestAnimationFrame(callback);
221
+ } else {
222
+ time = null;
223
+ _this.run(args);
224
+ window.cancelAnimationFrame(_this.id);
225
+ _this.id = null;
226
+ }
227
+ };
228
+ _this.id = window.requestAnimationFrame(callback);
229
+ } else {
230
+ // If requestAnimationFrame is not supported just run the function immediately
231
+ _this.run(args);
232
+ }
233
+ };
264
234
  /**
265
235
  * Starts the job when `promise` resolves.
266
236
  *
@@ -281,6 +251,26 @@ var Job = /*#__PURE__*/function () {
281
251
  * @memberof core/util.Job.prototype
282
252
  * @public
283
253
  */
254
+ this.promise = function (promise) {
255
+ !(promise && typeof promise.then === 'function') ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'promise expects a thenable') : (0, _invariant["default"])(false) : void 0;
256
+ _this.type = 'promise';
257
+ _this.id = promise;
258
+ return promise.then(function (result) {
259
+ if (_this.id === promise) {
260
+ _this.stop();
261
+ return _this.run([result]);
262
+ }
263
+ });
264
+ };
265
+ this.fn = fn;
266
+ this.timeout = _timeout;
267
+ }
268
+ _createClass(Job, [{
269
+ key: "run",
270
+ value: function run(args) {
271
+ // don't want to inadvertently apply Job's context on `fn`
272
+ return this.fn.apply(null, args);
273
+ }
284
274
  }]);
285
275
  return Job;
286
276
  }();