1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _react = _interopRequireDefault(require("react"));
|
9 |
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 |
|
12 | var _button = _interopRequireDefault(require("../button"));
|
13 |
|
14 | var _util = require("../util");
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
17 |
|
18 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
19 |
|
20 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
21 |
|
22 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
23 |
|
24 | 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); } }
|
25 |
|
26 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
27 |
|
28 | 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); }
|
29 |
|
30 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
31 |
|
32 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { 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); }; }
|
33 |
|
34 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
35 |
|
36 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
37 |
|
38 | 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; } }
|
39 |
|
40 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
41 |
|
42 | 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; }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | var Reset = function (_React$Component) {
|
50 | _inherits(Reset, _React$Component);
|
51 |
|
52 | var _super = _createSuper(Reset);
|
53 |
|
54 | function Reset() {
|
55 | var _this;
|
56 |
|
57 | _classCallCheck(this, Reset);
|
58 |
|
59 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
60 | args[_key] = arguments[_key];
|
61 | }
|
62 |
|
63 | _this = _super.call.apply(_super, [this].concat(args));
|
64 |
|
65 | _defineProperty(_assertThisInitialized(_this), "handleClick", function () {
|
66 | var _this$props = _this.props,
|
67 | names = _this$props.names,
|
68 | toDefault = _this$props.toDefault,
|
69 | onClick = _this$props.onClick;
|
70 | var field = _this.context._formField || _this.props.field;
|
71 |
|
72 | if (!field) {
|
73 | _util.log.warning('Form.Reset should be used in `Form`');
|
74 |
|
75 | onClick();
|
76 | return;
|
77 | }
|
78 |
|
79 | if (toDefault) {
|
80 | field.resetToDefault(names);
|
81 | } else {
|
82 | field.reset(names);
|
83 | }
|
84 |
|
85 | onClick();
|
86 | });
|
87 |
|
88 | return _this;
|
89 | }
|
90 |
|
91 | _createClass(Reset, [{
|
92 | key: "render",
|
93 | value: function render() {
|
94 | var children = this.props.children;
|
95 | return _react["default"].createElement(_button["default"], _extends({}, _util.obj.pickOthers(Reset.propTypes, this.props), {
|
96 | onClick: this.handleClick
|
97 | }), children);
|
98 | }
|
99 | }]);
|
100 |
|
101 | return Reset;
|
102 | }(_react["default"].Component);
|
103 |
|
104 | _defineProperty(Reset, "propTypes", {
|
105 | |
106 |
|
107 |
|
108 | names: _propTypes["default"].array,
|
109 |
|
110 | |
111 |
|
112 |
|
113 | onClick: _propTypes["default"].func,
|
114 |
|
115 | |
116 |
|
117 |
|
118 | toDefault: _propTypes["default"].bool,
|
119 |
|
120 | |
121 |
|
122 |
|
123 | field: _propTypes["default"].object,
|
124 | children: _propTypes["default"].node
|
125 | });
|
126 |
|
127 | _defineProperty(Reset, "defaultProps", {
|
128 | onClick: _util.func.noop
|
129 | });
|
130 |
|
131 | _defineProperty(Reset, "contextTypes", {
|
132 | _formField: _propTypes["default"].object
|
133 | });
|
134 |
|
135 | var _default = Reset;
|
136 | exports["default"] = _default; |
\ | No newline at end of file |