@enact/core 4.6.2 → 4.7.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.
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.1] - 2023-06-02
6
+
7
+ No significant changes.
8
+
9
+ ## [4.5.3] - 2023-04-06
10
+
11
+ No significant changes.
12
+
13
+ ## [4.7.0] - 2023-04-25
14
+
15
+ ### Deprecated
16
+
17
+ - `windowsPhone` platform in `core/platform.platforms` to be removed in 5.0.0
18
+
5
19
  ## [4.6.2] - 2023-03-09
6
20
 
7
21
  No significant changes.
@@ -14,7 +28,7 @@ No significant changes.
14
28
 
15
29
  ### Fixed
16
30
 
17
- - `core/dispatcher` to set the default target for event listeners properly when built with the snapshot option
31
+ - `core/dispatcher` to set the default target for event listeners properly when built with the snapshot option
18
32
 
19
33
  ## [4.0.12] - 2022-09-16
20
34
 
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
@@ -815,34 +815,34 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
815
815
  */
816
816
  exports.forwardCustom = forwardCustom;
817
817
  var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) {
818
- var prevented = false;
819
- var adapterWithPrevent = function adapterWithPrevent(ev) {
818
+ return function (ev) {
820
819
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
821
820
  args[_key8 - 1] = arguments[_key8];
822
821
  }
823
- var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
824
- var existingPreventDefault = null;
822
+ var prevented = false;
823
+ var adapterWithPrevent = function adapterWithPrevent() {
824
+ var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
825
+ var existingPreventDefault = null;
825
826
 
826
- // Handle either no adapter or a non-object return from the adapter
827
- if (!customEventPayload || typeof customEventPayload !== 'object') {
828
- customEventPayload = {};
829
- }
830
- if (typeof customEventPayload.preventDefault === 'function') {
831
- existingPreventDefault = customEventPayload.preventDefault;
832
- } else if (typeof ev.preventDefault === 'function') {
833
- existingPreventDefault = ev.preventDefault.bind(ev);
834
- }
835
- customEventPayload.preventDefault = function () {
836
- prevented = true;
837
- if (typeof existingPreventDefault === 'function') {
838
- existingPreventDefault();
827
+ // Handle either no adapter or a non-object return from the adapter
828
+ if (!customEventPayload || typeof customEventPayload !== 'object') {
829
+ customEventPayload = {};
830
+ }
831
+ if (typeof customEventPayload.preventDefault === 'function') {
832
+ existingPreventDefault = customEventPayload.preventDefault;
833
+ } else if (typeof (ev === null || ev === void 0 ? void 0 : ev.preventDefault) === 'function') {
834
+ existingPreventDefault = ev.preventDefault.bind(ev);
839
835
  }
836
+ customEventPayload.preventDefault = function () {
837
+ prevented = true;
838
+ if (typeof existingPreventDefault === 'function') {
839
+ existingPreventDefault(ev);
840
+ }
841
+ };
842
+ return customEventPayload;
840
843
  };
841
- return customEventPayload;
844
+ return forwardCustom(name, adapterWithPrevent).apply(void 0, [ev].concat(args)) && !prevented;
842
845
  };
843
- return handle(forwardCustom(name, adapterWithPrevent), function () {
844
- return !prevented;
845
- });
846
846
  }, 'forwardCustomWithPrevent');
847
847
 
848
848
  /**
@@ -446,4 +446,103 @@ describe('handle', function () {
446
446
  expect(actual).toEqual(expected);
447
447
  });
448
448
  });
449
+ describe('#forwardCustomWithPrevent', function () {
450
+ test('should pass an object with `type` and `preventDefault` when no adapter is provided', function () {
451
+ var handler = jest.fn();
452
+ (0, _handle.forwardCustomWithPrevent)('onCustomEvent')(null, {
453
+ onCustomEvent: handler
454
+ });
455
+ var actual = handler.mock.calls[0][0];
456
+ expect(actual).toEqual(expect.objectContaining({
457
+ type: 'onCustomEvent',
458
+ preventDefault: expect.any(Function)
459
+ }));
460
+ });
461
+ test('should add `type` and `preventDefault` to object returned by adapter', function () {
462
+ var handler = jest.fn();
463
+ var adapter = function adapter() {
464
+ return {
465
+ index: 0
466
+ };
467
+ };
468
+ (0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, {
469
+ onCustomEvent: handler
470
+ });
471
+ var actual = handler.mock.calls[0][0];
472
+ expect(actual).toEqual(expect.objectContaining({
473
+ type: 'onCustomEvent',
474
+ preventDefault: expect.any(Function),
475
+ index: 0
476
+ }));
477
+ });
478
+ test('should create an event payload if the adapter returns nothing', function () {
479
+ var handler = jest.fn();
480
+ var adapter = function adapter() {
481
+ return null;
482
+ };
483
+ (0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, {
484
+ onCustomEvent: handler
485
+ });
486
+ var actual = handler.mock.calls[0][0];
487
+ expect(actual).toEqual(expect.objectContaining({
488
+ type: 'onCustomEvent',
489
+ preventDefault: expect.any(Function)
490
+ }));
491
+ });
492
+ test('should pass an object with `preventDefault` and `stopPropagation` when event has them', function () {
493
+ var ev = {
494
+ preventDefault: jest.fn(),
495
+ stopPropagation: function stopPropagation() {}
496
+ };
497
+ var handler = jest.fn();
498
+ var adapter = function adapter() {
499
+ return null;
500
+ };
501
+ (0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(ev, {
502
+ onCustomEvent: handler
503
+ });
504
+ var actual = handler.mock.calls[0][0];
505
+ expect(actual).toEqual(expect.objectContaining({
506
+ type: 'onCustomEvent',
507
+ preventDefault: expect.any(Function),
508
+ stopPropagation: expect.any(Function)
509
+ }));
510
+ actual.preventDefault();
511
+ expect(ev.preventDefault).toHaveBeenCalled();
512
+ });
513
+ test('should pass event, props, and context args to adapter', function () {
514
+ var adapter = jest.fn();
515
+ var args = [1,
516
+ // ev,
517
+ 2,
518
+ // props,
519
+ 3 // context
520
+ ];
521
+
522
+ (0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter).apply(void 0, args);
523
+ var expected = args;
524
+ var actual = adapter.mock.calls[0];
525
+ expect(actual).toEqual(expected);
526
+ });
527
+ test('should call the next handler when `preventDefault` from provided props hasn\'t been called', function () {
528
+ var event = 'onMyClick';
529
+ var handler = jest.fn();
530
+ var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler);
531
+ callback();
532
+ expect(handler).toHaveBeenCalledTimes(1);
533
+ });
534
+ test('should not call the next handler when `preventDefault` from provided props has been called', function () {
535
+ var event = 'onMyClick';
536
+ var handler = jest.fn();
537
+ var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler);
538
+
539
+ // should stop chain when `preventDefault()` has been called
540
+ callback({}, {
541
+ 'onMyClick': function onMyClick(ev) {
542
+ return ev.preventDefault();
543
+ }
544
+ });
545
+ expect(handler).not.toHaveBeenCalled();
546
+ });
547
+ });
449
548
  });
@@ -9,7 +9,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
9
9
  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; }
10
10
  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; }
11
11
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
12
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable enact/display-name */
13
13
  describe('hoc', function () {
14
14
  var data;
15
15
  var testID = 'test-HoC';
@@ -23,8 +23,12 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
23
23
  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); }
24
24
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
25
  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; } }
