@enact/core 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/{build/dispatcher → dispatcher}/dispatcher.d.ts +0 -0
  3. package/dispatcher/dispatcher.js +76 -57
  4. package/dispatcher/listeners.js +31 -19
  5. package/dispatcher/tests/dispatcher-specs.js +75 -100
  6. package/{build/handle → handle}/handle.d.ts +0 -0
  7. package/handle/handle.js +260 -212
  8. package/handle/tests/handle-specs.js +476 -601
  9. package/{build/hoc → hoc}/hoc.d.ts +0 -0
  10. package/hoc/hoc.js +47 -33
  11. package/hoc/tests/hoc-specs.js +85 -126
  12. package/{build/index.d.ts → index.d.ts} +0 -0
  13. package/index.js +1 -0
  14. package/{build/internal → internal}/ApiDecorator/ApiDecorator.d.ts +0 -0
  15. package/internal/ApiDecorator/ApiDecorator.js +107 -61
  16. package/internal/ApiDecorator/tests/ApiDecorator-specs.js +106 -97
  17. package/{build/internal → internal}/Registry/Registry.d.ts +0 -0
  18. package/internal/Registry/Registry.js +68 -51
  19. package/internal/Registry/tests/Registry-specs.js +201 -143
  20. package/{build/internal → internal}/deprecate/deprecate.d.ts +0 -0
  21. package/internal/deprecate/deprecate.js +85 -60
  22. package/{build/internal → internal}/prop-types/prop-types.d.ts +0 -0
  23. package/internal/prop-types/prop-types.js +68 -61
  24. package/{build/keymap → keymap}/index.d.ts +0 -0
  25. package/keymap/index.js +27 -15
  26. package/keymap/keymap.js +67 -52
  27. package/keymap/tests/keymap-specs.js +75 -104
  28. package/kind/computed.js +29 -16
  29. package/{build/kind → kind}/kind.d.ts +0 -0
  30. package/kind/kind.js +150 -114
  31. package/kind/styles.js +62 -47
  32. package/kind/tests/computed-specs.js +87 -86
  33. package/kind/tests/kind-specs.js +216 -214
  34. package/kind/tests/styles-specs.js +170 -223
  35. package/kind/util.js +15 -7
  36. package/package.json +1 -1
  37. package/{build/platform → platform}/platform.d.ts +0 -0
  38. package/platform/platform.js +263 -169
  39. package/platform/tests/platform-specs.js +92 -90
  40. package/{build/snapshot → snapshot}/snapshot.d.ts +0 -0
  41. package/snapshot/snapshot.js +34 -27
  42. package/useChainRefs/tests/useChainRefs-specs.js +46 -30
  43. package/{build/useChainRefs → useChainRefs}/useChainRefs.d.ts +0 -0
  44. package/useChainRefs/useChainRefs.js +49 -29
  45. package/useClass/tests/useClass-specs.js +51 -46
  46. package/{build/useClass → useClass}/useClass.d.ts +0 -0
  47. package/useClass/useClass.js +27 -9
  48. package/useHandlers/Handlers.js +55 -30
  49. package/useHandlers/tests/useHandlers-specs.js +79 -95
  50. package/{build/useHandlers → useHandlers}/useHandlers.d.ts +0 -0
  51. package/useHandlers/useHandlers.js +18 -11
  52. package/util/Job.js +203 -241
  53. package/util/tests/Job-specs.js +216 -204
  54. package/util/tests/util-specs.js +123 -146
  55. package/{build/util → util}/util.d.ts +0 -0
  56. package/util/util.js +146 -103
  57. package/build/CHANGELOG.md +0 -699
  58. package/build/README.md +0 -33
  59. package/build/dispatcher/dispatcher.js +0 -160
  60. package/build/dispatcher/listeners.js +0 -37
  61. package/build/dispatcher/package.json +0 -3
  62. package/build/dispatcher/tests/dispatcher-specs.js +0 -75
  63. package/build/handle/handle.js +0 -846
  64. package/build/handle/package.json +0 -3
  65. package/build/handle/tests/handle-specs.js +0 -476
  66. package/build/hoc/hoc.js +0 -102
  67. package/build/hoc/package.json +0 -3
  68. package/build/hoc/tests/hoc-specs.js +0 -90
  69. package/build/index.js +0 -2
  70. package/build/internal/ApiDecorator/ApiDecorator.js +0 -143
  71. package/build/internal/ApiDecorator/package.json +0 -3
  72. package/build/internal/ApiDecorator/tests/ApiDecorator-specs.js +0 -106
  73. package/build/internal/Registry/Registry.js +0 -76
  74. package/build/internal/Registry/package.json +0 -3
  75. package/build/internal/Registry/tests/Registry-specs.js +0 -201
  76. package/build/internal/deprecate/deprecate.js +0 -116
  77. package/build/internal/deprecate/package.json +0 -3
  78. package/build/internal/prop-types/package.json +0 -3
  79. package/build/internal/prop-types/prop-types.js +0 -90
  80. package/build/keymap/index.js +0 -54
  81. package/build/keymap/keymap.js +0 -201
  82. package/build/keymap/package.json +0 -3
  83. package/build/keymap/tests/keymap-specs.js +0 -75
  84. package/build/kind/computed.js +0 -60
  85. package/build/kind/kind.js +0 -266
  86. package/build/kind/package.json +0 -3
  87. package/build/kind/styles.js +0 -105
  88. package/build/kind/tests/computed-specs.js +0 -87
  89. package/build/kind/tests/kind-specs.js +0 -216
  90. package/build/kind/tests/styles-specs.js +0 -170
  91. package/build/kind/util.js +0 -17
  92. package/build/package-lock.json +0 -206
  93. package/build/package.json +0 -38
  94. package/build/platform/package.json +0 -3
  95. package/build/platform/platform.js +0 -306
  96. package/build/platform/tests/platform-specs.js +0 -92
  97. package/build/snapshot/package.json +0 -3
  98. package/build/snapshot/snapshot.js +0 -89
  99. package/build/useChainRefs/package.json +0 -3
  100. package/build/useChainRefs/tests/useChainRefs-specs.js +0 -57
  101. package/build/useChainRefs/useChainRefs.js +0 -78
  102. package/build/useClass/package.json +0 -3
  103. package/build/useClass/tests/useClass-specs.js +0 -51
  104. package/build/useClass/useClass.js +0 -59
  105. package/build/useHandlers/Handlers.js +0 -55
  106. package/build/useHandlers/package.json +0 -3
  107. package/build/useHandlers/tests/useHandlers-specs.js +0 -84
  108. package/build/useHandlers/useHandlers.js +0 -36
  109. package/build/util/Job.js +0 -211
  110. package/build/util/package.json +0 -3
  111. package/build/util/tests/Job-specs.js +0 -216
  112. package/build/util/tests/util-specs.js +0 -123
  113. package/build/util/util.js +0 -322
