@enact/core 4.9.0 → 4.9.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,12 @@
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.9.1] - 2024-09-09
6
+
7
+ ### Added
8
+
9
+ - `core/util` function `setDefaultProps` to set props that are missing or `undefined` to default values
10
+
5
11
  ## [4.9.0] - 2024-07-17
6
12
 
7
13
  No significant changes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/core",
3
- "version": "4.9.0",
3
+ "version": "4.9.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",
@@ -268,18 +268,6 @@ var parseUserAgentLegacy = function parseUserAgentLegacy(userAgent) {
268
268
  break;
269
269
  }
270
270
  }
271
- if ('webos' === plat.platformName) {
272
- (0, _deprecate["default"])({
273
- name: plat.platformName,
274
- message: 'Refer `@enact/webos`\'s `platform` for webOS specific information.',
275
- until: '5.0.0'
276
- });
277
- } else if (!['chrome', 'safari', 'firefox'].includes(plat.platformName)) {
278
- (0, _deprecate["default"])({
279
- name: plat.platformName,
280
- until: '5.0.0'
281
- });
282
- }
283
271
  return plat;
284
272
  };
285
273
 
@@ -468,6 +456,13 @@ var platform = exports.platform = {};
468
456
  replacedBy: 'touchScreen'
469
457
  });
470
458
  }
459
+ if (name === 'webos') {
460
+ (0, _deprecate["default"])({
461
+ name: name,
462
+ message: 'Refer `@enact/webos`\'s `platform` for webOS specific information.',
463
+ until: '5.0.0'
464
+ });
465
+ }
471
466
  var p = detect();
472
467
  return p[name];
473
468
  }
@@ -212,6 +212,29 @@ describe('util', function () {
212
212
  expect(expected).toEqual(actual);
213
213
  });
214
214
  });
215
+ describe('setDefaultProps', function () {
216
+ var props = {
217
+ // eslint-disable-next-line no-undefined
218
+ direction: undefined,
219
+ index: 0,
220
+ size: 'small'
221
+ };
222
+ var defaultProps = {
223
+ direction: 'below',
224
+ selected: true,
225
+ size: 'large'
226
+ };
227
+ test('should set props that are missing or `undefined` to default values', function () {
228
+ var expected = {
229
+ direction: 'below',
230
+ index: 0,
231
+ selected: true,
232
+ size: 'small'
233
+ };
234
+ var actual = (0, _util.setDefaultProps)(props, defaultProps);
235
+ expect(expected).toEqual(actual);
236
+ });
237
+ });
215
238
  describe('shallowEqual', function () {
216
239
  var child = {
217
240
  name: 'child'
package/util/util.d.ts CHANGED
@@ -154,6 +154,10 @@ export function mapAndFilterChildren(
154
154
  callback: Function,
155
155
  filter?: Function,
156
156
  ): any;
157
+ /**
158
+ * Sets props that are missing or `undefined` to default values
159
+ */
160
+ export function setDefaultProps(props: Obejct, defaultProps: Obejct): object;
157
161
  /**
158
162
  * Performs shallow comparison for given objects.
159
163
  */
package/util/util.js CHANGED
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "Job", {
9
9
  return _Job["default"];
10
10
  }
11
11
  });
12
- exports.shallowEqual = exports.perfNow = exports.mergeClassNameMaps = exports.memoize = exports.mapAndFilterChildren = exports.isRenderable = exports.extractAriaProps = exports.coerceFunction = exports.coerceArray = exports.clamp = exports.cap = void 0;
12
+ exports.shallowEqual = exports.setDefaultProps = exports.perfNow = exports.mergeClassNameMaps = exports.memoize = exports.mapAndFilterChildren = exports.isRenderable = exports.extractAriaProps = exports.coerceFunction = exports.coerceArray = exports.clamp = exports.cap = void 0;
13
13
  var _always = _interopRequireDefault(require("ramda/src/always"));
14
14
  var _is = _interopRequireDefault(require("ramda/src/is"));
15
15
  var _unless = _interopRequireDefault(require("ramda/src/unless"));
@@ -280,6 +280,29 @@ var mapAndFilterChildren = exports.mapAndFilterChildren = function mapAndFilterC
280
280
  }
281
281
  };
282
282
 
283
+ /**
284
+ * Sets props that are missing or `undefined` to default values
285
+ *
286
+ * @function
287
+ * @param {Obejct} props Props object
288
+ * @param {Obejct} defaultProps Default value object
289
+ *
290
+ * @returns {Object} Props with default values
291
+ * @memberof core/util
292
+ * @public
293
+ */
294
+ var setDefaultProps = exports.setDefaultProps = function setDefaultProps(props) {
295
+ var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
296
+ var result = Object.assign({}, props);
297
+ for (var prop in defaultProps) {
298
+ // eslint-disable-next-line no-undefined
299
+ if (props[prop] === undefined) {
300
+ result[prop] = defaultProps[prop];
301
+ }
302
+ }
303
+ return result;
304
+ };
305
+
283
306
  /**
284
307
  * Performs shallow comparison for given objects.
285
308
  *