@enact/core 5.5.1 → 5.5.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 +10 -4
- package/kind/functionalKind.js +7 -31
- package/kind/kind.js +6 -30
- package/kind/styles.js +1 -6
- package/kind/util.js +18 -1
- package/package.json +4 -9
- package/usePublicClassNames/tests/usePublicClassNames-specs.js +10 -0
- package/usePublicClassNames/usePublicClassNames.js +4 -12
- package/util/tests/util-specs.js +94 -0
- package/util/util.d.ts +18 -0
- package/util/util.js +53 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,18 +2,24 @@
|
|
|
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
|
-
## [5.5.
|
|
5
|
+
## [5.5.2] - 2026-07-08
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Added
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- `core/util` functions `applyDefaultProps` and `normalizePublicClassNames`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `core/kind` `inline` handler injection to use a props snapshot so each handler receives the same base props
|
|
12
14
|
|
|
13
15
|
## [5.5.1] - 2026-06-01
|
|
14
16
|
|
|
15
17
|
No significant changes.
|
|
16
18
|
|
|
19
|
+
## [5.4.4] - 2026-05-22
|
|
20
|
+
|
|
21
|
+
No significant changes.
|
|
22
|
+
|
|
17
23
|
## [5.5.0] - 2026-05-08
|
|
18
24
|
|
|
19
25
|
### Added
|
package/kind/functionalKind.js
CHANGED
|
@@ -9,6 +9,7 @@ var _useHandlers = _interopRequireDefault(require("../useHandlers"));
|
|
|
9
9
|
var _util = require("../util");
|
|
10
10
|
var _computed = _interopRequireDefault(require("./computed"));
|
|
11
11
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
12
|
+
var _util2 = require("./util");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -147,8 +148,11 @@ var functionalKind = exports.functionalKind = function functionalKind(config) {
|
|
|
147
148
|
if (renderComputed) props = renderComputed(props, context);
|
|
148
149
|
return useRender(props, context); // eslint-disable-line react-hooks/rules-of-hooks
|
|
149
150
|
};
|
|
151
|
+
var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
|
|
152
|
+
var handlerKeys = handlers ? Object.keys(handlers) : null;
|
|
150
153
|
var _Component = function Component(props) {
|
|
151
154
|
// Hooks must always be called unconditionally and in the same order.
|
|
155
|
+
// useContext only accepts Context and never suspends (unlike use(), which can suspend on Promises and break SSR).
|
|
152
156
|
var ctx = (0, _react.useContext)(contextType);
|
|
153
157
|
var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
|
|
154
158
|
|
|
@@ -157,14 +161,7 @@ var functionalKind = exports.functionalKind = function functionalKind(config) {
|
|
|
157
161
|
|
|
158
162
|
// Apply defaultProps manually so functional components
|
|
159
163
|
// receive defaults even when React's own defaultProps is set.
|
|
160
|
-
|
|
161
|
-
Object.keys(defaultProps).forEach(function (key) {
|
|
162
|
-
// eslint-disable-next-line no-undefined
|
|
163
|
-
if (merged[key] === undefined) {
|
|
164
|
-
merged[key] = defaultProps[key];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
164
|
+
(0, _util.applyDefaultProps)(merged, defaultProps, defaultPropKeys);
|
|
168
165
|
(0, _util.checkPropTypes)(_Component, merged);
|
|
169
166
|
return renderKind(merged, ctx);
|
|
170
167
|
};
|
|
@@ -178,30 +175,9 @@ var functionalKind = exports.functionalKind = function functionalKind(config) {
|
|
|
178
175
|
// ── inline ──────────────────────────────────────────────────────────────
|
|
179
176
|
// A synchronous, hook-free path for calling the component logic outside
|
|
180
177
|
// of the React render cycle (e.g. in tests or server-side utilities).
|
|
181
|
-
var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
|
|
182
|
-
var handlerKeys = handlers ? Object.keys(handlers) : null;
|
|
183
178
|
_Component.inline = function (props, context) {
|
|
184
|
-
var updated = _objectSpread({}, props);
|
|
185
|
-
|
|
186
|
-
defaultPropKeys.forEach(function (key) {
|
|
187
|
-
// eslint-disable-next-line no-undefined
|
|
188
|
-
if (props == null || props[key] === undefined) {
|
|
189
|
-
updated[key] = defaultProps[key];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (handlerKeys !== null && handlerKeys !== void 0 && handlerKeys.length) {
|
|
194
|
-
// Snapshot `updated` before injecting handlers so every handler
|
|
195
|
-
// receives the same base props (no cross-contamination).
|
|
196
|
-
var snapshot = _objectSpread({}, updated);
|
|
197
|
-
updated = handlerKeys.reduce(function (_props, key) {
|
|
198
|
-
_props[key] = function (ev) {
|
|
199
|
-
return handlers[key](ev, snapshot, context);
|
|
200
|
-
};
|
|
201
|
-
return _props;
|
|
202
|
-
}, updated);
|
|
203
|
-
}
|
|
204
|
-
return renderKind(updated, context);
|
|
179
|
+
var updated = (0, _util.applyDefaultProps)(_objectSpread({}, props), defaultProps, defaultPropKeys);
|
|
180
|
+
return renderKind((0, _util2.bindInlineHandlers)(updated, handlers, handlerKeys, context), context);
|
|
205
181
|
};
|
|
206
182
|
return _Component;
|
|
207
183
|
};
|
package/kind/kind.js
CHANGED
|
@@ -10,6 +10,7 @@ var _Handlers = _interopRequireDefault(require("../useHandlers/Handlers"));
|
|
|
10
10
|
var _util = require("../util");
|
|
11
11
|
var _computed = _interopRequireDefault(require("./computed"));
|
|
12
12
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
13
|
+
var _util2 = require("./util");
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
15
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
16
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
@@ -163,6 +164,8 @@ var kind = exports.kind = function kind(config) {
|
|
|
163
164
|
if (renderComputed) props = renderComputed(props, context);
|
|
164
165
|
return render(props, context);
|
|
165
166
|
};
|
|
167
|
+
var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
|
|
168
|
+
var handlerKeys = handlers ? Object.keys(handlers) : null;
|
|
166
169
|
var _Component;
|
|
167
170
|
|
|
168
171
|
// In 4.x, this branch will become the only supported version and the class branch will be
|
|
@@ -172,14 +175,7 @@ var kind = exports.kind = function kind(config) {
|
|
|
172
175
|
var ctx = (0, _react.use)(contextType);
|
|
173
176
|
var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
|
|
174
177
|
var merged = _objectSpread(_objectSpread({}, props), boundHandlers);
|
|
175
|
-
|
|
176
|
-
Object.keys(defaultProps).forEach(function (key) {
|
|
177
|
-
// eslint-disable-next-line no-undefined
|
|
178
|
-
if (merged[key] === undefined) {
|
|
179
|
-
merged[key] = defaultProps[key];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
178
|
+
(0, _util.applyDefaultProps)(merged, defaultProps, defaultPropKeys);
|
|
183
179
|
(0, _util.checkPropTypes)(_Component, merged);
|
|
184
180
|
return renderKind(merged, ctx);
|
|
185
181
|
};
|
|
@@ -216,29 +212,9 @@ var kind = exports.kind = function kind(config) {
|
|
|
216
212
|
|
|
217
213
|
// Decorate the Component with the computed property object in DEV for easier testability
|
|
218
214
|
if (process.env.NODE_ENV !== "production" && cfgComputed) _Component.computed = cfgComputed;
|
|
219
|
-
var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
|
|
220
|
-
var handlerKeys = handlers ? Object.keys(handlers) : null;
|
|
221
215
|
_Component.inline = function (props, context) {
|
|
222
|
-
var updated = _objectSpread({}, props);
|
|
223
|
-
|
|
224
|
-
defaultPropKeys.forEach(function (key) {
|
|
225
|
-
// eslint-disable-next-line no-undefined
|
|
226
|
-
if (props == null || props[key] === undefined) {
|
|
227
|
-
updated[key] = defaultProps[key];
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (handlerKeys && handlerKeys.length > 0) {
|
|
232
|
-
// generate a handler with a clone of updated to ensure each handler receives the same
|
|
233
|
-
// props without the kind.handlers injected.
|
|
234
|
-
updated = handlerKeys.reduce(function (_props, key) {
|
|
235
|
-
_props[key] = function (ev) {
|
|
236
|
-
return handlers[key](ev, updated, context);
|
|
237
|
-
};
|
|
238
|
-
return _props;
|
|
239
|
-
}, _objectSpread({}, updated));
|
|
240
|
-
}
|
|
241
|
-
return renderKind(updated, context);
|
|
216
|
+
var updated = (0, _util.applyDefaultProps)(_objectSpread({}, props), defaultProps, defaultPropKeys);
|
|
217
|
+
return renderKind((0, _util2.bindInlineHandlers)(updated, handlers, handlerKeys, context), context);
|
|
242
218
|
};
|
|
243
219
|
return _Component;
|
|
244
220
|
};
|
package/kind/styles.js
CHANGED
|
@@ -52,12 +52,7 @@ var styles = exports.styles = function styles(cfg, optProps) {
|
|
|
52
52
|
_cfg$prop = cfg.prop,
|
|
53
53
|
prop = _cfg$prop === void 0 ? 'className' : _cfg$prop,
|
|
54
54
|
style = cfg.style;
|
|
55
|
-
var allowedClassNames = cfg.publicClassNames;
|
|
56
|
-
if (configCss && allowedClassNames === true) {
|
|
57
|
-
allowedClassNames = Object.keys(configCss);
|
|
58
|
-
} else if (typeof allowedClassNames === 'string') {
|
|
59
|
-
allowedClassNames = allowedClassNames.split(/\s+/);
|
|
60
|
-
}
|
|
55
|
+
var allowedClassNames = (0, _util.normalizePublicClassNames)(cfg.publicClassNames, configCss);
|
|
61
56
|
var renderStyles = function renderStyles(props) {
|
|
62
57
|
var css = configCss;
|
|
63
58
|
if (style) {
|
package/kind/util.js
CHANGED
|
@@ -3,7 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.addInternalProp = void 0;
|
|
6
|
+
exports.bindInlineHandlers = exports.addInternalProp = void 0;
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
var bindInlineHandlers = exports.bindInlineHandlers = function bindInlineHandlers(props, handlers, handlerKeys, context) {
|
|
13
|
+
if (!(handlerKeys !== null && handlerKeys !== void 0 && handlerKeys.length)) {
|
|
14
|
+
return props;
|
|
15
|
+
}
|
|
16
|
+
var snapshot = _objectSpread({}, props);
|
|
17
|
+
return handlerKeys.reduce(function (_props, key) {
|
|
18
|
+
_props[key] = function (ev) {
|
|
19
|
+
return handlers[key](ev, snapshot, context);
|
|
20
|
+
};
|
|
21
|
+
return _props;
|
|
22
|
+
}, props);
|
|
23
|
+
};
|
|
7
24
|
var addInternalProp = exports.addInternalProp = function addInternalProp(props, name, value) {
|
|
8
25
|
Object.defineProperty(props, name, {
|
|
9
26
|
value: value,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/core",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.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",
|
|
@@ -36,14 +36,9 @@
|
|
|
36
36
|
"invariant": "^2.2.4",
|
|
37
37
|
"prop-types": "^15.8.1",
|
|
38
38
|
"ramda": "^0.32.0",
|
|
39
|
-
"react": "^19.2.
|
|
40
|
-
"react-dom": "^19.2.
|
|
41
|
-
"react-is": "^19.2.
|
|
39
|
+
"react": "^19.2.7",
|
|
40
|
+
"react-dom": "^19.2.7",
|
|
41
|
+
"react-is": "^19.2.7",
|
|
42
42
|
"warning": "^4.0.3"
|
|
43
|
-
},
|
|
44
|
-
"overrides": {
|
|
45
|
-
"prop-types": {
|
|
46
|
-
"react-is": "^19.2.6"
|
|
47
|
-
}
|
|
48
43
|
}
|
|
49
44
|
}
|
|
@@ -63,4 +63,14 @@ describe('usePublicClassNames', function () {
|
|
|
63
63
|
expect(result.current.a).toBe(expected.a);
|
|
64
64
|
expect(result.current.b).toBe(expected.b);
|
|
65
65
|
});
|
|
66
|
+
test('should return `componentCss` when `publicClassNames` is not set', function () {
|
|
67
|
+
var _renderHook4 = (0, _react.renderHook)(function () {
|
|
68
|
+
return (0, _usePublicClassNames["default"])({
|
|
69
|
+
componentCss: componentCss,
|
|
70
|
+
customCss: customCss
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
result = _renderHook4.result;
|
|
74
|
+
expect(result.current).toBe(componentCss);
|
|
75
|
+
});
|
|
66
76
|
});
|
|
@@ -23,21 +23,13 @@ function usePublicClassNames(_ref) {
|
|
|
23
23
|
var componentCss = _ref.componentCss,
|
|
24
24
|
customCss = _ref.customCss,
|
|
25
25
|
publicClassNames = _ref.publicClassNames;
|
|
26
|
-
var allowedClassNames = publicClassNames;
|
|
27
|
-
var mergedCss = componentCss;
|
|
28
26
|
if (!componentCss || !customCss) {
|
|
29
|
-
return
|
|
27
|
+
return componentCss;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
allowedClassNames = Object.keys(componentCss);
|
|
33
|
-
} else if (typeof allowedClassNames === 'string') {
|
|
34
|
-
allowedClassNames = allowedClassNames.split(/\s+/);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// if the config includes a css map, merge them together now
|
|
29
|
+
var allowedClassNames = (0, _util.normalizePublicClassNames)(publicClassNames, componentCss);
|
|
38
30
|
if (allowedClassNames) {
|
|
39
|
-
|
|
31
|
+
return (0, _util.mergeClassNameMaps)(componentCss, customCss, allowedClassNames);
|
|
40
32
|
}
|
|
41
|
-
return
|
|
33
|
+
return componentCss;
|
|
42
34
|
}
|
|
43
35
|
var _default = exports["default"] = usePublicClassNames;
|
package/util/tests/util-specs.js
CHANGED
|
@@ -277,6 +277,79 @@ describe('util', function () {
|
|
|
277
277
|
expect(expected).toEqual(actual);
|
|
278
278
|
});
|
|
279
279
|
});
|
|
280
|
+
describe('normalizePublicClassNames', function () {
|
|
281
|
+
var css = {
|
|
282
|
+
a: 'a-class',
|
|
283
|
+
b: 'b-class'
|
|
284
|
+
};
|
|
285
|
+
test('should return all css keys when publicClassNames is true', function () {
|
|
286
|
+
expect((0, _util.normalizePublicClassNames)(true, css)).toEqual(['a', 'b']);
|
|
287
|
+
});
|
|
288
|
+
test('should split a string publicClassNames value', function () {
|
|
289
|
+
expect((0, _util.normalizePublicClassNames)('a b', css)).toEqual(['a', 'b']);
|
|
290
|
+
});
|
|
291
|
+
test('should return `true` unchanged when css is not provided', function () {
|
|
292
|
+
expect((0, _util.normalizePublicClassNames)(true)).toBe(true);
|
|
293
|
+
});
|
|
294
|
+
test('should return `false` unchanged', function () {
|
|
295
|
+
expect((0, _util.normalizePublicClassNames)(false, css)).toBe(false);
|
|
296
|
+
});
|
|
297
|
+
test('should return `undefined` unchanged', function () {
|
|
298
|
+
// eslint-disable-next-line no-undefined
|
|
299
|
+
expect((0, _util.normalizePublicClassNames)(undefined, css)).toBe(undefined);
|
|
300
|
+
});
|
|
301
|
+
test('should return an array value unchanged', function () {
|
|
302
|
+
var allowed = ['a', 'b'];
|
|
303
|
+
expect((0, _util.normalizePublicClassNames)(allowed, css)).toBe(allowed);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
describe('applyDefaultProps', function () {
|
|
307
|
+
test('should return target unchanged when keys are not provided', function () {
|
|
308
|
+
var target = {
|
|
309
|
+
size: 'small'
|
|
310
|
+
};
|
|
311
|
+
expect((0, _util.applyDefaultProps)(target, {
|
|
312
|
+
size: 'large'
|
|
313
|
+
}, null)).toBe(target);
|
|
314
|
+
expect(target).toEqual({
|
|
315
|
+
size: 'small'
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
test('should apply defaults for keys that are `undefined`', function () {
|
|
319
|
+
// eslint-disable-next-line no-undefined
|
|
320
|
+
var target = {
|
|
321
|
+
size: undefined
|
|
322
|
+
};
|
|
323
|
+
(0, _util.applyDefaultProps)(target, {
|
|
324
|
+
size: 'large'
|
|
325
|
+
}, ['size']);
|
|
326
|
+
expect(target.size).toBe('large');
|
|
327
|
+
});
|
|
328
|
+
test('should not overwrite a key that is already set', function () {
|
|
329
|
+
var target = {
|
|
330
|
+
size: 'small'
|
|
331
|
+
};
|
|
332
|
+
(0, _util.applyDefaultProps)(target, {
|
|
333
|
+
size: 'large'
|
|
334
|
+
}, ['size']);
|
|
335
|
+
expect(target.size).toBe('small');
|
|
336
|
+
});
|
|
337
|
+
test('should preserve falsy-but-defined values', function () {
|
|
338
|
+
var target = {
|
|
339
|
+
count: 0,
|
|
340
|
+
label: '',
|
|
341
|
+
flag: false
|
|
342
|
+
};
|
|
343
|
+
(0, _util.applyDefaultProps)(target, {
|
|
344
|
+
count: 5,
|
|
345
|
+
label: 'default',
|
|
346
|
+
flag: true
|
|
347
|
+
}, ['count', 'label', 'flag']);
|
|
348
|
+
expect(target.count).toBe(0);
|
|
349
|
+
expect(target.label).toBe('');
|
|
350
|
+
expect(target.flag).toBe(false);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
280
353
|
describe('setDefaultProps', function () {
|
|
281
354
|
var props = {
|
|
282
355
|
// eslint-disable-next-line no-undefined
|
|
@@ -378,5 +451,26 @@ describe('util', function () {
|
|
|
378
451
|
});
|
|
379
452
|
expect(result.current).toBe(42);
|
|
380
453
|
});
|
|
454
|
+
test('should keep prior value when value changes then stays the same', function () {
|
|
455
|
+
var value = 'a';
|
|
456
|
+
var _renderHook5 = (0, _react.renderHook)(function () {
|
|
457
|
+
return (0, _util.usePrevious)(value);
|
|
458
|
+
}),
|
|
459
|
+
result = _renderHook5.result,
|
|
460
|
+
rerender = _renderHook5.rerender;
|
|
461
|
+
|
|
462
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
463
|
+
(0, _react.act)(function () {
|
|
464
|
+
value = 'b';
|
|
465
|
+
rerender();
|
|
466
|
+
});
|
|
467
|
+
expect(result.current).toBe('a');
|
|
468
|
+
|
|
469
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
470
|
+
(0, _react.act)(function () {
|
|
471
|
+
rerender();
|
|
472
|
+
});
|
|
473
|
+
expect(result.current).toBe('a');
|
|
474
|
+
});
|
|
381
475
|
});
|
|
382
476
|
});
|
package/util/util.d.ts
CHANGED
|
@@ -137,6 +137,24 @@ export function mergeClassNameMaps(
|
|
|
137
137
|
additiveMap: object,
|
|
138
138
|
allowedClassNames?: string[],
|
|
139
139
|
): object;
|
|
140
|
+
/**
|
|
141
|
+
* Normalizes a `publicClassNames` config value into an array of logical class names.
|
|
142
|
+
*/
|
|
143
|
+
export function normalizePublicClassNames(
|
|
144
|
+
publicClassNames?: boolean | string | string[],
|
|
145
|
+
css?: object,
|
|
146
|
+
): string[] | boolean | string | void;
|
|
147
|
+
/**
|
|
148
|
+
* Applies default values for keys that are `undefined` on `target` .
|
|
149
|
+
*
|
|
150
|
+
* When `keys` is provided, only those keys are considered. This avoids
|
|
151
|
+
`Object.keys` on the hot path (e.g. `core/kind` render).
|
|
152
|
+
*/
|
|
153
|
+
export function applyDefaultProps(
|
|
154
|
+
target: object,
|
|
155
|
+
defaultProps: object,
|
|
156
|
+
keys?: string[],
|
|
157
|
+
): object;
|
|
140
158
|
/**
|
|
141
159
|
* Creates a function that memoizes the result of `fn` .
|
|
142
160
|
*
|
package/util/util.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "Job", {
|
|
|
9
9
|
return _Job["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
exports.usePrevious = exports.shallowEqual = exports.setDefaultProps = exports.perfNow = exports.mergeClassNameMaps = exports.memoize = exports.mapAndFilterChildren = exports.isRenderable = exports.extractAriaProps = exports.coerceFunction = exports.coerceArray = exports.clamp = exports.checkPropTypes = exports.cap = void 0;
|
|
12
|
+
exports.usePrevious = exports.shallowEqual = exports.setDefaultProps = exports.perfNow = exports.normalizePublicClassNames = exports.mergeClassNameMaps = exports.memoize = exports.mapAndFilterChildren = exports.isRenderable = exports.extractAriaProps = exports.coerceFunction = exports.coerceArray = exports.clamp = exports.checkPropTypes = exports.cap = exports.applyDefaultProps = void 0;
|
|
13
13
|
var _propTypes = require("prop-types");
|
|
14
14
|
var _always = _interopRequireDefault(require("ramda/src/always"));
|
|
15
15
|
var _is = _interopRequireDefault(require("ramda/src/is"));
|
|
@@ -38,6 +38,8 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /**
|
|
|
38
38
|
* @exports Job
|
|
39
39
|
* @exports memoize
|
|
40
40
|
* @exports mergeClassNameMaps
|
|
41
|
+
* @exports normalizePublicClassNames
|
|
42
|
+
* @exports applyDefaultProps
|
|
41
43
|
* @exports perfNow
|
|
42
44
|
* @exports mapAndFilterChildren
|
|
43
45
|
* @exports shallowEqual
|
|
@@ -223,6 +225,55 @@ var mergeClassNameMaps = exports.mergeClassNameMaps = function mergeClassNameMap
|
|
|
223
225
|
return css;
|
|
224
226
|
};
|
|
225
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Normalizes a `publicClassNames` config value into an array of logical class names.
|
|
230
|
+
*
|
|
231
|
+
* @function
|
|
232
|
+
* @param {Boolean|String|String[]} [publicClassNames] The public class names config
|
|
233
|
+
* @param {Object} [css] Component CSS map used when
|
|
234
|
+
* `publicClassNames` is `true`
|
|
235
|
+
* @returns {String[]|Boolean|String|undefined} Normalized class name list, or the
|
|
236
|
+
* original value when no normalization applies
|
|
237
|
+
* @memberof core/util
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
var normalizePublicClassNames = exports.normalizePublicClassNames = function normalizePublicClassNames(publicClassNames, css) {
|
|
241
|
+
var allowedClassNames = publicClassNames;
|
|
242
|
+
if (css && allowedClassNames === true) {
|
|
243
|
+
allowedClassNames = Object.keys(css);
|
|
244
|
+
} else if (typeof allowedClassNames === 'string') {
|
|
245
|
+
allowedClassNames = allowedClassNames.split(/\s+/);
|
|
246
|
+
}
|
|
247
|
+
return allowedClassNames;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Applies default values for keys that are `undefined` on `target`.
|
|
252
|
+
*
|
|
253
|
+
* When `keys` is provided, only those keys are considered. This avoids
|
|
254
|
+
* `Object.keys` on the hot path (e.g. `core/kind` render).
|
|
255
|
+
*
|
|
256
|
+
* @function
|
|
257
|
+
* @param {Object} target Props object to update in place
|
|
258
|
+
* @param {Object} defaultProps Default value object
|
|
259
|
+
* @param {String[]} [keys] Optional precomputed key list
|
|
260
|
+
*
|
|
261
|
+
* @returns {Object} The updated `target`
|
|
262
|
+
* @memberof core/util
|
|
263
|
+
* @public
|
|
264
|
+
*/
|
|
265
|
+
var applyDefaultProps = exports.applyDefaultProps = function applyDefaultProps(target, defaultProps, keys) {
|
|
266
|
+
if (keys !== null && keys !== void 0 && keys.length) {
|
|
267
|
+
keys.forEach(function (key) {
|
|
268
|
+
// eslint-disable-next-line no-undefined
|
|
269
|
+
if (target[key] === undefined) {
|
|
270
|
+
target[key] = defaultProps[key];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return target;
|
|
275
|
+
};
|
|
276
|
+
|
|
226
277
|
/**
|
|
227
278
|
* Creates a function that memoizes the result of `fn`.
|
|
228
279
|
*
|
|
@@ -299,14 +350,7 @@ var mapAndFilterChildren = exports.mapAndFilterChildren = function mapAndFilterC
|
|
|
299
350
|
*/
|
|
300
351
|
var setDefaultProps = exports.setDefaultProps = function setDefaultProps(props) {
|
|
301
352
|
var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
302
|
-
|
|
303
|
-
for (var prop in defaultProps) {
|
|
304
|
-
// eslint-disable-next-line no-undefined
|
|
305
|
-
if (props[prop] === undefined) {
|
|
306
|
-
result[prop] = defaultProps[prop];
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return result;
|
|
353
|
+
return applyDefaultProps(Object.assign({}, props), defaultProps, Object.keys(defaultProps));
|
|
310
354
|
};
|
|
311
355
|
|
|
312
356
|
/**
|