26
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
- // Gets a property from `provider`
26
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**
27
+ * Provides the `ApiDecorator` higher-order component
28
+ *
29
+ * @module core/internal/ApiDecorator
30
+ * @private
31
+ */ // Gets a property from `provider`
28
32
  var get = function get(provider, name) {
29
33
  return function () {
30
34
  if (provider) {
@@ -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
  });
package/kind/kind.d.ts CHANGED
@@ -20,19 +20,55 @@ export interface HandlerFunction {
20
20
  * Configuration for CSS class name mapping
21
21
  */
22
22
  export interface StylesBlock {
23
- css: { [key: string]: string };
24
- className?: string;
23
+ /**
24
+ * The CSS of the component
25
+ */
26
+ css: { [key: string]: string }
27
+ /**
28
+ * The className of the component
29
+ */;
30
+ className?: string /**
31
+ * Specifies which class names are overridable.
32
+ If this value is `true` , all of the class names of the component CSS will become public.
33
+ */;
25
34
  publicClassNames?: boolean | string | string[];
26
35
  }
27
36
  export interface KindConfig {
28
- name?: string;
29
- functional?: boolean;
30
- propTypes?: { [key: string]: Function };
31
- defaultProps?: { [key: string]: any };
32
- contextType?: object;
33
- styles?: StylesBlock;
34
- handlers?: { [key: string]: HandlerFunction };
35
- computed?: { [key: string]: ComputedPropFunction };
37
+ /**
38
+ * The name of the component
39
+ */
40
+ name?: string
41
+ /**
42
+ * Boolean controlling whether the returned component should be a functional component
43
+ */;
44
+ functional?: boolean
45
+ /**
46
+ * Specifies expected props
47
+ */;
48
+ propTypes?: { [key: string]: Function }
49
+ /**
50
+ * Sets the default props
51
+ */;
52
+ defaultProps?: { [key: string]: any }
53
+ /**
54
+ * Specifies context type
55
+ */;
56
+ contextType?: object
57
+ /**
58
+ * Configures styles with the static className to merge with user className
59
+ */;
60
+ styles?: StylesBlock /**
61
+ * Adds event handlers that are cached between calls to prevent recreating each call.
62
+ Any handlers are added to the props passed to `render()` . See .
63
+ */;
64
+ handlers?: { [key: string]: HandlerFunction }
65
+ /**
66
+ * Adds some computed properties, these are added to props passed to `render()`
67
+ */;
68
+ computed?: { [key: string]: ComputedPropFunction }
69
+ /**
70
+ * The render function
71
+ */;
36
72
  render: RenderFunction;
37
73
  }
38
74
  /**
@@ -43,7 +79,7 @@ export interface KindConfig {
43
79
  import css from './Button.module.less';
44
80
  const Button = kind({
45
81
  name: 'Button',
46
- // Return a functional component suitable for use with React hooks
82
+ // Return a functional component
47
83
  functional: true,
48
84
  // expect color and onClick properties but neither required
49
85
  propTypes: {
package/kind/kind.js CHANGED
@@ -24,7 +24,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
24
24
  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; }
25
25
  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; }
26
26
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
27
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
27
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
28
+ * Provides the {@link core/kind.kind} method to create components
29
+ *
30
+ * @module core/kind
31
+ * @exports kind
32
+ */
28
33
  // Because contextType is optional and hooks must be called in the same order, we need a fallback
29
34
  // context when none is specified. This likely has some overhead so we may want to deprecate and
30
35
  // remove contextType support for 4.0 since the context APIs have improved since this was added.
@@ -59,23 +64,25 @@ var NoContext = /*#__PURE__*/(0, _react.createContext)(null);
59
64
  *
60
65
  * @typedef {Object} StylesBlock
61
66
  * @memberof core/kind
62
- * @property {Object.<string, string>} css
63
- * @property {String} [className]
64
- * @property {Boolean|String|String[]} [publicClassNames]
67
+ * @property {Object.<string, string>} css The CSS of the component
68
+ * @property {String} [className] The className of the component
69
+ * @property {Boolean|String|String[]} [publicClassNames] Specifies which class names are overridable.
70
+ * If this value is `true`, all of the class names of the component CSS will become public.
65
71
  */
66
72
 
67
73
  /**
68
74
  * @typedef {Object} KindConfig
69
75
  * @memberof core/kind
70
- * @property {String} [name]
71
- * @property {Boolean} [functional]
72
- * @property {Object.<string, Function>} [propTypes]
73
- * @property {Object.<string, any>} [defaultProps]
74
- * @property {Object} [contextType]
75
- * @property {StylesBlock} [styles]
76
- * @property {Object.<string, HandlerFunction>} [handlers]
77
- * @property {Object.<string, ComputedPropFunction>} [computed]
78
- * @property {RenderFunction} render
76
+ * @property {String} [name] The name of the component
77
+ * @property {Boolean} [functional] Boolean controlling whether the returned component should be a functional component
78
+ * @property {Object.<string, Function>} [propTypes] Specifies expected props
79
+ * @property {Object.<string, any>} [defaultProps] Sets the default props
80
+ * @property {Object} [contextType] Specifies context type
81
+ * @property {StylesBlock} [styles] Configures styles with the static className to merge with user className
82
+ * @property {Object.<string, HandlerFunction>} [handlers] Adds event handlers that are cached between calls to prevent recreating each call.
83
+ * Any handlers are added to the props passed to `render()`. See {@link core/handle.handle}.
84
+ * @property {Object.<string, ComputedPropFunction>} [computed] Adds some computed properties, these are added to props passed to `render()`
85
+ * @property {RenderFunction} render The render function
79
86
  */
80
87
 
81
88
  /**
@@ -86,7 +93,7 @@ var NoContext = /*#__PURE__*/(0, _react.createContext)(null);
86
93
  * import css from './Button.module.less';
87
94
  * const Button = kind({
88
95
  * name: 'Button',
89
- * // Return a functional component suitable for use with React hooks
96
+ * // Return a functional component
90
97
  * functional: true,
91
98
  * // expect color and onClick properties but neither required
92
99
  * propTypes: {
@@ -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.6.2",
3
+ "version": "4.7.1",
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",
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.platform = exports.parseUserAgent = exports.detect = exports["default"] = void 0;
7
7
  var _uniq = _interopRequireDefault(require("ramda/src/uniq"));
8
+ var _deprecate = _interopRequireDefault(require("../internal/deprecate"));
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
10
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
11
  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."); }
@@ -16,7 +17,14 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
16
17
  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; }
17
18
  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; }
18
19
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
19
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
21
+ * Utilities for detecting basic platform capabilities.
22
+ *
23
+ * @module core/platform
24
+ * @exports detect
25
+ * @exports platform
26
+ * @public
27
+ */
20
28
  var hasGesture = function hasGesture() {
21
29
  return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1));
22
30
  };
@@ -238,6 +246,12 @@ var parseUserAgent = function parseUserAgent(userAgent) {
238
246
  break;
239
247
  }
240
248
  }
