@enact/core 5.4.3 → 5.5.0
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 -0
- package/internal/prop-types/tests/prop-types-specs.js +18 -18
- package/kind/functionalKind.js +208 -0
- package/kind/index.js +21 -0
- package/kind/kind.js +30 -14
- package/kind/package.json +1 -1
- package/kind/tests/functionalKind-specs.js +244 -0
- package/kind/tests/kind-specs.js +87 -9
- package/package.json +9 -4
- package/useClass/useClass.js +12 -3
- package/useHandlers/tests/useHandlers-specs.js +6 -3
- package/util/tests/util-specs.js +129 -4
- package/util/util.d.ts +14 -0
- package/util/util.js +69 -3
- /package/kind/{kind.d.ts → index.d.ts} +0 -0
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
|
+
## [5.5.0] - 2026-05-08
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `core/util` function `checkPropTypes` to check the prop types of a component
|
|
10
|
+
|
|
5
11
|
## [5.4.3] - 2026-02-26
|
|
6
12
|
|
|
7
13
|
No significant changes.
|
|
@@ -12,6 +18,10 @@ No significant changes.
|
|
|
12
18
|
|
|
13
19
|
- `core/platform` to support `safari` 16.6, `chrome` 119, and `firefox` 128 or later
|
|
14
20
|
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `core/kind` to properly apply `defaultProps` to functional components
|
|
24
|
+
|
|
15
25
|
## [5.4.1] - 2025-12-30
|
|
16
26
|
|
|
17
27
|
No significant changes.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
4
|
var _react2 = require("react");
|
|
5
5
|
var _propTypes = _interopRequireDefault(require("../prop-types"));
|
|
6
|
+
var _util = require("../../../util");
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
9
|
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
|
|
@@ -18,28 +19,24 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
18
19
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
19
20
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
20
21
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
21
|
-
describe
|
|
22
|
+
describe('prop-types', function () {
|
|
22
23
|
var DummyElement = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
23
24
|
var DummyRenderable = function DummyRenderable() {
|
|
24
25
|
return DummyElement;
|
|
25
26
|
};
|
|
26
27
|
var dummyString = 'Some String';
|
|
27
28
|
var TestComponent = /*#__PURE__*/function (_Component) {
|
|
28
|
-
function TestComponent() {
|
|
29
|
+
function TestComponent(props) {
|
|
30
|
+
var _this;
|
|
29
31
|
_classCallCheck(this, TestComponent);
|
|
30
|
-
|
|
32
|
+
_this = _callSuper(this, TestComponent, [props]);
|
|
33
|
+
(0, _util.checkPropTypes)(_this, props);
|
|
34
|
+
return _this;
|
|
31
35
|
}
|
|
32
36
|
_inherits(TestComponent, _Component);
|
|
33
37
|
return _createClass(TestComponent, [{
|
|
34
38
|
key: "render",
|
|
35
39
|
value: function render() {
|
|
36
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
37
|
-
rest = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
38
|
-
delete rest.typeComponent;
|
|
39
|
-
delete rest.typeComponentOverride;
|
|
40
|
-
delete rest.typeRef;
|
|
41
|
-
delete rest.typeRenderable;
|
|
42
|
-
delete rest.typeRenderableOverride;
|
|
43
40
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
44
41
|
children: "Test"
|
|
45
42
|
});
|
|
@@ -167,16 +164,19 @@ describe.skip('prop-types', function () {
|
|
|
167
164
|
});
|
|
168
165
|
describe('isRequired', function () {
|
|
169
166
|
var RequiredComponent = /*#__PURE__*/function (_Component2) {
|
|
170
|
-
function RequiredComponent() {
|
|
167
|
+
function RequiredComponent(props) {
|
|
168
|
+
var _this2;
|
|
171
169
|
_classCallCheck(this, RequiredComponent);
|
|
172
|
-
|
|
170
|
+
_this2 = _callSuper(this, RequiredComponent, [props]);
|
|
171
|
+
(0, _util.checkPropTypes)(_this2, props);
|
|
172
|
+
return _this2;
|
|
173
173
|
}
|
|
174
174
|
_inherits(RequiredComponent, _Component2);
|
|
175
175
|
return _createClass(RequiredComponent, [{
|
|
176
176
|
key: "render",
|
|
177
177
|
value: function render() {
|
|
178
|
-
var
|
|
179
|
-
rest = Object.assign({}, (_objectDestructuringEmpty(
|
|
178
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
179
|
+
rest = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
180
180
|
delete rest.typeRequired;
|
|
181
181
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
182
182
|
children: "Test"
|
|
@@ -211,8 +211,8 @@ describe.skip('prop-types', function () {
|
|
|
211
211
|
return _createClass(DeprecatedComponent, [{
|
|
212
212
|
key: "render",
|
|
213
213
|
value: function render() {
|
|
214
|
-
var
|
|
215
|
-
rest = Object.assign({}, (_objectDestructuringEmpty(
|
|
214
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
215
|
+
rest = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
216
216
|
delete rest.typeDeprecated;
|
|
217
217
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
218
218
|
children: "Test"
|
|
@@ -239,8 +239,8 @@ describe.skip('prop-types', function () {
|
|
|
239
239
|
return _createClass(DeprecatedComponent, [{
|
|
240
240
|
key: "render",
|
|
241
241
|
value: function render() {
|
|
242
|
-
var
|
|
243
|
-
rest = Object.assign({}, (_objectDestructuringEmpty(
|
|
242
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
243
|
+
rest = Object.assign({}, (_objectDestructuringEmpty(_ref3), _ref3));
|
|
244
244
|
delete rest.typeDeprecated;
|
|
245
245
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
246
246
|
children: "Test"
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.functionalKind = exports["default"] = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _useHandlers = _interopRequireDefault(require("../useHandlers"));
|
|
9
|
+
var _util = require("../util");
|
|
10
|
+
var _computed = _interopRequireDefault(require("./computed"));
|
|
11
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
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
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
17
|
+
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); } /*
|
|
18
|
+
* Provides the {@link core/kind.functionalKind} method to create components
|
|
19
|
+
*
|
|
20
|
+
* @module core/kind
|
|
21
|
+
* @exports functionalKind
|
|
22
|
+
*/
|
|
23
|
+
// Fallback context when none is specified.
|
|
24
|
+
var NoContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* @callback RenderFunction
|
|
28
|
+
* @memberof core/kind
|
|
29
|
+
* @param {Object<string, any>} props
|
|
30
|
+
* @param {Object<string, any>} context
|
|
31
|
+
* @returns React.Element|null
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* @callback ComputedPropFunction
|
|
36
|
+
* @memberof core/kind
|
|
37
|
+
* @param {Object<string, any>} props
|
|
38
|
+
* @param {Object<string, any>} context
|
|
39
|
+
* @returns any
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* @callback HandlerFunction
|
|
44
|
+
* @memberof core/kind
|
|
45
|
+
* @param {any} event
|
|
46
|
+
* @param {Object<string, any>} props
|
|
47
|
+
* @param {Object<string, any>} context
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Configuration for CSS class name mapping
|
|
52
|
+
*
|
|
53
|
+
* @typedef {Object} StylesBlock
|
|
54
|
+
* @memberof core/kind
|
|
55
|
+
* @property {Object.<string, string>} css The CSS of the component
|
|
56
|
+
* @property {String} [className] The className of the component
|
|
57
|
+
* @property {Boolean|String|String[]} [publicClassNames] Specifies which class names are overridable.
|
|
58
|
+
* If this value is `true`, all the class names of the component CSS will become public.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* @typedef {Object} KindConfig
|
|
63
|
+
* @memberof core/kind
|
|
64
|
+
* @property {String} [name] The name of the component
|
|
65
|
+
* @property {Object.<string, Function>} [propTypes] Specifies expected props
|
|
66
|
+
* @property {Object.<string, any>} [defaultProps] Sets the default props
|
|
67
|
+
* @property {Object} [contextType] Specifies context type
|
|
68
|
+
* @property {StylesBlock} [styles] Configures styles
|
|
69
|
+
* @property {Object.<string, HandlerFunction>} [handlers] Adds event handlers
|
|
70
|
+
* @property {Object.<string, ComputedPropFunction>} [computed] Adds computed properties
|
|
71
|
+
* @property {RenderFunction} useRender The useRender function
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* Creates a new component with some helpful declarative syntactic sugar.
|
|
76
|
+
*
|
|
77
|
+
* Example:
|
|
78
|
+
* ```
|
|
79
|
+
* import css from './Button.module.less';
|
|
80
|
+
* // Return a functional component
|
|
81
|
+
* const Button = functionalKind({
|
|
82
|
+
* name: 'Button',
|
|
83
|
+
* // expect color and onClick properties but neither required
|
|
84
|
+
* propTypes: {
|
|
85
|
+
* color: PropTypes.string
|
|
86
|
+
* },
|
|
87
|
+
* // if no color is provided, it'll be green
|
|
88
|
+
* defaultProps: {
|
|
89
|
+
* color: 'green'
|
|
90
|
+
* },
|
|
91
|
+
* // expect backgroundColor via context
|
|
92
|
+
* contextType: React.createContext({ backgroundColor }),
|
|
93
|
+
* // configure styles with the static className to merge with user className
|
|
94
|
+
* styles: {
|
|
95
|
+
* // include the CSS modules map so 'button' can be resolved to the local name
|
|
96
|
+
* css,
|
|
97
|
+
* className: 'button'
|
|
98
|
+
* },
|
|
99
|
+
* // add event handlers that are cached between calls to prevent recreating each call. Any
|
|
100
|
+
* // handlers are added to the props passed to `useRender()`. See core/handle.
|
|
101
|
+
* handlers: {
|
|
102
|
+
* onKeyDown: (evt, props) => { .... }
|
|
103
|
+
* },
|
|
104
|
+
* // add some computed properties, these are added to props passed to `useRender()`
|
|
105
|
+
* computed: {
|
|
106
|
+
* // border color will be the color prepended by 'light'
|
|
107
|
+
* borderColor: ({color}) => 'light' + color,
|
|
108
|
+
* // background color will be the contextual background color if specified
|
|
109
|
+
* color: ({color}, context) => context.backgroundColor || color
|
|
110
|
+
* },
|
|
111
|
+
* // Render the thing, already!
|
|
112
|
+
* useRender: ({color, borderColor, children, ...rest}) => (
|
|
113
|
+
* <button
|
|
114
|
+
* {...rest}
|
|
115
|
+
* style={{backgroundColor: color, borderColor}}
|
|
116
|
+
* >
|
|
117
|
+
* {children}
|
|
118
|
+
* </button>
|
|
119
|
+
* )
|
|
120
|
+
* });
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* Creates a new functional component with declarative syntactic sugar.
|
|
125
|
+
*
|
|
126
|
+
* @function
|
|
127
|
+
* @template Props
|
|
128
|
+
* @param {KindConfig} config Component configuration
|
|
129
|
+
* @returns {Component<Props>}
|
|
130
|
+
* @memberof core/kind
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
var functionalKind = exports.functionalKind = function functionalKind(config) {
|
|
134
|
+
var cfgComputed = config.computed,
|
|
135
|
+
_config$contextType = config.contextType,
|
|
136
|
+
contextType = _config$contextType === void 0 ? NoContext : _config$contextType,
|
|
137
|
+
defaultProps = config.defaultProps,
|
|
138
|
+
handlers = config.handlers,
|
|
139
|
+
name = config.name,
|
|
140
|
+
propTypes = config.propTypes,
|
|
141
|
+
useRender = config.useRender,
|
|
142
|
+
cfgStyles = config.styles;
|
|
143
|
+
var renderStyles = cfgStyles ? (0, _styles["default"])(cfgStyles) : false;
|
|
144
|
+
var renderComputed = cfgComputed ? (0, _computed["default"])(cfgComputed) : false;
|
|
145
|
+
var renderKind = function renderKind(props, context) {
|
|
146
|
+
if (renderStyles) props = renderStyles(props, context);
|
|
147
|
+
if (renderComputed) props = renderComputed(props, context);
|
|
148
|
+
return useRender(props, context); // eslint-disable-line react-hooks/rules-of-hooks
|
|
149
|
+
};
|
|
150
|
+
var _Component = function Component(props) {
|
|
151
|
+
// Hooks must always be called unconditionally and in the same order.
|
|
152
|
+
var ctx = (0, _react.useContext)(contextType);
|
|
153
|
+
var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
|
|
154
|
+
|
|
155
|
+
// Merge incoming props with bound handlers.
|
|
156
|
+
var merged = _objectSpread(_objectSpread({}, props), boundHandlers);
|
|
157
|
+
|
|
158
|
+
// Apply defaultProps manually so functional components
|
|
159
|
+
// receive defaults even when React's own defaultProps is set.
|
|
160
|
+
if (defaultProps) {
|
|
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
|
+
}
|
|
168
|
+
(0, _util.checkPropTypes)(_Component, merged);
|
|
169
|
+
return renderKind(merged, ctx);
|
|
170
|
+
};
|
|
171
|
+
if (name) _Component.displayName = name;
|
|
172
|
+
if (propTypes) _Component.propTypes = propTypes;
|
|
173
|
+
if (defaultProps) _Component.defaultProps = defaultProps;
|
|
174
|
+
|
|
175
|
+
// Expose computed map in DEV for easier testability.
|
|
176
|
+
if (process.env.NODE_ENV !== "production" && cfgComputed) _Component.computed = cfgComputed;
|
|
177
|
+
|
|
178
|
+
// ── inline ──────────────────────────────────────────────────────────────
|
|
179
|
+
// A synchronous, hook-free path for calling the component logic outside
|
|
180
|
+
// 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
|
+
_Component.inline = function (props, context) {
|
|
184
|
+
var updated = _objectSpread({}, props);
|
|
185
|
+
if (defaultPropKeys !== null && defaultPropKeys !== void 0 && defaultPropKeys.length) {
|
|
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);
|
|
205
|
+
};
|
|
206
|
+
return _Component;
|
|
207
|
+
};
|
|
208
|
+
var _default = exports["default"] = functionalKind;
|
package/kind/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
Object.defineProperty(exports, "functionalKind", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _functionalKind.functionalKind;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "kind", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _kind.kind;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _functionalKind = require("./functionalKind");
|
|
20
|
+
var _kind = require("./kind");
|
|
21
|
+
var _default = exports["default"] = _kind.kind;
|
package/kind/kind.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.kind = exports["default"] = void 0;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useHandlers = _interopRequireDefault(require("../useHandlers"));
|
|
9
9
|
var _Handlers = _interopRequireDefault(require("../useHandlers/Handlers"));
|
|
10
|
+
var _util = require("../util");
|
|
10
11
|
var _computed = _interopRequireDefault(require("./computed"));
|
|
11
12
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -162,29 +163,44 @@ var kind = exports.kind = function kind(config) {
|
|
|
162
163
|
if (renderComputed) props = renderComputed(props, context);
|
|
163
164
|
return render(props, context);
|
|
164
165
|
};
|
|
165
|
-
var
|
|
166
|
+
var _Component;
|
|
166
167
|
|
|
167
168
|
// In 4.x, this branch will become the only supported version and the class branch will be
|
|
168
169
|
// removed.
|
|
169
170
|
if (functional) {
|
|
170
|
-
|
|
171
|
+
_Component = function Component(props) {
|
|
171
172
|
var ctx = (0, _react.use)(contextType);
|
|
172
173
|
var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
|
|
173
174
|
var merged = _objectSpread(_objectSpread({}, props), boundHandlers);
|
|
175
|
+
if (defaultProps) {
|
|
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
|
+
}
|
|
183
|
+
(0, _util.checkPropTypes)(_Component, merged);
|
|
174
184
|
return renderKind(merged, ctx);
|
|
175
185
|
};
|
|
176
186
|
} else {
|
|
177
187
|
var _Class;
|
|
178
|
-
|
|
179
|
-
function
|
|
188
|
+
_Component = (_Class = /*#__PURE__*/function (_ReactComponent) {
|
|
189
|
+
function _Component(props) {
|
|
180
190
|
var _this;
|
|
181
|
-
_classCallCheck(this,
|
|
182
|
-
_this = _callSuper(this,
|
|
191
|
+
_classCallCheck(this, _Component);
|
|
192
|
+
_this = _callSuper(this, _Component, [props]);
|
|
193
|
+
(0, _util.checkPropTypes)(_this, props);
|
|
183
194
|
_this.handlers = new _Handlers["default"](handlers);
|
|
184
195
|
return _this;
|
|
185
196
|
}
|
|
186
|
-
_inherits(
|
|
187
|
-
return _createClass(
|
|
197
|
+
_inherits(_Component, _ReactComponent);
|
|
198
|
+
return _createClass(_Component, [{
|
|
199
|
+
key: "componentDidUpdate",
|
|
200
|
+
value: function componentDidUpdate(prevProps) {
|
|
201
|
+
(0, _util.checkPropTypes)(this, this.props, prevProps);
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
188
204
|
key: "render",
|
|
189
205
|
value: function render() {
|
|
190
206
|
this.handlers.setContext(this.props, this.context);
|
|
@@ -194,15 +210,15 @@ var kind = exports.kind = function kind(config) {
|
|
|
194
210
|
}]);
|
|
195
211
|
}(_react.Component), _Class.contextType = contextType, _Class);
|
|
196
212
|
}
|
|
197
|
-
if (name)
|
|
198
|
-
if (propTypes)
|
|
199
|
-
if (defaultProps)
|
|
213
|
+
if (name) _Component.displayName = name;
|
|
214
|
+
if (propTypes) _Component.propTypes = propTypes;
|
|
215
|
+
if (defaultProps) _Component.defaultProps = defaultProps;
|
|
200
216
|
|
|
201
217
|
// Decorate the Component with the computed property object in DEV for easier testability
|
|
202
|
-
if (process.env.NODE_ENV !== "production" && cfgComputed)
|
|
218
|
+
if (process.env.NODE_ENV !== "production" && cfgComputed) _Component.computed = cfgComputed;
|
|
203
219
|
var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
|
|
204
220
|
var handlerKeys = handlers ? Object.keys(handlers) : null;
|
|
205
|
-
|
|
221
|
+
_Component.inline = function (props, context) {
|
|
206
222
|
var updated = _objectSpread({}, props);
|
|
207
223
|
if (defaultPropKeys && defaultPropKeys.length > 0) {
|
|
208
224
|
defaultPropKeys.forEach(function (key) {
|
|
@@ -224,6 +240,6 @@ var kind = exports.kind = function kind(config) {
|
|
|
224
240
|
}
|
|
225
241
|
return renderKind(updated, context);
|
|
226
242
|
};
|
|
227
|
-
return
|
|
243
|
+
return _Component;
|
|
228
244
|
};
|
|
229
245
|
var _default = exports["default"] = kind;
|
package/kind/package.json
CHANGED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
7
|
+
var _react2 = require("react");
|
|
8
|
+
var _functionalKind = _interopRequireDefault(require("../functionalKind"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
var _excluded = ["contextValue", "label", "value"];
|
|
11
|
+
/* eslint-disable enact/display-name */
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
16
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
20
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
21
|
+
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; }
|
|
22
|
+
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; }
|
|
23
|
+
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; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
25
|
+
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); }
|
|
26
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
27
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
28
|
+
describe('functionalKind', function () {
|
|
29
|
+
var TestContext = /*#__PURE__*/(0, _react2.createContext)({
|
|
30
|
+
value: 'initial'
|
|
31
|
+
});
|
|
32
|
+
var FunctionalKind = (0, _functionalKind["default"])({
|
|
33
|
+
name: 'Kind',
|
|
34
|
+
propTypes: {
|
|
35
|
+
prop: _propTypes["default"].number.isRequired,
|
|
36
|
+
label: _propTypes["default"].string
|
|
37
|
+
},
|
|
38
|
+
defaultProps: {
|
|
39
|
+
label: 'Label'
|
|
40
|
+
},
|
|
41
|
+
contextType: TestContext,
|
|
42
|
+
styles: {
|
|
43
|
+
className: 'kind'
|
|
44
|
+
},
|
|
45
|
+
handlers: {
|
|
46
|
+
onClick: function onClick(ev, props, context) {
|
|
47
|
+
props.onClick(context.value);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
computed: {
|
|
51
|
+
value: function value(_ref) {
|
|
52
|
+
var prop = _ref.prop;
|
|
53
|
+
return prop + 1;
|
|
54
|
+
},
|
|
55
|
+
contextValue: function contextValue(props, context) {
|
|
56
|
+
return context ? "context".concat(context.value) : 'unknown';
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
useRender: function useRender(_ref2) {
|
|
60
|
+
var contextValue = _ref2.contextValue,
|
|
61
|
+
label = _ref2.label,
|
|
62
|
+
value = _ref2.value,
|
|
63
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
64
|
+
delete rest.prop;
|
|
65
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
66
|
+
"data-context": contextValue,
|
|
67
|
+
title: label,
|
|
68
|
+
children: value
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
test('should assign name to displayName', function () {
|
|
73
|
+
var expected = 'Kind';
|
|
74
|
+
var actual = FunctionalKind.displayName;
|
|
75
|
+
expect(actual).toBe(expected);
|
|
76
|
+
});
|
|
77
|
+
test('should support undefined handlers', function () {
|
|
78
|
+
var Minimal = (0, _functionalKind["default"])({
|
|
79
|
+
name: 'Minimal',
|
|
80
|
+
useRender: function useRender() {
|
|
81
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
82
|
+
"data-testid": "minimal"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {}));
|
|
87
|
+
var minimalDiv = _react.screen.queryByTestId('minimal');
|
|
88
|
+
expect(minimalDiv).toBeInTheDocument();
|
|
89
|
+
});
|
|
90
|
+
test('should detect invalid proType on component rerender', function () {
|
|
91
|
+
var Minimal = (0, _functionalKind["default"])({
|
|
92
|
+
name: 'Minimal',
|
|
93
|
+
propTypes: {
|
|
94
|
+
value: _propTypes["default"].number
|
|
95
|
+
},
|
|
96
|
+
useRender: function useRender(props) {
|
|
97
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({
|
|
98
|
+
"data-testid": "minimal"
|
|
99
|
+
}, props));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {
|
|
103
|
+
value: 0
|
|
104
|
+
})),
|
|
105
|
+
rerender = _render.rerender;
|
|
106
|
+
var minimalDiv = _react.screen.queryByTestId('minimal');
|
|
107
|
+
expect(minimalDiv).toBeInTheDocument();
|
|
108
|
+
var consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
109
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {
|
|
110
|
+
value: "five"
|
|
111
|
+
}));
|
|
112
|
+
expect(consoleErrorMock).toHaveBeenCalled();
|
|
113
|
+
consoleErrorMock.mockRestore();
|
|
114
|
+
});
|
|
115
|
+
test('should default {label} property', function () {
|
|
116
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
117
|
+
prop: 1,
|
|
118
|
+
"data-testid": "unlabeled"
|
|
119
|
+
}));
|
|
120
|
+
var expected = 'Label';
|
|
121
|
+
var actual = _react.screen.queryByTestId('unlabeled').getAttribute('title');
|
|
122
|
+
expect(actual).toBe(expected);
|
|
123
|
+
});
|
|
124
|
+
test('should default {label} property when explicitly undefined', function () {
|
|
125
|
+
// Explicitly testing for undefined
|
|
126
|
+
// eslint-disable-next-line no-undefined
|
|
127
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
128
|
+
label: undefined,
|
|
129
|
+
"data-testid": "unlabeled",
|
|
130
|
+
prop: 1
|
|
131
|
+
}));
|
|
132
|
+
var expected = 'Label';
|
|
133
|
+
var actual = _react.screen.queryByTestId('unlabeled').getAttribute('title');
|
|
134
|
+
expect(actual).toBe(expected);
|
|
135
|
+
});
|
|
136
|
+
test('should add className defined in styles', function () {
|
|
137
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
138
|
+
prop: 1
|
|
139
|
+
}));
|
|
140
|
+
var expected = 'kind';
|
|
141
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
142
|
+
expect(kindDiv).toHaveClass(expected);
|
|
143
|
+
});
|
|
144
|
+
test('should compute {value} property', function () {
|
|
145
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
146
|
+
prop: 1
|
|
147
|
+
}));
|
|
148
|
+
var expected = '2';
|
|
149
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
150
|
+
expect(kindDiv).toHaveTextContent(expected);
|
|
151
|
+
});
|
|
152
|
+
test('should support contextType in handlers', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
153
|
+
var onClick = jest.fn();
|
|
154
|
+
var user = _userEvent["default"].setup();
|
|
155
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
156
|
+
onClick: onClick,
|
|
157
|
+
prop: 1
|
|
158
|
+
}));
|
|
159
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
160
|
+
yield user.click(kindDiv);
|
|
161
|
+
var expected = 'initial';
|
|
162
|
+
var actual = onClick.mock.calls[0][0];
|
|
163
|
+
expect(actual).toBe(expected);
|
|
164
|
+
}));
|
|
165
|
+
test('should support contextType in computed', function () {
|
|
166
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
167
|
+
prop: 1
|
|
168
|
+
}));
|
|
169
|
+
var expected = 'contextinitial';
|
|
170
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
171
|
+
expect(kindDiv).toHaveAttribute('data-context', expected);
|
|
172
|
+
});
|
|
173
|
+
test('support using hooks within kind instances', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
174
|
+
var user = _userEvent["default"].setup();
|
|
175
|
+
var Comp = (0, _functionalKind["default"])({
|
|
176
|
+
name: 'Comp',
|
|
177
|
+
functional: true,
|
|
178
|
+
useRender: function useRender() {
|
|
179
|
+
var _useState = (0, _react2.useState)(0),
|
|
180
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
181
|
+
state = _useState2[0],
|
|
182
|
+
setState = _useState2[1];
|
|
183
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
184
|
+
"data-testid": "button",
|
|
185
|
+
onClick: function onClick() {
|
|
186
|
+
return setState(state + 1);
|
|
187
|
+
},
|
|
188
|
+
children: state
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
193
|
+
var button = _react.screen.getByTestId('button');
|
|
194
|
+
yield user.click(button);
|
|
195
|
+
var expected = '1';
|
|
196
|
+
expect(button).toHaveTextContent(expected);
|
|
197
|
+
}));
|
|
198
|
+
describe('inline', function () {
|
|
199
|
+
test('should support a minimal kind', function () {
|
|
200
|
+
var Minimal = (0, _functionalKind["default"])({
|
|
201
|
+
name: 'Minimal',
|
|
202
|
+
useRender: function useRender() {
|
|
203
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
var component = Minimal.inline();
|
|
207
|
+
var expected = 'div';
|
|
208
|
+
var actual = component.type;
|
|
209
|
+
expect(actual).toBe(expected);
|
|
210
|
+
});
|
|
211
|
+
test('should set default props when prop is not passed', function () {
|
|
212
|
+
var component = FunctionalKind.inline();
|
|
213
|
+
|
|
214
|
+
// since we're inlining the output, we have to reference where the label prop lands --
|
|
215
|
+
// the title prop of the <div> -- rather than the label prop on the component (which
|
|
216
|
+
// doesn't exist due to inlining).
|
|
217
|
+
var expected = 'Label';
|
|
218
|
+
var actual = component.props.title;
|
|
219
|
+
expect(actual).toBe(expected);
|
|
220
|
+
});
|
|
221
|
+
test('should set default props when passed prop is undefined', function () {
|
|
222
|
+
var component = FunctionalKind.inline({
|
|
223
|
+
// explicitly testing settings undefined in this test case
|
|
224
|
+
// eslint-disable-next-line no-undefined
|
|
225
|
+
label: undefined
|
|
226
|
+
});
|
|
227
|
+
var expected = 'Label';
|
|
228
|
+
var actual = component.props.title;
|
|
229
|
+
expect(actual).toBe(expected);
|
|
230
|
+
});
|
|
231
|
+
test('should include handlers', function () {
|
|
232
|
+
var component = FunctionalKind.inline();
|
|
233
|
+
var expected = 'function';
|
|
234
|
+
var actual = typeof component.props.onClick;
|
|
235
|
+
expect(actual).toBe(expected);
|
|
236
|
+
});
|
|
237
|
+
test('should not support context', function () {
|
|
238
|
+
var component = FunctionalKind.inline();
|
|
239
|
+
var expected = 'unknown';
|
|
240
|
+
var actual = component.props['data-context'];
|
|
241
|
+
expect(actual).toBe(expected);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
package/kind/tests/kind-specs.js
CHANGED
|
@@ -7,7 +7,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
7
7
|
var _react2 = require("react");
|
|
8
8
|
var _kind = _interopRequireDefault(require("../kind"));
|
|
9
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
var _excluded = ["contextValue", "label", "value"]
|
|
10
|
+
var _excluded = ["contextValue", "label", "value"],
|
|
11
|
+
_excluded2 = ["contextValue", "label", "value"];
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
13
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
14
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -68,6 +69,47 @@ describe('kind', function () {
|
|
|
68
69
|
}));
|
|
69
70
|
}
|
|
70
71
|
});
|
|
72
|
+
var FunctionalKind = (0, _kind["default"])({
|
|
73
|
+
name: 'Kind',
|
|
74
|
+
functional: true,
|
|
75
|
+
propTypes: {
|
|
76
|
+
prop: _propTypes["default"].number.isRequired,
|
|
77
|
+
label: _propTypes["default"].string
|
|
78
|
+
},
|
|
79
|
+
defaultProps: {
|
|
80
|
+
label: 'Label'
|
|
81
|
+
},
|
|
82
|
+
contextType: TestContext,
|
|
83
|
+
styles: {
|
|
84
|
+
className: 'kind'
|
|
85
|
+
},
|
|
86
|
+
handlers: {
|
|
87
|
+
onClick: function onClick(ev, props, context) {
|
|
88
|
+
props.onClick(context.value);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
computed: {
|
|
92
|
+
value: function value(_ref3) {
|
|
93
|
+
var prop = _ref3.prop;
|
|
94
|
+
return prop + 1;
|
|
95
|
+
},
|
|
96
|
+
contextValue: function contextValue(props, context) {
|
|
97
|
+
return context ? "context".concat(context.value) : 'unknown';
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
render: function render(_ref4) {
|
|
101
|
+
var contextValue = _ref4.contextValue,
|
|
102
|
+
label = _ref4.label,
|
|
103
|
+
value = _ref4.value,
|
|
104
|
+
rest = _objectWithoutProperties(_ref4, _excluded2);
|
|
105
|
+
delete rest.prop;
|
|
106
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
107
|
+
"data-context": contextValue,
|
|
108
|
+
title: label,
|
|
109
|
+
children: value
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
71
113
|
test('should assign name to displayName', function () {
|
|
72
114
|
var expected = 'Kind';
|
|
73
115
|
var actual = Kind.displayName;
|
|
@@ -86,23 +128,59 @@ describe('kind', function () {
|
|
|
86
128
|
var minimalDiv = _react.screen.queryByTestId('minimal');
|
|
87
129
|
expect(minimalDiv).toBeInTheDocument();
|
|
88
130
|
});
|
|
89
|
-
test
|
|
90
|
-
var
|
|
91
|
-
|
|
131
|
+
test('should detect invalid proType on component rerender', function () {
|
|
132
|
+
var Minimal = (0, _kind["default"])({
|
|
133
|
+
name: 'Minimal',
|
|
134
|
+
propTypes: {
|
|
135
|
+
value: _propTypes["default"].number
|
|
136
|
+
},
|
|
137
|
+
render: function render(props) {
|
|
138
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({
|
|
139
|
+
"data-testid": "minimal"
|
|
140
|
+
}, props));
|
|
141
|
+
}
|
|
92
142
|
});
|
|
143
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {
|
|
144
|
+
value: 0
|
|
145
|
+
})),
|
|
146
|
+
rerender = _render.rerender;
|
|
147
|
+
var minimalDiv = _react.screen.queryByTestId('minimal');
|
|
148
|
+
expect(minimalDiv).toBeInTheDocument();
|
|
149
|
+
var consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
150
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {
|
|
151
|
+
value: "five"
|
|
152
|
+
}));
|
|
153
|
+
expect(consoleErrorMock).toHaveBeenCalled();
|
|
154
|
+
consoleErrorMock.mockRestore();
|
|
155
|
+
});
|
|
156
|
+
test('should default {label} property', function () {
|
|
157
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
158
|
+
prop: 1,
|
|
159
|
+
"data-testid": "unlabeled"
|
|
160
|
+
}));
|
|
161
|
+
var expected = 'Label';
|
|
162
|
+
var actual = _react.screen.queryByTestId('unlabeled').getAttribute('title');
|
|
163
|
+
expect(actual).toBe(expected);
|
|
164
|
+
});
|
|
165
|
+
test('should default {label} property for `functional` is `true`', function () {
|
|
166
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(FunctionalKind, {
|
|
167
|
+
prop: 1,
|
|
168
|
+
"data-testid": "unlabeled"
|
|
169
|
+
}));
|
|
93
170
|
var expected = 'Label';
|
|
94
|
-
var actual =
|
|
171
|
+
var actual = _react.screen.queryByTestId('unlabeled').getAttribute('title');
|
|
95
172
|
expect(actual).toBe(expected);
|
|
96
173
|
});
|
|
97
|
-
test
|
|
174
|
+
test('should default {label} property when explicitly undefined', function () {
|
|
98
175
|
// Explicitly testing for undefined
|
|
99
176
|
// eslint-disable-next-line no-undefined
|
|
100
|
-
|
|
177
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
101
178
|
label: undefined,
|
|
179
|
+
"data-testid": "unlabeled",
|
|
102
180
|
prop: 1
|
|
103
|
-
});
|
|
181
|
+
}));
|
|
104
182
|
var expected = 'Label';
|
|
105
|
-
var actual =
|
|
183
|
+
var actual = _react.screen.queryByTestId('unlabeled').getAttribute('title');
|
|
106
184
|
expect(actual).toBe(expected);
|
|
107
185
|
});
|
|
108
186
|
test('should add className defined in styles', function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
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,9 +36,14 @@
|
|
|
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.6",
|
|
40
|
+
"react-dom": "^19.2.6",
|
|
41
|
+
"react-is": "^19.2.6",
|
|
42
42
|
"warning": "^4.0.3"
|
|
43
|
+
},
|
|
44
|
+
"overrides": {
|
|
45
|
+
"prop-types": {
|
|
46
|
+
"react-is": "^19.2.6"
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
}
|
package/useClass/useClass.js
CHANGED
|
@@ -9,6 +9,12 @@ var _react = require("react");
|
|
|
9
9
|
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
|
|
10
10
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
11
11
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
12
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
12
18
|
/**
|
|
13
19
|
* Creates one instance of the class, `Ctor` with the provided `args`, for the life of the
|
|
14
20
|
* component.
|
|
@@ -38,11 +44,14 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
38
44
|
* @private
|
|
39
45
|
*/
|
|
40
46
|
function useClass(Ctor) {
|
|
41
|
-
var ref = (0, _react.useRef)(null);
|
|
42
47
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
43
48
|
args[_key - 1] = arguments[_key];
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
var _useState = (0, _react.useState)(function () {
|
|
51
|
+
return _construct(Ctor, args);
|
|
52
|
+
}),
|
|
53
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
54
|
+
state = _useState2[0];
|
|
55
|
+
return state;
|
|
47
56
|
}
|
|
48
57
|
var _default = exports["default"] = useClass;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
+
var _react2 = require("react");
|
|
5
6
|
var _useHandlers = _interopRequireDefault(require("../useHandlers"));
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -21,9 +22,11 @@ describe('useHandlers', function () {
|
|
|
21
22
|
return ev(p, c);
|
|
22
23
|
}
|
|
23
24
|
}, props, context);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
(0, _react2.useEffect)(function () {
|
|
26
|
+
data = {
|
|
27
|
+
handlers: handlers
|
|
28
|
+
};
|
|
29
|
+
}, [handlers]);
|
|
27
30
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, {
|
|
28
31
|
"data-testid": "divComponent"
|
|
29
32
|
}));
|
package/util/tests/util-specs.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _react = require("react");
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
5
|
+
var _react2 = require("react");
|
|
4
6
|
var _util = require("../util");
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
+
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); }
|
|
14
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
15
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
16
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
17
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
18
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
19
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
20
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
5
21
|
describe('util', function () {
|
|
6
22
|
describe('cap', function () {
|
|
7
23
|
test('should return a capitalized string', function () {
|
|
@@ -18,6 +34,55 @@ describe('util', function () {
|
|
|
18
34
|
expect((0, _util.clamp)(20, 10, 10)).toBe(20); // special case
|
|
19
35
|
});
|
|
20
36
|
});
|
|
37
|
+
describe('checkPropTypes', function () {
|
|
38
|
+
var TestComponent = /*#__PURE__*/function (_Component) {
|
|
39
|
+
function TestComponent(props) {
|
|
40
|
+
var _this;
|
|
41
|
+
_classCallCheck(this, TestComponent);
|
|
42
|
+
_this = _callSuper(this, TestComponent, [props]);
|
|
43
|
+
(0, _util.checkPropTypes)(_this, _this.props);
|
|
44
|
+
return _this;
|
|
45
|
+
}
|
|
46
|
+
_inherits(TestComponent, _Component);
|
|
47
|
+
return _createClass(TestComponent, [{
|
|
48
|
+
key: "render",
|
|
49
|
+
value: function render() {
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
51
|
+
children: "Test"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
}(_react2.Component);
|
|
56
|
+
TestComponent.displayName = 'TestComponent';
|
|
57
|
+
TestComponent.propTypes = {
|
|
58
|
+
bool: _propTypes["default"].bool,
|
|
59
|
+
string: _propTypes["default"].string
|
|
60
|
+
};
|
|
61
|
+
var consoleWarnMock = null;
|
|
62
|
+
var consoleErrorMock = null;
|
|
63
|
+
beforeEach(function () {
|
|
64
|
+
consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
65
|
+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
66
|
+
});
|
|
67
|
+
afterEach(function () {
|
|
68
|
+
consoleWarnMock.mockRestore();
|
|
69
|
+
consoleErrorMock.mockRestore();
|
|
70
|
+
});
|
|
71
|
+
test('should not call any console.error for a correct prop', function () {
|
|
72
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {
|
|
73
|
+
bool: true,
|
|
74
|
+
string: "String"
|
|
75
|
+
}));
|
|
76
|
+
expect(consoleErrorMock).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
test('should call console.error for a wrong prop', function () {
|
|
79
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {
|
|
80
|
+
bool: "true",
|
|
81
|
+
string: "String"
|
|
82
|
+
}));
|
|
83
|
+
expect(consoleErrorMock).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
21
86
|
describe('coerceArray', function () {
|
|
22
87
|
test('should return an array', function () {
|
|
23
88
|
expect((0, _util.coerceArray)(['a'])).toEqual(['a']);
|
|
@@ -66,17 +131,17 @@ describe('util', function () {
|
|
|
66
131
|
});
|
|
67
132
|
test('should return {true} for React.forwardRef', function () {
|
|
68
133
|
var expected = true;
|
|
69
|
-
var view = (0, _util.isRenderable)(/*#__PURE__*/(0,
|
|
134
|
+
var view = (0, _util.isRenderable)(/*#__PURE__*/(0, _react2.forwardRef)(function () {}));
|
|
70
135
|
expect(view).toEqual(expected);
|
|
71
136
|
});
|
|
72
137
|
test('should return {true} for React.memo', function () {
|
|
73
138
|
var expected = true;
|
|
74
|
-
var view = (0, _util.isRenderable)(/*#__PURE__*/(0,
|
|
139
|
+
var view = (0, _util.isRenderable)(/*#__PURE__*/(0, _react2.memo)(function () {}));
|
|
75
140
|
expect(view).toEqual(expected);
|
|
76
141
|
});
|
|
77
142
|
test('should return {true} for React.lazy', function () {
|
|
78
143
|
var expected = true;
|
|
79
|
-
var view = (0, _util.isRenderable)(/*#__PURE__*/(0,
|
|
144
|
+
var view = (0, _util.isRenderable)(/*#__PURE__*/(0, _react2.lazy)(function () {}));
|
|
80
145
|
expect(view).toEqual(expected);
|
|
81
146
|
});
|
|
82
147
|
});
|
|
@@ -254,4 +319,64 @@ describe('util', function () {
|
|
|
254
319
|
expect((0, _util.shallowEqual)(child, fakeChild)).toBe(false);
|
|
255
320
|
});
|
|
256
321
|
});
|
|
322
|
+
describe('usePrevious', function () {
|
|
323
|
+
test('should return the initial value on first render', function () {
|
|
324
|
+
var _renderHook = (0, _react.renderHook)(function () {
|
|
325
|
+
return (0, _util.usePrevious)(1);
|
|
326
|
+
}),
|
|
327
|
+
result = _renderHook.result;
|
|
328
|
+
expect(result.current).toBe(1);
|
|
329
|
+
});
|
|
330
|
+
test('should return the previous value after the value changes', function () {
|
|
331
|
+
var value = 1;
|
|
332
|
+
var _renderHook2 = (0, _react.renderHook)(function () {
|
|
333
|
+
return (0, _util.usePrevious)(value);
|
|
334
|
+
}),
|
|
335
|
+
result = _renderHook2.result,
|
|
336
|
+
rerender = _renderHook2.rerender;
|
|
337
|
+
|
|
338
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
339
|
+
(0, _react.act)(function () {
|
|
340
|
+
value = 2;
|
|
341
|
+
rerender();
|
|
342
|
+
});
|
|
343
|
+
expect(result.current).toBe(1);
|
|
344
|
+
});
|
|
345
|
+
test('should track the previous value across multiple changes', function () {
|
|
346
|
+
var value = 'a';
|
|
347
|
+
var _renderHook3 = (0, _react.renderHook)(function () {
|
|
348
|
+
return (0, _util.usePrevious)(value);
|
|
349
|
+
}),
|
|
350
|
+
result = _renderHook3.result,
|
|
351
|
+
rerender = _renderHook3.rerender;
|
|
352
|
+
|
|
353
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
354
|
+
(0, _react.act)(function () {
|
|
355
|
+
value = 'b';
|
|
356
|
+
rerender();
|
|
357
|
+
});
|
|
358
|
+
expect(result.current).toBe('a');
|
|
359
|
+
|
|
360
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
361
|
+
(0, _react.act)(function () {
|
|
362
|
+
value = 'c';
|
|
363
|
+
rerender();
|
|
364
|
+
});
|
|
365
|
+
expect(result.current).toBe('b');
|
|
366
|
+
});
|
|
367
|
+
test('should not update previous value when value stays the same', function () {
|
|
368
|
+
var value = 42;
|
|
369
|
+
var _renderHook4 = (0, _react.renderHook)(function () {
|
|
370
|
+
return (0, _util.usePrevious)(value);
|
|
371
|
+
}),
|
|
372
|
+
result = _renderHook4.result,
|
|
373
|
+
rerender = _renderHook4.rerender;
|
|
374
|
+
|
|
375
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
376
|
+
(0, _react.act)(function () {
|
|
377
|
+
rerender();
|
|
378
|
+
});
|
|
379
|
+
expect(result.current).toBe(42);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
257
382
|
});
|
package/util/util.d.ts
CHANGED
|
@@ -162,3 +162,17 @@ export function setDefaultProps(props: object, defaultProps: object): object;
|
|
|
162
162
|
* Performs shallow comparison for given objects.
|
|
163
163
|
*/
|
|
164
164
|
export function shallowEqual(a: object, b: object): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Checks the prop types of a component.
|
|
167
|
+
*
|
|
168
|
+
* It only performs the check when `__DEV__` is true.
|
|
169
|
+
*/
|
|
170
|
+
export function checkPropTypes(
|
|
171
|
+
component: object,
|
|
172
|
+
props: object,
|
|
173
|
+
prevProps?: object,
|
|
174
|
+
): void;
|
|
175
|
+
/**
|
|
176
|
+
* A custom hook that returns the previous value of a variable.
|
|
177
|
+
*/
|
|
178
|
+
export function usePrevious(value: any): any;
|
package/util/util.js
CHANGED
|
@@ -9,7 +9,8 @@ Object.defineProperty(exports, "Job", {
|
|
|
9
9
|
return _Job["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
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;
|
|
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;
|
|
13
|
+
var _propTypes = require("prop-types");
|
|
13
14
|
var _always = _interopRequireDefault(require("ramda/src/always"));
|
|
14
15
|
var _is = _interopRequireDefault(require("ramda/src/is"));
|
|
15
16
|
var _unless = _interopRequireDefault(require("ramda/src/unless"));
|
|
@@ -18,11 +19,17 @@ var ReactIs = _interopRequireWildcard(require("react-is"));
|
|
|
18
19
|
var _Job = _interopRequireDefault(require("./Job"));
|
|
19
20
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
20
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
21
|
-
|
|
22
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
23
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
25
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
26
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
27
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /**
|
|
22
28
|
* A collection of utility methods.
|
|
23
29
|
*
|
|
24
30
|
* @module core/util
|
|
25
31
|
* @exports cap
|
|
32
|
+
* @exports checkPropTypes
|
|
26
33
|
* @exports clamp
|
|
27
34
|
* @exports coerceArray
|
|
28
35
|
* @exports coerceFunction
|
|
@@ -34,8 +41,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
|
|
|
34
41
|
* @exports perfNow
|
|
35
42
|
* @exports mapAndFilterChildren
|
|
36
43
|
* @exports shallowEqual
|
|
44
|
+
* @exports usePrevious
|
|
37
45
|
*/
|
|
38
|
-
|
|
39
46
|
/**
|
|
40
47
|
* Capitalizes a given string (not locale-aware).
|
|
41
48
|
*
|
|
@@ -335,4 +342,63 @@ var shallowEqual = exports.shallowEqual = function shallowEqual(a, b) {
|
|
|
335
342
|
}
|
|
336
343
|
}
|
|
337
344
|
return true;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Checks the prop types of a component.
|
|
349
|
+
*
|
|
350
|
+
* It only performs the check when `__DEV__` is true.
|
|
351
|
+
*
|
|
352
|
+
* @function checkPropTypes
|
|
353
|
+
* @param {Object} component The component instance to check.
|
|
354
|
+
* @param {Object} props The component props to check.
|
|
355
|
+
* @param {Object} [prevProps] The previous props to compare against.
|
|
356
|
+
*
|
|
357
|
+
* @returns {undefined}
|
|
358
|
+
* @memberof core/util
|
|
359
|
+
* @public
|
|
360
|
+
*/
|
|
361
|
+
var _checkPropTypes = exports.checkPropTypes = function checkPropTypes(component, props, prevProps) {
|
|
362
|
+
if (process.env.NODE_ENV !== "production" && !(prevProps && prevProps === props)) {
|
|
363
|
+
var isFunctional = typeof component === 'function';
|
|
364
|
+
var _ref = isFunctional ? component : component.constructor,
|
|
365
|
+
displayName = _ref.displayName,
|
|
366
|
+
name = _ref.name,
|
|
367
|
+
propTypes = _ref.propTypes; // eslint-disable-line react/forbid-foreign-prop-types
|
|
368
|
+
|
|
369
|
+
(0, _propTypes.checkPropTypes)(propTypes, props, 'prop', displayName || name, function () {
|
|
370
|
+
// Create a new error to capture the current stack trace
|
|
371
|
+
var checkPropsError = new Error();
|
|
372
|
+
if (Error.captureStackTrace) {
|
|
373
|
+
Error.captureStackTrace(checkPropsError, _checkPropTypes);
|
|
374
|
+
}
|
|
375
|
+
return checkPropsError.stack.split('@')[0];
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* A custom hook that returns the previous value of a variable.
|
|
382
|
+
*
|
|
383
|
+
* @function
|
|
384
|
+
* @param {*} value The value to track.
|
|
385
|
+
*
|
|
386
|
+
* @returns {*} The value from the previous render.
|
|
387
|
+
* @memberof core/util
|
|
388
|
+
* @public
|
|
389
|
+
*/
|
|
390
|
+
var usePrevious = exports.usePrevious = function usePrevious(value) {
|
|
391
|
+
var _useState = (0, _react.useState)(value),
|
|
392
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
393
|
+
previousTrackedValue = _useState2[0],
|
|
394
|
+
setPreviousTrackedValue = _useState2[1];
|
|
395
|
+
var _useState3 = (0, _react.useState)(value),
|
|
396
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
397
|
+
previousValue = _useState4[0],
|
|
398
|
+
setPreviousValue = _useState4[1];
|
|
399
|
+
if (value !== previousTrackedValue) {
|
|
400
|
+
setPreviousTrackedValue(value);
|
|
401
|
+
setPreviousValue(previousTrackedValue);
|
|
402
|
+
}
|
|
403
|
+
return previousValue;
|
|
338
404
|
};
|
|
File without changes
|