@enact/core 4.6.1 → 4.7.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 +11 -1
- package/README.md +1 -1
- package/dispatcher/dispatcher.d.ts +21 -0
- package/handle/handle.d.ts +618 -0
- package/handle/handle.js +21 -21
- package/handle/tests/handle-specs.js +102 -1
- package/hoc/hoc.d.ts +43 -0
- package/hoc/tests/hoc-specs.js +3 -1
- package/index.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.d.ts +0 -0
- package/internal/ApiDecorator/ApiDecorator.js +10 -4
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +3 -1
- package/internal/Registry/Registry.d.ts +0 -0
- package/internal/Registry/tests/Registry-specs.js +4 -2
- package/internal/deprecate/deprecate.d.ts +0 -0
- package/internal/prop-types/prop-types.d.ts +0 -0
- package/internal/prop-types/tests/prop-types-specs.js +3 -1
- package/keymap/index.d.ts +37 -0
- package/kind/kind.d.ts +126 -0
- package/kind/kind.js +24 -15
- package/kind/tests/kind-specs.js +5 -3
- package/package.json +1 -1
- package/platform/platform.d.ts +45 -0
- package/platform/platform.js +18 -2
- package/platform/tests/platform-specs.js +10 -0
- package/snapshot/snapshot.d.ts +30 -0
- package/useChainRefs/tests/useChainRefs-specs.js +1 -1
- package/useChainRefs/useChainRefs.d.ts +0 -0
- package/useClass/tests/useClass-specs.js +3 -1
- package/useClass/useClass.d.ts +0 -0
- package/useHandlers/Handlers.js +3 -1
- package/useHandlers/tests/useHandlers-specs.js +3 -1
- package/useHandlers/useHandlers.d.ts +0 -0
- package/usePublicClassNames/usePublicClassNames.d.ts +0 -0
- package/util/Job.js +121 -1
- package/util/util.d.ts +162 -0
package/handle/handle.js
CHANGED
|
@@ -815,34 +815,34 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
|
|
|
815
815
|
*/
|
|
816
816
|
exports.forwardCustom = forwardCustom;
|
|
817
817
|
var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) {
|
|
818
|
-
|
|
819
|
-
var adapterWithPrevent = function adapterWithPrevent(ev) {
|
|
818
|
+
return function (ev) {
|
|
820
819
|
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
821
820
|
args[_key8 - 1] = arguments[_key8];
|
|
822
821
|
}
|
|
823
|
-
var
|
|
824
|
-
var
|
|
822
|
+
var prevented = false;
|
|
823
|
+
var adapterWithPrevent = function adapterWithPrevent() {
|
|
824
|
+
var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
|
|
825
|
+
var existingPreventDefault = null;
|
|
825
826
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
customEventPayload.preventDefault = function () {
|
|
836
|
-
prevented = true;
|
|
837
|
-
if (typeof existingPreventDefault === 'function') {
|
|
838
|
-
existingPreventDefault();
|
|
827
|
+
// Handle either no adapter or a non-object return from the adapter
|
|
828
|
+
if (!customEventPayload || typeof customEventPayload !== 'object') {
|
|
829
|
+
customEventPayload = {};
|
|
830
|
+
}
|
|
831
|
+
if (typeof customEventPayload.preventDefault === 'function') {
|
|
832
|
+
existingPreventDefault = customEventPayload.preventDefault;
|
|
833
|
+
} else if (typeof (ev === null || ev === void 0 ? void 0 : ev.preventDefault) === 'function') {
|
|
834
|
+
existingPreventDefault = ev.preventDefault.bind(ev);
|
|
839
835
|
}
|
|
836
|
+
customEventPayload.preventDefault = function () {
|
|
837
|
+
prevented = true;
|
|
838
|
+
if (typeof existingPreventDefault === 'function') {
|
|
839
|
+
existingPreventDefault(ev);
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
return customEventPayload;
|
|
840
843
|
};
|
|
841
|
-
return
|
|
844
|
+
return forwardCustom(name, adapterWithPrevent).apply(void 0, [ev].concat(args)) && !prevented;
|
|
842
845
|
};
|
|
843
|
-
return handle(forwardCustom(name, adapterWithPrevent), function () {
|
|
844
|
-
return !prevented;
|
|
845
|
-
});
|
|
846
846
|
}, 'forwardCustomWithPrevent');
|
|
847
847
|
|
|
848
848
|
/**
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
var _handle = require("../handle");
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
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; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
9
|
describe('handle', function () {
|
|
8
10
|
var makeEvent = function makeEvent(payload) {
|
|
9
11
|
return _objectSpread({
|
|
@@ -444,4 +446,103 @@ describe('handle', function () {
|
|
|
444
446
|
expect(actual).toEqual(expected);
|
|
445
447
|
});
|
|
446
448
|
});
|
|
449
|
+
describe('#forwardCustomWithPrevent', function () {
|
|
450
|
+
test('should pass an object with `type` and `preventDefault` when no adapter is provided', function () {
|
|
451
|
+
var handler = jest.fn();
|
|
452
|
+
(0, _handle.forwardCustomWithPrevent)('onCustomEvent')(null, {
|
|
453
|
+
onCustomEvent: handler
|
|
454
|
+
});
|
|
455
|
+
var actual = handler.mock.calls[0][0];
|
|
456
|
+
expect(actual).toEqual(expect.objectContaining({
|
|
457
|
+
type: 'onCustomEvent',
|
|
458
|
+
preventDefault: expect.any(Function)
|
|
459
|
+
}));
|
|
460
|
+
});
|
|
461
|
+
test('should add `type` and `preventDefault` to object returned by adapter', function () {
|
|
462
|
+
var handler = jest.fn();
|
|
463
|
+
var adapter = function adapter() {
|
|
464
|
+
return {
|
|
465
|
+
index: 0
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, {
|
|
469
|
+
onCustomEvent: handler
|
|
470
|
+
});
|
|
471
|
+
var actual = handler.mock.calls[0][0];
|
|
472
|
+
expect(actual).toEqual(expect.objectContaining({
|
|
473
|
+
type: 'onCustomEvent',
|
|
474
|
+
preventDefault: expect.any(Function),
|
|
475
|
+
index: 0
|
|
476
|
+
}));
|
|
477
|
+
});
|
|
478
|
+
test('should create an event payload if the adapter returns nothing', function () {
|
|
479
|
+
var handler = jest.fn();
|
|
480
|
+
var adapter = function adapter() {
|
|
481
|
+
return null;
|
|
482
|
+
};
|
|
483
|
+
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, {
|
|
484
|
+
onCustomEvent: handler
|
|
485
|
+
});
|
|
486
|
+
var actual = handler.mock.calls[0][0];
|
|
487
|
+
expect(actual).toEqual(expect.objectContaining({
|
|
488
|
+
type: 'onCustomEvent',
|
|
489
|
+
preventDefault: expect.any(Function)
|
|
490
|
+
}));
|
|
491
|
+
});
|
|
492
|
+
test('should pass an object with `preventDefault` and `stopPropagation` when event has them', function () {
|
|
493
|
+
var ev = {
|
|
494
|
+
preventDefault: jest.fn(),
|
|
495
|
+
stopPropagation: function stopPropagation() {}
|
|
496
|
+
};
|
|
497
|
+
var handler = jest.fn();
|
|
498
|
+
var adapter = function adapter() {
|
|
499
|
+
return null;
|
|
500
|
+
};
|
|
501
|
+
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(ev, {
|
|
502
|
+
onCustomEvent: handler
|
|
503
|
+
});
|
|
504
|
+
var actual = handler.mock.calls[0][0];
|
|
505
|
+
expect(actual).toEqual(expect.objectContaining({
|
|
506
|
+
type: 'onCustomEvent',
|
|
507
|
+
preventDefault: expect.any(Function),
|
|
508
|
+
stopPropagation: expect.any(Function)
|
|
509
|
+
}));
|
|
510
|
+
actual.preventDefault();
|
|
511
|
+
expect(ev.preventDefault).toHaveBeenCalled();
|
|
512
|
+
});
|
|
513
|
+
test('should pass event, props, and context args to adapter', function () {
|
|
514
|
+
var adapter = jest.fn();
|
|
515
|
+
var args = [1,
|
|
516
|
+
// ev,
|
|
517
|
+
2,
|
|
518
|
+
// props,
|
|
519
|
+
3 // context
|
|
520
|
+
];
|
|
521
|
+
|
|
522
|
+
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter).apply(void 0, args);
|
|
523
|
+
var expected = args;
|
|
524
|
+
var actual = adapter.mock.calls[0];
|
|
525
|
+
expect(actual).toEqual(expected);
|
|
526
|
+
});
|
|
527
|
+
test('should call the next handler when `preventDefault` from provided props hasn\'t been called', function () {
|
|
528
|
+
var event = 'onMyClick';
|
|
529
|
+
var handler = jest.fn();
|
|
530
|
+
var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler);
|
|
531
|
+
callback();
|
|
532
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
533
|
+
});
|
|
534
|
+
test('should not call the next handler when `preventDefault` from provided props has been called', function () {
|
|
535
|
+
var event = 'onMyClick';
|
|
536
|
+
var handler = jest.fn();
|
|
537
|
+
var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler);
|
|
538
|
+
|
|
539
|
+
// should stop chain when `preventDefault()` has been called
|
|
540
|
+
callback({}, {
|
|
541
|
+
'onMyClick': function onMyClick(ev) {
|
|
542
|
+
return ev.preventDefault();
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
expect(handler).not.toHaveBeenCalled();
|
|
546
|
+
});
|
|
547
|
+
});
|
|
447
548
|
});
|
package/hoc/hoc.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Type definitions for core/hoc
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a higher-order component (HOC) using an optional set of default configuration parameters and
|
|
8
|
+
a factory method that accepts instance configuration parameters and a component to wrap. The
|
|
9
|
+
returned function can accept:
|
|
10
|
+
* * an instance config and a component constructor to wrap and return a renderable component, or
|
|
11
|
+
* * an instance config only and return a decorator function expecting a component constructor
|
|
12
|
+
(like the next bullet), or
|
|
13
|
+
* * a component constructor and return a renderable component
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```
|
|
17
|
+
const Countable = hoc({prop: 'data-count'}, (config, Wrapped) => {
|
|
18
|
+
return class extends React.Component {
|
|
19
|
+
constructor (props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.state = {
|
|
22
|
+
count: 0
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
inc = () => this.setState({count: this.state.count + 1}),
|
|
26
|
+
render () {
|
|
27
|
+
const props = Object.assign({}, this.props, {
|
|
28
|
+
[config.prop]: this.state.count,
|
|
29
|
+
onClick: this.inc
|
|
30
|
+
});
|
|
31
|
+
return <Wrapped {...props} />
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const CountableAsDataNumber({prop: 'data-number'});
|
|
37
|
+
const CountableDiv('div');
|
|
38
|
+
const CountableDivAsDataNumber = CountableAsDataNumber('div');
|
|
39
|
+
```
|
|
40
|
+
*/
|
|
41
|
+
export function hoc(defaultConfig: object, hawk: Function): Function;
|
|
42
|
+
|
|
43
|
+
export default hoc;
|
package/hoc/tests/hoc-specs.js
CHANGED
|
@@ -7,7 +7,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
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; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable enact/display-name */
|
|
11
13
|
describe('hoc', function () {
|
|
12
14
|
var data;
|
|
13
15
|
var testID = 'test-HoC';
|
package/index.d.ts
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -11,18 +11,24 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
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; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
15
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
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); } }
|
|
16
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
17
17
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
20
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
21
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
22
|
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); }; }
|
|
21
23
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
22
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
25
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
24
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
25
|
-
|
|
26
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**
|
|
27
|
+
* Provides the `ApiDecorator` higher-order component
|
|
28
|
+
*
|
|
29
|
+
* @module core/internal/ApiDecorator
|
|
30
|
+
* @private
|
|
31
|
+
*/ // Gets a property from `provider`
|
|
26
32
|
var get = function get(provider, name) {
|
|
27
33
|
return function () {
|
|
28
34
|
if (provider) {
|
|
@@ -6,8 +6,10 @@ var _ApiDecorator = _interopRequireDefault(require("../ApiDecorator"));
|
|
|
6
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
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); } }
|
|
9
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
13
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
14
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
13
15
|
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); }; }
|
|
File without changes
|
|
@@ -9,10 +9,12 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
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; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
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); } }
|
|
14
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
15
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
18
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
19
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
20
|
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); }; }
|
|
File without changes
|
|
File without changes
|
|
@@ -7,8 +7,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
8
|
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
|
|
9
9
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
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); } }
|
|
10
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
11
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
14
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
15
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
16
|
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); }; }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Type definitions for core/keymap
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers `keyCode` for `name` .
|
|
8
|
+
*/
|
|
9
|
+
export function add(name: string, keyCode: number | number[]): void;
|
|
10
|
+
/**
|
|
11
|
+
* Registers `keyCode` for `name` .
|
|
12
|
+
*/
|
|
13
|
+
export function add(name: string): (keyCode: number | number[]) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a set of key codes.
|
|
16
|
+
*/
|
|
17
|
+
export function addAll(set: { [key: string]: number | number[] }): void;
|
|
18
|
+
/**
|
|
19
|
+
* Unregisters `keyCode` from `name` .
|
|
20
|
+
*/
|
|
21
|
+
export function remove(name: string, keyCode: number | number[]): void;
|
|
22
|
+
/**
|
|
23
|
+
* Unregisters `keyCode` from `name` .
|
|
24
|
+
*/
|
|
25
|
+
export function remove(name: string): (keyCode: number | number[]) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Unregisters a set of key codes.
|
|
28
|
+
*/
|
|
29
|
+
export function removeAll(set: object): void;
|
|
30
|
+
/**
|
|
31
|
+
* Determines if `keyCode` is mapped to `name` .
|
|
32
|
+
*/
|
|
33
|
+
export function is(name: string, keyCode: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Determines if `keyCode` is mapped to `name` .
|
|
36
|
+
*/
|
|
37
|
+
export function is(name: string): (keyCode: number) => boolean;
|
package/kind/kind.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Type definitions for core/kind
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
export interface RenderFunction {
|
|
7
|
+
(props: { [key: string]: any }, context: { [key: string]: any }): any;
|
|
8
|
+
}
|
|
9
|
+
export interface ComputedPropFunction {
|
|
10
|
+
(props: { [key: string]: any }, context: { [key: string]: any }): any;
|
|
11
|
+
}
|
|
12
|
+
export interface HandlerFunction {
|
|
13
|
+
(
|
|
14
|
+
event: any,
|
|
15
|
+
props: { [key: string]: any },
|
|
16
|
+
context: { [key: string]: any }
|
|
17
|
+
): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for CSS class name mapping
|
|
21
|
+
*/
|
|
22
|
+
export interface StylesBlock {
|
|
23
|
+
/**
|
|
24
|
+
* The CSS of the component
|
|
25
|
+
*/
|
|
26
|
+
css: { [key: string]: string }
|
|
27
|
+
/**
|
|
28
|
+
* The className of the component
|
|
29
|
+
*/;
|
|
30
|
+
className?: string /**
|
|
31
|
+
* Specifies which class names are overridable.
|
|
32
|
+
If this value is `true` , all of the class names of the component CSS will become public.
|
|
33
|
+
*/;
|
|
34
|
+
publicClassNames?: boolean | string | string[];
|
|
35
|
+
}
|
|
36
|
+
export interface KindConfig {
|
|
37
|
+
/**
|
|
38
|
+
* The name of the component
|
|
39
|
+
*/
|
|
40
|
+
name?: string
|
|
41
|
+
/**
|
|
42
|
+
* Boolean controlling whether the returned component should be a functional component
|
|
43
|
+
*/;
|
|
44
|
+
functional?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* Specifies expected props
|
|
47
|
+
*/;
|
|
48
|
+
propTypes?: { [key: string]: Function }
|
|
49
|
+
/**
|
|
50
|
+
* Sets the default props
|
|
51
|
+
*/;
|
|
52
|
+
defaultProps?: { [key: string]: any }
|
|
53
|
+
/**
|
|
54
|
+
* Specifies context type
|
|
55
|
+
*/;
|
|
56
|
+
contextType?: object
|
|
57
|
+
/**
|
|
58
|
+
* Configures styles with the static className to merge with user className
|
|
59
|
+
*/;
|
|
60
|
+
styles?: StylesBlock /**
|
|
61
|
+
* Adds event handlers that are cached between calls to prevent recreating each call.
|
|
62
|
+
Any handlers are added to the props passed to `render()` . See .
|
|
63
|
+
*/;
|
|
64
|
+
handlers?: { [key: string]: HandlerFunction }
|
|
65
|
+
/**
|
|
66
|
+
* Adds some computed properties, these are added to props passed to `render()`
|
|
67
|
+
*/;
|
|
68
|
+
computed?: { [key: string]: ComputedPropFunction }
|
|
69
|
+
/**
|
|
70
|
+
* The render function
|
|
71
|
+
*/;
|
|
72
|
+
render: RenderFunction;
|
|
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
|
+
const Button = kind({
|
|
81
|
+
name: 'Button',
|
|
82
|
+
// Return a functional component
|
|
83
|
+
functional: true,
|
|
84
|
+
// expect color and onClick properties but neither required
|
|
85
|
+
propTypes: {
|
|
86
|
+
color: PropTypes.string
|
|
87
|
+
},
|
|
88
|
+
// if no color is provided, it'll be green
|
|
89
|
+
defaultProps: {
|
|
90
|
+
color: 'green'
|
|
91
|
+
},
|
|
92
|
+
// expect backgroundColor via context
|
|
93
|
+
contextType: React.createContext({ backgroundColor }),
|
|
94
|
+
// configure styles with the static className to merge with user className
|
|
95
|
+
styles: {
|
|
96
|
+
// include the CSS modules map so 'button' can be resolved to the local name
|
|
97
|
+
css,
|
|
98
|
+
className: 'button'
|
|
99
|
+
},
|
|
100
|
+
// add event handlers that are cached between calls to prevent recreating each call. Any
|
|
101
|
+
// handlers are added to the props passed to `render()`. See core/handle.
|
|
102
|
+
handlers: {
|
|
103
|
+
onKeyDown: (evt, props) => { .... }
|
|
104
|
+
},
|
|
105
|
+
// add some computed properties, these are added to props passed to `render()`
|
|
106
|
+
computed: {
|
|
107
|
+
// border color will be the color prepended by 'light'
|
|
108
|
+
borderColor: ({color}) => 'light' + color,
|
|
109
|
+
// background color will be the contextual background color if specified
|
|
110
|
+
color: ({color}, context) => context.backgroundColor || color
|
|
111
|
+
},
|
|
112
|
+
// Render the thing, already!
|
|
113
|
+
render: ({color, borderColor, children, ...rest}) => (
|
|
114
|
+
<button
|
|
115
|
+
{...rest}
|
|
116
|
+
style={{backgroundColor: color, borderColor}}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</button>
|
|
120
|
+
)
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
*/
|
|
124
|
+
export function kind<Props>(config: KindConfig): React.ComponentType<Props>;
|
|
125
|
+
|
|
126
|
+
export default kind;
|
package/kind/kind.js
CHANGED
|
@@ -11,7 +11,7 @@ var _computed = _interopRequireDefault(require("./computed"));
|
|
|
11
11
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
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); } }
|
|
14
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
15
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
16
|
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
17
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
@@ -22,7 +22,14 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
22
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
23
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
24
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
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; }
|
|
25
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
26
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
27
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
|
|
28
|
+
* Provides the {@link core/kind.kind} method to create components
|
|
29
|
+
*
|
|
30
|
+
* @module core/kind
|
|
31
|
+
* @exports kind
|
|
32
|
+
*/
|
|
26
33
|
// Because contextType is optional and hooks must be called in the same order, we need a fallback
|
|
27
34
|
// context when none is specified. This likely has some overhead so we may want to deprecate and
|
|
28
35
|
// remove contextType support for 4.0 since the context APIs have improved since this was added.
|
|
@@ -57,23 +64,25 @@ var NoContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
|
57
64
|
*
|
|
58
65
|
* @typedef {Object} StylesBlock
|
|
59
66
|
* @memberof core/kind
|
|
60
|
-
* @property {Object.<string, string>} css
|
|
61
|
-
* @property {String} [className]
|
|
62
|
-
* @property {Boolean|String|String[]} [publicClassNames]
|
|
67
|
+
* @property {Object.<string, string>} css The CSS of the component
|
|
68
|
+
* @property {String} [className] The className of the component
|
|
69
|
+
* @property {Boolean|String|String[]} [publicClassNames] Specifies which class names are overridable.
|
|
70
|
+
* If this value is `true`, all of the class names of the component CSS will become public.
|
|
63
71
|
*/
|
|
64
72
|
|
|
65
73
|
/**
|
|
66
74
|
* @typedef {Object} KindConfig
|
|
67
75
|
* @memberof core/kind
|
|
68
|
-
* @property {String} [name]
|
|
69
|
-
* @property {Boolean} [functional]
|
|
70
|
-
* @property {Object.<string, Function>} [propTypes]
|
|
71
|
-
* @property {Object.<string, any>} [defaultProps]
|
|
72
|
-
* @property {Object} [contextType]
|
|
73
|
-
* @property {StylesBlock} [styles]
|
|
74
|
-
* @property {Object.<string, HandlerFunction>} [handlers]
|
|
75
|
-
*
|
|
76
|
-
* @property {
|
|
76
|
+
* @property {String} [name] The name of the component
|
|
77
|
+
* @property {Boolean} [functional] Boolean controlling whether the returned component should be a functional component
|
|
78
|
+
* @property {Object.<string, Function>} [propTypes] Specifies expected props
|
|
79
|
+
* @property {Object.<string, any>} [defaultProps] Sets the default props
|
|
80
|
+
* @property {Object} [contextType] Specifies context type
|
|
81
|
+
* @property {StylesBlock} [styles] Configures styles with the static className to merge with user className
|
|
82
|
+
* @property {Object.<string, HandlerFunction>} [handlers] Adds event handlers that are cached between calls to prevent recreating each call.
|
|
83
|
+
* Any handlers are added to the props passed to `render()`. See {@link core/handle.handle}.
|
|
84
|
+
* @property {Object.<string, ComputedPropFunction>} [computed] Adds some computed properties, these are added to props passed to `render()`
|
|
85
|
+
* @property {RenderFunction} render The render function
|
|
77
86
|
*/
|
|
78
87
|
|
|
79
88
|
/**
|
|
@@ -84,7 +93,7 @@ var NoContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
|
84
93
|
* import css from './Button.module.less';
|
|
85
94
|
* const Button = kind({
|
|
86
95
|
* name: 'Button',
|
|
87
|
-
* // Return a functional component
|
|
96
|
+
* // Return a functional component
|
|
88
97
|
* functional: true,
|
|
89
98
|
* // expect color and onClick properties but neither required
|
|
90
99
|
* propTypes: {
|
package/kind/tests/kind-specs.js
CHANGED
|
@@ -12,12 +12,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
12
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
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
14
|
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); }
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
16
|
-
function _iterableToArrayLimit(arr, i) { var _i =
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
18
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
19
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
|
-
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; }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
22
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
23
|
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; }
|
|
22
24
|
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; }
|
|
23
25
|
describe('kind', function () {
|
package/package.json
CHANGED