@@ -1,266 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.kind = exports["default"] = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _useHandlers = _interopRequireDefault(require("../useHandlers"));
11
-
12
- var _Handlers = _interopRequireDefault(require("../useHandlers/Handlers"));
13
-
14
- var _computed = _interopRequireDefault(require("./computed"));
15
-
16
- var _styles = _interopRequireDefault(require("./styles"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
-
20
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
-
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
-
26
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
-
28
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
-
30
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
31
-
32
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33
-
34
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
-
36
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
37
-
38
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
-
40
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
41
-
42
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
43
-
44
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
45
-
46
- // Because contextType is optional and hooks must be called in the same order, we need a fallback
47
- // context when none is specified. This likely has some overhead so we may want to deprecate and
48
- // remove contextType support for 4.0 since the context APIs have improved since this was added.
49
- var NoContext = /*#__PURE__*/_react["default"].createContext(null);
50
- /**
51
- * @callback RenderFunction
52
- * @memberof core/kind
53
- * @param {Object<string, any>} props
54
- * @param {Object<string, any>} context
55
- * @returns React.Element|null
56
- */
57
-
58
- /**
59
- * @callback ComputedPropFunction
60
- * @memberof core/kind
61
- * @param {Object<string, any>} props
62
- * @param {Object<string, any>} context
63
- * @returns any
64
- */
65
-
66
- /**
67
- * @callback HandlerFunction
68
- * @memberof core/kind
69
- * @param {any} event
70
- * @param {Object<string, any>} props
71
- * @param {Object<string, any>} context
72
- */
73
-
74
- /**
75
- * Configuration for CSS class name mapping
76
- *
77
- * @typedef {Object} StylesBlock
78
- * @memberof core/kind
79
- * @property {Object.<string, string>} css
80
- * @property {String} [className]
81
- * @property {Boolean|String|String[]} [publicClassNames]
82
- */
83
-
84
- /**
85
- * @typedef {Object} KindConfig
86
- * @memberof core/kind
87
- * @property {String} [name]
88
- * @property {Boolean} [functional]
89
- * @property {Object.<string, Function>} [propTypes]
90
- * @property {Object.<string, any>} [defaultProps]
91
- * @property {Object} [contextType]
92
- * @property {StylesBlock} [styles]
93
- * @property {Object.<string, HandlerFunction>} [handlers]
94
- * @property {Object.<string, ComputedPropFunction>} [computed]
95
- * @property {RenderFunction} render
96
- */
97
-
98
- /**
99
- * Creates a new component with some helpful declarative syntactic sugar.
100
- *
101
- * Example:
102
- * ```
103
- * import css from './Button.module.less';
104
- * const Button = kind({
105
- * name: 'Button',
106
- * // Return a functional component suitable for use with React hooks
107
- * functional: true,
108
- * // expect color and onClick properties but neither required
109
- * propTypes: {
110
- * color: PropTypes.string
111
- * },
112
- * // if no color is provided, it'll be green
113
- * defaultProps: {
114
- * color: 'green'
115
- * },
116
- * // expect backgroundColor via context
117
- * contextType: React.createContext({ backgroundColor }),
118
- * // configure styles with the static className to merge with user className
119
- * styles: {
120
- * // include the CSS modules map so 'button' can be resolved to the local name
121
- * css,
122
- * className: 'button'
123
- * },
124
- * // add event handlers that are cached between calls to prevent recreating each call. Any
125
- * // handlers are added to the props passed to `render()`. See core/handle.
126
- * handlers: {
127
- * onKeyDown: (evt, props) => { .... }
128
- * },
129
- * // add some computed properties, these are added to props passed to `render()`
130
- * computed: {
131
- * // border color will be the color prepended by 'light'
132
- * borderColor: ({color}) => 'light' + color,
133
- * // background color will be the contextual background color if specified
134
- * color: ({color}, context) => context.backgroundColor || color
135
- * },
136
- * // Render the thing, already!
137
- * render: ({color, borderColor, children, ...rest}) => (
138
- * <button
139
- * {...rest}
140
- * style={{backgroundColor: color, borderColor}}
141
- * >
142
- * {children}
143
- * </button>
144
- * )
145
- * });
146
- * ```
147
- *
148
- * @function
149
- * @template Props
150
- * @param {KindConfig} config Component configuration
151
- *
152
- * @returns {Component<Props>} Component
153
- * @memberof core/kind
154
- * @see {@link core/handle}
155
- * @public
156
- */
157
-
158
-
159
- var kind = function kind(config) {
160
- var cfgComputed = config.computed,
161
- _config$contextType = config.contextType,
162
- contextType = _config$contextType === void 0 ? NoContext : _config$contextType,
163
- defaultProps = config.defaultProps,
164
- functional = config.functional,
165
- handlers = config.handlers,
166
- name = config.name,
167
- propTypes = config.propTypes,
168
- render = config.render,
169
- cfgStyles = config.styles;
170
- var renderStyles = cfgStyles ? (0, _styles["default"])(cfgStyles) : false;
171
- var renderComputed = cfgComputed ? (0, _computed["default"])(cfgComputed) : false;
172
-
173
- var renderKind = function renderKind(props, context) {
174
- if (renderStyles) props = renderStyles(props, context);
175
- if (renderComputed) props = renderComputed(props, context);
176
- return render(props, context);
177
- };
178
-
179
- var Component; // In 4.x, this branch will become the only supported version and the class branch will be
180
- // removed.
181
-
182
- if (functional) {
183
- Component = function Component(props) {
184
- var ctx = _react["default"].useContext(contextType);
185
-
186
- var boundHandlers = (0, _useHandlers["default"])(handlers, props, ctx);
187
-
188
- var merged = _objectSpread(_objectSpread({}, props), boundHandlers);
189
-
190
- return renderKind(merged, ctx);
191
- };
192
- } else {
193
- var _class, _temp;
194
-
195
- // eslint-disable-next-line enact/display-name
196
- Component = (_temp = _class = /*#__PURE__*/function (_React$Component) {
197
- _inherits(Component, _React$Component);
198
-
199
- var _super = _createSuper(Component);
200
-
201
- function Component() {
202
- var _this;
203
-
204
- _classCallCheck(this, Component);
205
-
206
- _this = _super.call(this);
207
- _this.handlers = new _Handlers["default"](handlers);
208
- return _this;
209
- }
210
-
211
- _createClass(Component, [{
212
- key: "render",
213
- value: function render() {
214
- this.handlers.setContext(this.props, this.context);
215
-
216
- var merged = _objectSpread(_objectSpread({}, this.props), this.handlers.handlers);
217
-
218
- return renderKind(merged, this.context);
219
- }
220
- }]);
221
-
222
- return Component;
223
- }(_react["default"].Component), _class.contextType = contextType, _temp);
224
- }
225
-
226
- if (name) Component.displayName = name;
227
- if (propTypes) Component.propTypes = propTypes;
228
- if (defaultProps) Component.defaultProps = defaultProps; // Decorate the Component with the computed property object in DEV for easier testability
229
-
230
- if (process.env.NODE_ENV !== "production" && cfgComputed) Component.computed = cfgComputed;
231
- var defaultPropKeys = defaultProps ? Object.keys(defaultProps) : null;
232
- var handlerKeys = handlers ? Object.keys(handlers) : null;
233
-
234
- Component.inline = function (props, context) {
235
- var updated = _objectSpread({}, props);
236
-
237
- if (defaultPropKeys && defaultPropKeys.length > 0) {
238
- defaultPropKeys.forEach(function (key) {
239
- // eslint-disable-next-line no-undefined
240
- if (props == null || props[key] === undefined) {
241
- updated[key] = defaultProps[key];
242
- }
243
- });
244
- }
245
-
246
- if (handlerKeys && handlerKeys.length > 0) {
247
- // generate a handler with a clone of updated to ensure each handler receives the same
248
- // props without the kind.handlers injected.
249
- updated = handlerKeys.reduce(function (_props, key) {
250
- _props[key] = function (ev) {
251
- return handlers[key](ev, updated, context);
252
- };
253
-
254
- return _props;
255
- }, _objectSpread({}, updated));
256
- }
257
-
258
- return renderKind(updated, context);
259
- };
260
-
261
- return Component;
262
- };
263
-
264
- exports.kind = kind;
265
- var _default = kind;
266
- exports["default"] = _default;
@@ -1,3 +0,0 @@
1
- {
2
- "main":"kind.js"
3
- }
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.styles = exports["default"] = void 0;
7
-
8
- var _bind = _interopRequireDefault(require("classnames/bind"));
9
-
10
- var _util = require("../util");
11
-
12
- var _util2 = require("./util");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- /**
17
- * Merges external and internal CSS classes and style objects. Internal CSS classes can be
18
- * optionally mapped to alternate names (e.g. those generated by CSS modules) by including a
19
- * `css` parameter.
20
- *
21
- * Example:
22
- * ```
23
- * const stylesConfig = {
24
- * css: {
25
- * button: 'unambiguous-button-class-name',
26
- * client: 'unambiguous-button-class-name-client'
27
- * },
28
- * className: 'button global-class',
29
- * style: {
30
- * color: 'red'
31
- * }
32
- * };
33
- *
34
- * const props = {
35
- * className: 'my-button',
36
- * style: {
37
- * display: 'none'
38
- * }
39
- * };
40
- *
41
- * const renderStyles = styles(stylesConfig);
42
- * const renderStyles(props); // {className: 'unambiguous-button-class-name global-class', styles: {color: 'red', display: 'none'}}
43
- * ```
44
- *
45
- * @method styles
46
- * @param {Object} cfg Configuration object containing one of `css`, `className`,
47
- * `publicClassNames`, and/or `style`
48
- *
49
- * @returns {Function} Function that accepts a props object and mutates it to merge class
50
- * names and style objects and provide the `styler` utility function and
51
- * `css` merged class name map
52
- * @private
53
- */
54
- var styles = function styles(cfg, optProps) {
55
- var className = cfg.className,
56
- configCss = cfg.css,
57
- _cfg$prop = cfg.prop,
58
- prop = _cfg$prop === void 0 ? 'className' : _cfg$prop,
59
- style = cfg.style;
60
- var allowedClassNames = cfg.publicClassNames;
61
-
62
- if (configCss && allowedClassNames === true) {
63
- allowedClassNames = Object.keys(configCss);
64
- } else if (typeof allowedClassNames === 'string') {
65
- allowedClassNames = allowedClassNames.split(/\s+/);
66
- }
67
-
68
- var renderStyles = function renderStyles(props) {
69
- var css = configCss;
70
-
71
- if (style) {
72
- props.style = Object.assign({}, style, props.style);
73
- } // if the props includes a css map, merge them together now
74
-
75
-
76
- if (css && allowedClassNames && props.css) {
77
- css = (0, _util.mergeClassNameMaps)(css, props.css, allowedClassNames);
78
- }
79
-
80
- var cn = css ? _bind["default"].bind(css) : _bind["default"];
81
- var joinedClassName = props[prop] = (0, _bind["default"])(className ? cn(className.split(' ')) : null, props.className);
82
- (0, _util2.addInternalProp)(props, 'css', css);
83
- (0, _util2.addInternalProp)(props, 'styler', {
84
- join: cn,
85
- append: function append() {
86
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
87
- args[_key] = arguments[_key];
88
- }
89
-
90
- return cn.apply(void 0, [joinedClassName].concat(args));
91
- }
92
- });
93
- return props;
94
- };
95
-
96
- if (optProps) {
97
- return renderStyles(optProps);
98
- }
99
-
100
- return renderStyles;
101
- };
102
-
103
- exports.styles = styles;
104
- var _default = styles;
105
- exports["default"] = _default;
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- var _computed = _interopRequireDefault(require("../computed"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
-
7
- describe('computed', function () {
8
- var exampleCfg = {
9
- sum: function sum(_ref) {
10
- var x = _ref.x,
11
- y = _ref.y,
12
- z = _ref.z;
13
- return x + y + z;
14
- },
15
- product: function product(_ref2) {
16
- var x = _ref2.x,
17
- y = _ref2.y,
18
- z = _ref2.z;
19
- return x * y * z;
20
- }
21
- };
22
- var exampleProps = {
23
- x: 2,
24
- y: 3,
25
- z: 4
26
- };
27
- test('should add new props to updated object', function () {
28
- var props = {
29
- value: true
30
- };
31
- var cfg = {
32
- count: function count() {
33
- return 1;
34
- }
35
- };
36
- var updated = (0, _computed["default"])(cfg, props);
37
- var expected = 1;
38
- var actual = updated.count;
39
- expect(actual).toBe(expected);
40
- });
41
- test('should overwrite properties with computed values', function () {
42
- var props = {
43
- value: true,
44
- count: 2
45
- };
46
- var cfg = {
47
- count: function count() {
48
- return 1;
49
- }
50
- };
51
- var updated = (0, _computed["default"])(cfg, props);
52
- var expected = 1;
53
- var actual = updated.count;
54
- expect(actual).toBe(expected);
55
- });
56
- test('should not leak updated prop values into other computed props', function () {
57
- var props = {
58
- count: 1
59
- };
60
- var cfg = {
61
- value: function value(_ref3) {
62
- var count = _ref3.count;
63
- return count + 5;
64
- },
65
- count: function count(_ref4) {
66
- var _count = _ref4.count;
67
- return _count + 1;
68
- }
69
- };
70
- var updated = (0, _computed["default"])(cfg, props);
71
- var expected = 6;
72
- var actual = updated.value;
73
- expect(actual).toBe(expected);
74
- });
75
- test('should work with its documented example - sum', function () {
76
- var updated = (0, _computed["default"])(exampleCfg, exampleProps);
77
- var expected = 9;
78
- var actual = updated.sum;
79
- expect(actual).toBe(expected);
80
- });
81
- test('should work with its documented example - product', function () {
82
- var updated = (0, _computed["default"])(exampleCfg, exampleProps);
83
- var expected = 24;
84
- var actual = updated.product;
85
- expect(actual).toBe(expected);
86
- });
87
- });
@@ -1,216 +0,0 @@
1
- "use strict";
2
-
3
- var _react = _interopRequireDefault(require("react"));
4
-
5
- var _propTypes = _interopRequireDefault(require("prop-types"));
6
-
7
- var _enzyme = require("enzyme");
8
-
9
- var _kind = _interopRequireDefault(require("../kind"));
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
-
13
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
14
-
15
- 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."); }
16
-
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
-
19
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
20
-
21
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
22
-
23
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
24
-
25
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
26
-
27
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
28
-
29
- describe('kind', function () {
30
- var TestContext = /*#__PURE__*/_react["default"].createContext({
31
- value: 'initial'
32
- });
33
-
34
- var Kind = (0, _kind["default"])({
35
- name: 'Kind',
36
- propTypes: {
37
- prop: _propTypes["default"].number.isRequired,
38
- label: _propTypes["default"].string
39
- },
40
- defaultProps: {
41
- label: 'Label'
42
- },
43
- contextType: TestContext,
44
- styles: {
45
- className: 'kind'
46
- },
47
- handlers: {
48
- onClick: function onClick(ev, props, context) {
49
- props.onClick(context.value);
50
- }
51
- },
52
- computed: {
53
- value: function value(_ref) {
54
- var prop = _ref.prop;
55
- return prop + 1;
56
- },
57
- contextValue: function contextValue(props, context) {
58
- return context ? "context".concat(context.value) : 'unknown';
59
- }
60
- },
61
- render: function render(_ref2) {
62
- var contextValue = _ref2.contextValue,
63
- label = _ref2.label,
64
- value = _ref2.value,
65
- rest = _objectWithoutProperties(_ref2, ["contextValue", "label", "value"]);
66
-
67
- delete rest.prop;
68
- return /*#__PURE__*/_react["default"].createElement("div", Object.assign({}, rest, {
69
- title: label,
70
- "data-context": contextValue
71
- }), value);
72
- }
73
- });
74
- test('should assign name to displayName', function () {
75
- var expected = 'Kind';
76
- var actual = Kind.displayName;
77
- expect(actual).toBe(expected);
78
- });
79
- test('should support undefined handlers', function () {
80
- var Minimal = (0, _kind["default"])({
81
- name: 'Minimal',
82
- render: function render() {
83
- return /*#__PURE__*/_react["default"].createElement("div", null);
84
- }
85
- });
86
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Minimal, null));
87
- var actual = subject.find('div');
88
- expect(actual).toBeDefined();
89
- });
90
- test('should default {label} property', function () {
91
- var subject = /*#__PURE__*/_react["default"].createElement(Kind, {
92
- prop: 1
93
- });
94
-
95
- var expected = 'Label';
96
- var actual = subject.props.label;
97
- expect(actual).toBe(expected);
98
- });
99
- test('should default {label} property when explicitly undefined', function () {
100
- // Explicitly testing for undefined
101
- // eslint-disable-next-line no-undefined
102
- var subject = /*#__PURE__*/_react["default"].createElement(Kind, {
103
- prop: 1,
104
- label: undefined
105
- });
106
-
107
- var expected = 'Label';
108
- var actual = subject.props.label;
109
- expect(actual).toBe(expected);
110
- });
111
- test('should add className defined in styles', function () {
112
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Kind, {
113
- prop: 1
114
- }));
115
- var expected = 'kind';
116
- var actual = subject.find('div').prop('className');
117
- expect(actual).toBe(expected);
118
- });
119
- test('should compute {value} property', function () {
120
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Kind, {
121
- prop: 1
122
- }));
123
- var expected = 2;
124
- var actual = subject.find('div').prop('children');
125
- expect(actual).toBe(expected);
126
- });
127
- test('should support contextType in handlers', function () {
128
- var onClick = jest.fn();
129
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Kind, {
130
- prop: 1,
131
- onClick: onClick
132
- }));
133
- subject.find('div').invoke('onClick')();
134
- var expected = 'initial';
135
- var actual = onClick.mock.calls[0][0];
136
- expect(actual).toBe(expected);
137
- });
138
- test('should support contextType in computed', function () {
139
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Kind, {
140
- prop: 1
141
- }));
142
- var expected = 'contextinitial';
143
- var actual = subject.find('div').prop('data-context');
144
- expect(actual).toBe(expected);
145
- });
146
- test('support using hooks within kind instances', function () {
147
- var Comp = (0, _kind["default"])({
148
- name: 'Comp',
149
- functional: true,
150
- render: function render() {
151
- // eslint-disable-next-line react-hooks/rules-of-hooks
152
- var _React$useState = _react["default"].useState(0),
153
- _React$useState2 = _slicedToArray(_React$useState, 2),
154
- state = _React$useState2[0],
155
- setState = _React$useState2[1]; // eslint-disable-next-line react/jsx-no-bind
156
-
157
-
158
- return /*#__PURE__*/_react["default"].createElement("button", {
159
- onClick: function onClick() {
160
- return setState(state + 1);
161
- }
162
- }, state);
163
- }
164
- });
165
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Comp, null));
166
- subject.find('button').invoke('onClick')();
167
- var expected = 1;
168
- var actual = subject.find('button').prop('children');
169
- expect(actual).toBe(expected);
170
- });
171
- describe('inline', function () {
172
- test('should support a minimal kind', function () {
173
- var Minimal = (0, _kind["default"])({
174
- name: 'Minimal',
175
- render: function render() {
176
- return /*#__PURE__*/_react["default"].createElement("div", null);
177
- }
178
- });
179
- var component = Minimal.inline();
180
- var expected = 'div';
181
- var actual = component.type;
182
- expect(actual).toBe(expected);
183
- });
184
- test('should set default props when prop is not passed', function () {
185
- var component = Kind.inline(); // since we're inlining the output, we have to reference where the label prop lands --
186
- // the title prop of the <div> -- rather than the label prop on the component (which
187
- // doesn't exist due to inlining).
188
-
189
- var expected = 'Label';
190
- var actual = component.props.title;
191
- expect(actual).toBe(expected);
192
- });
193
- test('should set default props when passed prop is undefined', function () {
194
- var component = Kind.inline({
195
- // explicitly testing settings undefined in this test case
196
- // eslint-disable-next-line no-undefined
197
- label: undefined
198
- });
199
- var expected = 'Label';
200
- var actual = component.props.title;
201
- expect(actual).toBe(expected);
202
- });
203
- test('should include handlers', function () {
204
- var component = Kind.inline();
205
- var expected = 'function';
206
- var actual = typeof component.props.onClick;
207
- expect(actual).toBe(expected);
208
- });
209
- test('should not support context', function () {
210
- var component = Kind.inline();
211
- var expected = 'unknown';
212
- var actual = component.props['data-context'];
213
- expect(actual).toBe(expected);
214
- });
215
- });
216
- });