249
+ if (plat.platformName === 'windowsPhone') {
250
+ (0, _deprecate["default"])({
251
+ name: 'Windows Phone platform',
252
+ until: '5.0.0'
253
+ });
254
+ }
241
255
  return plat;
242
256
  };
243
257
 
@@ -106,6 +106,16 @@ describe('platform', function () {
106
106
  expect((0, _platform.parseUserAgent)(webOS2)).toMatchObject(expected);
107
107
  });
108
108
  });
109
+ describe('parseUserAgent for Windows Phone', function () {
110
+ var windowsPhone = 'Mozilla/5.0 (Windows Phone 8.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4103.84 Mobile Safari/537.36';
111
+ test('should return platformName `windowsPhone`', function () {
112
+ var expected = {
113
+ platformName: 'windowsPhone'
114
+ };
115
+ var actual = (0, _platform.parseUserAgent)(windowsPhone);
116
+ expect(actual).toMatchObject(expected);
117
+ });
118
+ });
109
119
  describe('parseUserAgent for User-Agent Reduction', function () {
110
120
  var testVersion = '113';
111
121
  var uaGenerator = function uaGenerator(unifiedPlatform) {
package/util/Job.js CHANGED
@@ -33,12 +33,34 @@ var Job = /*#__PURE__*/function () {
33
33
  this.fn = null;
34
34
  this.timeout = null;
35
35
  this.type = null;
36
+ /**
37
+ * Starts the job.
38
+ *
39
+ * @method
40
+ * @param {...*} [args] Any args passed are forwarded to the callback
41
+ *
42
+ * @returns {undefined}
43
+ * @memberof core/util.Job.prototype
44
+ * @public
45
+ */
36
46
  this.start = function () {
37
47
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
38
48
  args[_key] = arguments[_key];
39
49
  }
40
50
  _this.startAfter.apply(_this, [_this.timeout].concat(args));
41
51
  };
52
+ /**
53
+ * Starts the job in `timeout` milliseconds
54
+ *
55
+ * @method
56
+ * @param {Number} timeout The number of milliseconds to wait before starting the job.
57
+ * This supersedes the timeout set at construction.
58
+ * @param {...*} [args] Any args passed are forwarded to the callback
59
+ *
60
+ * @returns {undefined}
61
+ * @memberof core/util.Job.prototype
62
+ * @public
63
+ */
42
64
  this.startAfter = function (timeout) {
43
65
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
44
66
  args[_key2 - 1] = arguments[_key2];
@@ -49,6 +71,15 @@ var Job = /*#__PURE__*/function () {
49
71
  return _this.run(args);
50
72
  }, timeout);
51
73
  };
74
+ /**
75
+ * Stops the job.
76
+ *
77
+ * @method
78
+ *
79
+ * @returns {undefined}
80
+ * @memberof core/util.Job.prototype
81
+ * @public
82
+ */
52
83
  this.stop = function () {
53
84
  if (_this.id) {
54
85
  if (_this.type === 'idle') {
@@ -61,12 +92,36 @@ var Job = /*#__PURE__*/function () {
61
92
  _this.id = _this.type = null;
62
93
  }
63
94
  };
95
+ /**
96
+ * Executes the job immediately, then prevents any other calls to `throttle()` from running
97
+ * until the `timeout` configured at construction passes.
98
+ *
99
+ * @method
100
+ * @param {...*} args Any args passed are forwarded to the callback
101
+ *
102
+ * @returns {undefined}
103
+ * @memberof core/util.Job.prototype
104
+ * @public
105
+ */
64
106
  this.throttle = function () {
65
107
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
66
108
  args[_key3] = arguments[_key3];
67
109
  }
68
110
  _this.throttleUntil.apply(_this, [_this.timeout].concat(args));
69
111
  };
112
+ /**
113
+ * Executes the job immediately, then prevents any other calls to `throttle()` from running for
114
+ * `timeout` milliseconds.
115
+ *
116
+ * @method
117
+ * @param {Number} timeout The number of milliseconds to wait before allowing the job to
118
+ * be ran again. This supersedes the timeout set at construction.
119
+ * @param {...*} [args] Any args passed are forwarded to the callback
120
+ *
121
+ * @returns {undefined}
122
+ * @memberof core/util.Job.prototype
123
+ * @public
124
+ */
70
125
  this.throttleUntil = function (timeout) {
71
126
  if (!_this.id) {
72
127
  _this.type = 'timeout';
@@ -77,12 +132,35 @@ var Job = /*#__PURE__*/function () {
77
132
  _this.id = setTimeout(_this.stop, timeout);
78
133
  }
79
134
  };
135
+ /**
136
+ * Executes job when the CPU is idle.
137
+ *
138
+ * @method
139
+ * @param {...*} [args] Any args passed are forwarded to the callback
140
+ *
141
+ * @returns {undefined}
142
+ * @memberof core/util.Job.prototype
143
+ * @public
144
+ */
80
145
  this.idle = function () {
81
146
  for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
82
147
  args[_key5] = arguments[_key5];
83
148
  }
84
149
  _this.idleUntil.apply(_this, [null].concat(args));
85
150
  };
151
+ /**
152
+ * Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first.
153
+ *
154
+ * @method
155
+ * @param {Number} timeout The number of milliseconds to wait before executing the
156
+ * job. This guarantees that the job is run, if a positive value
157
+ * is specified.
158
+ * @param {...*} [args] Any args passed are forwarded to the callback
159
+ *
160
+ * @returns {undefined}
161
+ * @memberof core/util.Job.prototype
162
+ * @public
163
+ */
86
164
  this.idleUntil = function (timeout) {
87
165
  for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
88
166
  args[_key6 - 1] = arguments[_key6];
@@ -100,12 +178,33 @@ var Job = /*#__PURE__*/function () {
100
178
  _this.startAfter.apply(_this, [timeout].concat(args));
101
179
  }
102
180
  };
181
+ /**
182
+ * Executes job before the next repaint.
183
+ *
184
+ * @method
185
+ * @param {...*} [args] Any args passed are forwarded to the callback
186
+ *
187
+ * @returns {undefined}
188
+ * @memberof core/util.Job.prototype
189
+ * @public
190
+ */
103
191
  this.startRaf = function () {
104
192
  for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
105
193
  args[_key7] = arguments[_key7];
106
194
  }
107
195
  _this.startRafAfter.apply(_this, [_this.timeout].concat(args));
108
196
  };
197
+ /**
198
+ * Executes job before the next repaint after a given amount of timeout.
199
+ *
200
+ * @method
201
+ * @param {Number} timeout The number of milliseconds to wait before running `requestAnimationFrame`.
202
+ * @param {...*} [args] Any args passed are forwarded to the callback
203
+ *
204
+ * @returns {undefined}
205
+ * @memberof core/util.Job.prototype
206
+ * @public
207
+ */
109
208
  this.startRafAfter = function (timeout) {
110
209
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
111
210
  args[_key8 - 1] = arguments[_key8];
@@ -132,6 +231,26 @@ var Job = /*#__PURE__*/function () {
132
231
  _this.run(args);
133
232
  }
134
233
  };
234
+ /**
235
+ * Starts the job when `promise` resolves.
236
+ *
237
+ * The job execution is tied to the resolution of the last `Promise` passed. Like other methods
238
+ * on `Job`, calling `promise()` again with a new `Promise` will block execution of the job
239
+ * until that new `Promise` resolves. Any previous `Promise`s will still resolve normally but
240
+ * will not trigger job execution.
241
+ *
242
+ * Unlike other methods on `Job`, `promise()` returns a `Promise` which is the result of calling
243
+ * `then()` on the passed `promise`. That `Promise` resolves with either the result of job
244
+ * execution or `undefined` if `Promise` was superseded by a subsequent `Promise` passed as
245
+ * described above.
246
+ *
247
+ * @method
248
+ * @param {Promise} promise The promise that must resolve before the job is executed
249
+ *
250
+ * @returns {Promise}
251
+ * @memberof core/util.Job.prototype
252
+ * @public
253
+ */
135
254
  this.promise = function (promise) {
136
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;
137
256
  _this.type = 'promise';
@@ -152,17 +271,6 @@ var Job = /*#__PURE__*/function () {
152
271
  // don't want to inadvertently apply Job's context on `fn`
153
272
  return this.fn.apply(null, args);
154
273
  }
155
-
156
- /**
157
- * Starts the job.
158
- *
159
- * @method
160
- * @param {...*} [args] Any args passed are forwarded to the callback
161
- *
162
- * @returns {undefined}
163
- * @memberof core/util.Job.prototype
164
- * @public
165
- */
166
274
  }]);
167
275
  return Job;
168
276
  }();