linear-react-components-ui 0.4.76-rc.1 → 0.4.76-rc.5

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 (71) hide show
  1. package/lib/alerts/AlertProvider.js +1 -1
  2. package/lib/alerts/BaseAlert.js +1 -1
  3. package/lib/buttons/DefaultButton.js +1 -1
  4. package/lib/buttons/index.js +28 -28
  5. package/lib/calendar/base/helpers.js +6 -6
  6. package/lib/calendar/base/index.js +1 -1
  7. package/lib/calendar/index.js +10 -10
  8. package/lib/checkbox/index.js +1 -1
  9. package/lib/dialog/base/index.js +1 -1
  10. package/lib/dialog/index.js +6 -6
  11. package/lib/drawer/Drawer.js +1 -1
  12. package/lib/drawer/index.js +4 -4
  13. package/lib/dropdown/withDropdown.js +2 -2
  14. package/lib/fieldset/index.js +1 -1
  15. package/lib/form/Field.js +1 -1
  16. package/lib/form/helpers.js +1 -1
  17. package/lib/form/index.js +204 -278
  18. package/lib/form/withFieldHOC.js +1 -1
  19. package/lib/form/withFormSecurity.js +10 -10
  20. package/lib/index.js +12 -12
  21. package/lib/inputs/base/InputTextBase.js +1 -1
  22. package/lib/inputs/base/helpers.js +1 -1
  23. package/lib/inputs/color/index.js +1 -1
  24. package/lib/inputs/date/Dropdown.js +1 -1
  25. package/lib/inputs/date/index.js +1 -1
  26. package/lib/inputs/inputHOC.js +1 -1
  27. package/lib/inputs/mask/Cnpj.js +1 -1
  28. package/lib/inputs/mask/Cpf.js +1 -1
  29. package/lib/inputs/mask/helpers.js +2 -2
  30. package/lib/inputs/mask/imaskHOC.js +1 -1
  31. package/lib/inputs/mask/index.js +4 -4
  32. package/lib/inputs/multiSelect/Dropdown.js +1 -1
  33. package/lib/inputs/multiSelect/index.js +1 -1
  34. package/lib/inputs/number/format_number.js +1 -1
  35. package/lib/inputs/period/Dropdown.js +1 -1
  36. package/lib/inputs/period/helper.js +1 -1
  37. package/lib/inputs/period/index.js +1 -1
  38. package/lib/inputs/search/index.js +1 -1
  39. package/lib/inputs/select/Dropdown.js +1 -1
  40. package/lib/inputs/select/helper.js +1 -1
  41. package/lib/inputs/select/multiple/index.js +1 -1
  42. package/lib/inputs/select/simple/index.js +1 -1
  43. package/lib/internals/constants.js +1 -1
  44. package/lib/internals/withTooltip.js +1 -1
  45. package/lib/labelMessages/index.js +1 -1
  46. package/lib/labels/DefaultLabel.js +1 -1
  47. package/lib/labels/index.js +10 -10
  48. package/lib/list/Item.js +1 -1
  49. package/lib/list/index.js +1 -1
  50. package/lib/menus/sidenav/NavMenuItem.js +1 -1
  51. package/lib/menus/sidenav/NavSubMenuItem.js +1 -1
  52. package/lib/menus/sidenav/helpers.js +1 -1
  53. package/lib/menus/sidenav/index.js +9 -9
  54. package/lib/menus/sidenav/popup_menu_search/index.js +1 -1
  55. package/lib/panel/Default.js +1 -1
  56. package/lib/panel/helpers.js +1 -1
  57. package/lib/panel/index.js +14 -14
  58. package/lib/permissionValidations.js +1 -1
  59. package/lib/radio/index.js +1 -1
  60. package/lib/spinner/index.js +1 -1
  61. package/lib/split/Split.js +1 -1
  62. package/lib/table/helpers.js +1 -1
  63. package/lib/table/index.js +9 -9
  64. package/lib/tabs/Panel.js +1 -1
  65. package/lib/tabs/index.js +1 -1
  66. package/lib/tabs/tabHelpers.js +2 -3
  67. package/lib/toolbar/index.js +8 -8
  68. package/lib/treeview/Node.js +1 -1
  69. package/lib/treeview/index.js +1 -1
  70. package/lib/treeview_old/Node.js +1 -1
  71. package/package.json +1 -1
package/lib/form/index.js CHANGED
@@ -11,16 +11,16 @@ Object.defineProperty(exports, "Field", {
11
11
  return _Field["default"];
12
12
  }
13
13
  });
14
- Object.defineProperty(exports, "FieldArray", {
14
+ Object.defineProperty(exports, "FieldNumber", {
15
15
  enumerable: true,
16
16
  get: function get() {
17
- return _FieldArray["default"];
17
+ return _FieldNumber["default"];
18
18
  }
19
19
  });
20
- Object.defineProperty(exports, "FieldNumber", {
20
+ Object.defineProperty(exports, "FieldArray", {
21
21
  enumerable: true,
22
22
  get: function get() {
23
- return _FieldNumber["default"];
23
+ return _FieldArray["default"];
24
24
  }
25
25
  });
26
26
  exports["default"] = void 0;
@@ -45,321 +45,247 @@ var _dialog = require("../dialog");
45
45
 
46
46
  var _withFormSecurity = require("./withFormSecurity");
47
47
 
48
+ var _this = void 0;
49
+
48
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
49
51
 
50
52
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
51
53
 
52
54
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
53
55
 
56
+ 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; }
57
+
58
+ 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); }
59
+
54
60
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
55
61
 
56
62
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
57
63
 
58
- 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); }
59
-
60
64
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
61
65
 
62
66
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
63
67
 
64
- 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; }
68
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
65
69
 
66
- 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; }
70
+ 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."); }
67
71
 
68
- 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); }
72
+ 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); }
69
73
 
70
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
74
+ 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; }
71
75
 
72
- 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); } }
76
+ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
77
+
78
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
79
+
80
+ var Form = function Form(_ref) {
81
+ var submitOnPressEnterKey = _ref.submitOnPressEnterKey,
82
+ dataSource = _ref.dataSource,
83
+ securityBeforeUnload = _ref.securityBeforeUnload,
84
+ handlerReset = _ref.handlerReset,
85
+ handlerSubmit = _ref.handlerSubmit,
86
+ children = _ref.children,
87
+ handlerValidates = _ref.handlerValidates,
88
+ style = _ref.style,
89
+ customClass = _ref.customClass,
90
+ securityTitle = _ref.securityTitle,
91
+ securityText = _ref.securityText,
92
+ onDataChange = _ref.onDataChange,
93
+ onValidateForm = _ref.onValidateForm,
94
+ externalFieldErrors = _ref.externalFieldErrors,
95
+ onSubmit = _ref.onSubmit;
96
+
97
+ var _useState = (0, _react.useState)(dataSource),
98
+ _useState2 = _slicedToArray(_useState, 2),
99
+ data = _useState2[0],
100
+ setData = _useState2[1];
101
+
102
+ var _useState3 = (0, _react.useState)(dataSource),
103
+ _useState4 = _slicedToArray(_useState3, 2),
104
+ originalData = _useState4[0],
105
+ setOriginalData = _useState4[1];
106
+
107
+ var _useState5 = (0, _react.useState)(submitOnPressEnterKey),
108
+ _useState6 = _slicedToArray(_useState5, 2),
109
+ submitFormOnEnter = _useState6[0],
110
+ setSubmitFormOnEnter = _useState6[1];
111
+
112
+ var _useState7 = (0, _react.useState)({}),
113
+ _useState8 = _slicedToArray(_useState7, 2),
114
+ fieldErrors = _useState8[0],
115
+ setFieldErrors = _useState8[1];
116
+
117
+ var _useState9 = (0, _react.useState)({}),
118
+ _useState10 = _slicedToArray(_useState9, 2),
119
+ fieldsValidators = _useState10[0],
120
+ setFieldsValidators = _useState10[1];
121
+
122
+ var context = (0, _react.useContext)(_withFormSecurity.FormSecurityContext);
123
+
124
+ var getValidatesErrorMessages = function getValidatesErrorMessages(validators, fieldValue) {
125
+ var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
126
+ var errors = [];
127
+ validatorsArray.forEach(function (validator) {
128
+ var result = validator(fieldValue);
129
+ if (result) errors = [].concat(_toConsumableArray(errors), [result]);
130
+ });
131
+ return errors;
132
+ };
73
133
 
74
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
134
+ var checkIsValid = function checkIsValid(value) {
135
+ var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
136
+ var dataValidate = value || data;
137
+ var currentFieldErrors = {};
75
138
 
76
- 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); }
139
+ _lodash["default"].forEach(fieldsValidators, function (validators, fieldName) {
140
+ var fieldValue = _lodash["default"].get(dataValidate, fieldName);
77
141
 
78
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
142
+ var messages = getValidatesErrorMessages(validators, fieldValue);
79
143
 
80
- 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); }; }
144
+ if (messages.length > 0) {
145
+ currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
146
+ }
147
+ });
81
148
 
82
- 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); }
149
+ if (updateState) setFieldErrors(currentFieldErrors);
150
+ return _lodash["default"].isEmpty(currentFieldErrors);
151
+ };
83
152
 
84
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
153
+ var onFieldChange = function onFieldChange(e) {
154
+ var _e$target = e.target,
155
+ name = _e$target.name,
156
+ value = _e$target.value;
85
157
 
86
- 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; } }
158
+ var newData = _extends({}, data, _defineProperty({}, name, value));
87
159
 
88
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
160
+ if (context) {
161
+ var onChangedData = context.onChangedData;
89
162
 
90
- var Form = /*#__PURE__*/function (_Component) {
91
- _inherits(Form, _Component);
163
+ if (onChangedData) {
164
+ if (!_lodash["default"].isEqual(newData, originalData)) {
165
+ onChangedData(true);
166
+ } else {
167
+ onChangedData(false);
168
+ }
169
+ }
170
+ }
92
171
 
93
- var _super = _createSuper(Form);
172
+ setData(newData); // TODO - Usar debounce para evitar chamada a cada letra digitada
94
173
 
95
- function Form(props) {
96
- var _this;
174
+ if (onValidateForm) onValidateForm(checkIsValid(newData, false));
175
+ if (onDataChange) onDataChange(newData);
176
+ };
97
177
 
98
- _classCallCheck(this, Form);
178
+ var onValidate = function onValidate(fieldName, fieldValue, validators) {
179
+ if (validators) {
180
+ var currentFieldErrors = fieldErrors;
181
+ var errors = getValidatesErrorMessages(validators, fieldValue);
99
182
 
100
- _this = _super.call(this, props);
101
- Object.defineProperty(_assertThisInitialized(_this), "onBeforeUnload", {
102
- configurable: true,
103
- enumerable: true,
104
- writable: true,
105
- value: function value(e) {
106
- e.preventDefault();
183
+ if (errors.length === 0) {
184
+ currentFieldErrors = _lodash["default"].omit(fieldErrors, fieldName);
185
+ } else {
186
+ currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, errors));
187
+ }
107
188
 
108
- if (Object.is(_this.state.data, _this.state.originalData)) {
109
- return;
110
- }
189
+ setFieldErrors(currentFieldErrors);
190
+ }
191
+ };
111
192
 
112
- e.returnValue = true;
113
- }
114
- });
115
- Object.defineProperty(_assertThisInitialized(_this), "onFieldChange", {
116
- configurable: true,
117
- enumerable: true,
118
- writable: true,
119
- value: function value(e) {
120
- var _this$props = _this.props,
121
- onValidateForm = _this$props.onValidateForm,
122
- onDataChange = _this$props.onDataChange;
123
- var data = _this.state.data;
124
- var _e$target = e.target,
125
- name = _e$target.name,
126
- value = _e$target.value;
127
-
128
- _lodash["default"].set(data, name, value);
129
-
130
- _this.setState({
131
- data: data
132
- });
133
-
134
- if (_this.context.onChangedData) {
135
- var onChangedData = _this.context.onChangedData;
136
-
137
- if (!Object.is(data, _this.state.originalData)) {
138
- onChangedData(true);
139
- } else {
140
- onChangedData(false);
141
- }
142
- } // TODO - Usar debounce para evitar chamada a cada letra digitada
143
-
144
-
145
- if (onValidateForm) onValidateForm(_this.checkIsValid(data, false));
146
- if (onDataChange) onDataChange(data);
147
- }
148
- });
149
- Object.defineProperty(_assertThisInitialized(_this), "onValidate", {
150
- configurable: true,
151
- enumerable: true,
152
- writable: true,
153
- value: function value(fieldName, fieldValue, validators) {
154
- if (validators) {
155
- var fieldErrors = _this.state.fieldErrors;
156
-
157
- var errors = _this.getValidatesErrorMessages(validators, fieldValue);
158
-
159
- if (errors.length === 0) {
160
- fieldErrors = _lodash["default"].omit(fieldErrors, fieldName);
161
- } else {
162
- fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, errors));
163
- }
164
-
165
- _this.setState({
166
- fieldErrors: fieldErrors
167
- });
168
- }
169
- }
170
- });
171
- Object.defineProperty(_assertThisInitialized(_this), "onSubmit", {
172
- configurable: true,
173
- enumerable: true,
174
- writable: true,
175
- value: function value(event) {
176
- if (event) event.preventDefault();
177
- var data = _this.state.data;
178
- if (_this.checkIsValid(data)) _this.props.onSubmit(data);
179
- }
180
- });
181
- Object.defineProperty(_assertThisInitialized(_this), "onReset", {
182
- configurable: true,
183
- enumerable: true,
184
- writable: true,
185
- value: function value() {
186
- _this.setState({
187
- data: JSON.parse(JSON.stringify(_this.state.originalData)),
188
- fieldErrors: {}
189
- });
190
- }
191
- });
192
- Object.defineProperty(_assertThisInitialized(_this), "onRemoveFieldValidators", {
193
- configurable: true,
194
- enumerable: true,
195
- writable: true,
196
- value: function value(fieldName) {
197
- _this.fieldsValidators = _lodash["default"].omit(_this.fieldsValidators, fieldName);
198
- }
199
- });
200
- Object.defineProperty(_assertThisInitialized(_this), "getValidatesErrorMessages", {
201
- configurable: true,
202
- enumerable: true,
203
- writable: true,
204
- value: function value(validators, fieldValue) {
205
- var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
206
- var errors = [];
207
- validatorsArray.forEach(function (validator) {
208
- var result = validator(fieldValue);
209
- if (result) errors = [].concat(_toConsumableArray(errors), [result]);
210
- });
211
- return errors;
212
- }
213
- });
214
- Object.defineProperty(_assertThisInitialized(_this), "getContextValue", {
215
- configurable: true,
216
- enumerable: true,
217
- writable: true,
218
- value: function value() {
219
- return {
220
- handlerFieldChange: _this.onFieldChange,
221
- handlerFieldValidade: _this.onValidate,
222
- handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
223
- _this.fieldsValidators = _extends({}, _this.fieldsValidators, _defineProperty({}, fieldName, fieldValidates));
224
- },
225
- handlerRemoveValidators: _this.onRemoveFieldValidators,
226
- data: _this.state.data,
227
- fieldErrors: _this.state.fieldErrors,
228
- externalFieldErrors: _this.props.externalFieldErrors
229
- };
230
- }
231
- });
232
- Object.defineProperty(_assertThisInitialized(_this), "checkIsValid", {
233
- configurable: true,
234
- enumerable: true,
235
- writable: true,
236
- value: function value(data) {
237
- var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
238
- var dataValidate = data || _this.state.data;
239
- var fieldErrors = {};
240
-
241
- _lodash["default"].forEach(_this.fieldsValidators, function (validators, fieldName) {
242
- var fieldValue = _lodash["default"].get(dataValidate, fieldName);
243
-
244
- var messages = _this.getValidatesErrorMessages(validators, fieldValue);
245
-
246
- if (messages.length > 0) {
247
- fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
248
- }
249
- });
250
-
251
- if (updateState) _this.setState({
252
- fieldErrors: fieldErrors
253
- });
254
- return _lodash["default"].isEmpty(fieldErrors);
255
- }
256
- });
257
- Object.defineProperty(_assertThisInitialized(_this), "submitOnEnter", {
258
- configurable: true,
259
- enumerable: true,
260
- writable: true,
261
- value: function value(event) {
262
- if (event.key === 'Enter') {
263
- event.preventDefault();
264
- if (_this.state.submitFormOnEnter) _this.onSubmit();
265
- }
266
- }
193
+ var onFormSubmit = function onFormSubmit(event) {
194
+ if (event) event.preventDefault();
195
+ if (checkIsValid(data)) onSubmit(data);
196
+ };
197
+
198
+ var onReset = function onReset() {
199
+ _this.setState({
200
+ data: JSON.parse(JSON.stringify(_this.state.originalData)),
201
+ fieldErrors: {}
267
202
  });
268
- _this.fieldsValidators = {};
269
- var dataSource = props.dataSource,
270
- submitOnPressEnterKey = props.submitOnPressEnterKey;
271
- _this.state = {
272
- data: dataSource,
273
- originalData: dataSource,
274
- fieldErrors: {},
275
- submitFormOnEnter: submitOnPressEnterKey
276
- };
277
- return _this;
278
- }
203
+ };
279
204
 
280
- _createClass(Form, [{
281
- key: "componentDidMount",
282
- value: function componentDidMount() {
283
- var _this$props2 = this.props,
284
- handlerReset = _this$props2.handlerReset,
285
- handlerSubmit = _this$props2.handlerSubmit,
286
- handlerValidates = _this$props2.handlerValidates,
287
- securityBeforeUnload = _this$props2.securityBeforeUnload;
288
- handlerSubmit(this.onSubmit);
289
- if (handlerReset) handlerReset(this.onReset);
290
- if (handlerValidates) handlerValidates(this.checkIsValid);
291
-
292
- if (securityBeforeUnload) {
293
- if (this.context.setSecurityBeforeUnload) this.context.setSecurityBeforeUnload(true);
294
- window.addEventListener('beforeunload', this.onBeforeUnload);
295
- }
205
+ var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
206
+ var newFieldsValidators = _lodash["default"].omit(fieldsValidators, fieldName);
207
+
208
+ setFieldsValidators(newFieldsValidators);
209
+ };
210
+
211
+ var onBeforeUnload = function onBeforeUnload(e) {
212
+ e.preventDefault();
213
+
214
+ if (_lodash["default"].isEqual(data, originalData)) {
215
+ return;
296
216
  }
297
- }, {
298
- key: "componentWillUnmount",
299
- value: function componentWillUnmount() {
300
- window.removeEventListener('beforeunload', this.onBeforeUnload);
217
+
218
+ e.returnValue = true;
219
+ };
220
+
221
+ var submitOnEnter = function submitOnEnter(event) {
222
+ if (event.key === 'Enter') {
223
+ event.preventDefault();
224
+ if (submitFormOnEnter) onFormSubmit();
301
225
  }
302
- }, {
303
- key: "render",
304
- value: function render() {
305
- var _this2 = this;
306
-
307
- var _this$props3 = this.props,
308
- style = _this$props3.style,
309
- customClass = _this$props3.customClass,
310
- children = _this$props3.children,
311
- securityBeforeUnload = _this$props3.securityBeforeUnload,
312
- securityTitle = _this$props3.securityTitle,
313
- securityText = _this$props3.securityText;
314
- return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_helpers.FormContext.Provider, {
315
- value: this.getContextValue()
316
- }, /*#__PURE__*/_react["default"].createElement("form", {
317
- style: style,
318
- onSubmit: function onSubmit(e) {
319
- e.preventDefault();
320
- },
321
- onKeyPress: function onKeyPress(e) {
322
- _this2.submitOnEnter(e);
323
- },
324
- role: "presentation",
325
- className: "form-component ".concat(customClass)
326
- }, children)), /*#__PURE__*/_react["default"].createElement(_dialog.DialogQuestion, {
327
- zIndex: "99999999",
328
- customClassName: "classTeste",
329
- title: securityTitle || 'Dados Alterados',
330
- text: securityText || 'Vocẽ possui dados alterados, confirma o fechamento?',
331
- visible: securityBeforeUnload && this.context.showQuestion,
332
- onConfirmClick: securityBeforeUnload ? this.context.onConfirmClick : function () {},
333
- onUnconfirmClick: securityBeforeUnload ? this.context.onUnconfirmClick : function () {}
334
- }));
226
+ };
227
+
228
+ var getContextValue = function getContextValue() {
229
+ return {
230
+ handlerFieldChange: onFieldChange,
231
+ handlerFieldValidade: onValidate,
232
+ handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
233
+ setFieldsValidators(_extends({}, fieldsValidators, _defineProperty({}, fieldName, fieldValidates)));
234
+ },
235
+ handlerRemoveValidators: onRemoveFieldValidators,
236
+ data: data,
237
+ fieldErrors: fieldErrors,
238
+ externalFieldErrors: externalFieldErrors
239
+ };
240
+ };
241
+
242
+ (0, _react.useEffect)(function () {
243
+ handlerSubmit(onFormSubmit);
244
+ if (handlerReset) handlerReset(onReset);
245
+ if (handlerValidates) handlerValidates(checkIsValid);
246
+ }, []);
247
+ (0, _react.useEffect)(function () {
248
+ if (securityBeforeUnload) {
249
+ if (context) context.setSecurityBeforeUnload(true);
250
+ window.addEventListener('beforeunload', onBeforeUnload);
335
251
  }
336
- }], [{
337
- key: "getDerivedStateFromProps",
338
- value: function getDerivedStateFromProps(props, state) {
339
- var submitOnPressEnterKey = props.submitOnPressEnterKey,
340
- dataSource = props.dataSource;
341
-
342
- if (submitOnPressEnterKey !== state.submitFormOnEnter || dataSource !== state.originalData) {
343
- return {
344
- submitFormOnEnter: submitOnPressEnterKey,
345
- data: dataSource,
346
- originalData: state.originalData || dataSource
347
- };
348
- }
349
252
 
350
- return null;
253
+ return function () {
254
+ return window.removeEventListener('beforeunload', onBeforeUnload);
255
+ };
256
+ }, [securityBeforeUnload, onBeforeUnload]);
257
+ (0, _react.useEffect)(function () {
258
+ if (submitOnPressEnterKey !== submitFormOnEnter || dataSource !== originalData) {
259
+ setData(dataSource);
260
+ setOriginalData(function (prevState) {
261
+ return prevState || dataSource;
262
+ });
263
+ setSubmitFormOnEnter(submitOnPressEnterKey);
351
264
  }
352
- }]);
353
-
354
- return Form;
355
- }(_react.Component);
265
+ }, [submitOnPressEnterKey, dataSource]);
266
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_helpers.FormContext.Provider, {
267
+ value: getContextValue()
268
+ }, /*#__PURE__*/_react["default"].createElement("form", {
269
+ style: style,
270
+ onSubmit: function onSubmit(e) {
271
+ return e.preventDefault();
272
+ },
273
+ onKeyPress: function onKeyPress(e) {
274
+ return submitOnEnter(e);
275
+ },
276
+ role: "presentation",
277
+ className: "form-component ".concat(customClass)
278
+ }, children)), /*#__PURE__*/_react["default"].createElement(_dialog.DialogQuestion, {
279
+ zIndex: "99999999",
280
+ customClassName: "classTeste",
281
+ title: securityTitle || 'Dados Alterados',
282
+ text: securityText || 'Vocẽ possui dados alterados, confirma o fechamento?',
283
+ visible: !!context && context.showQuestion,
284
+ onConfirmClick: context ? context.onConfirmClick : function () {},
285
+ onUnconfirmClick: context ? context.onUnconfirmClick : function () {}
286
+ }));
287
+ };
356
288
 
357
- Object.defineProperty(Form, "contextType", {
358
- configurable: true,
359
- enumerable: true,
360
- writable: true,
361
- value: _withFormSecurity.FormSecurityContext
362
- });
363
289
  Form.propTypes = {
364
290
  dataSource: _propTypes["default"].object.isRequired,
365
291
  children: _propTypes["default"].any.isRequired,
@@ -33,7 +33,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
33
33
 
34
34
  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); }; }
35
35
 
36
- 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); }
36
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
37
37
 
38
38
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
39
39
 
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = exports.FormSecurityContext = void 0;
8
+ exports.FormSecurityContext = exports["default"] = void 0;
9
9
 
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
 
@@ -29,7 +29,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
29
29
 
30
30
  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; }
31
31
 
32
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
32
+ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
33
33
 
34
34
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
35
 
@@ -47,19 +47,15 @@ var withFormSecurity = function withFormSecurity(WrappedComponent) {
47
47
  props = _objectWithoutProperties(_ref, _excluded);
48
48
 
49
49
  var changedData = (0, _react.useRef)(false);
50
+ var securityBeforeUnload = (0, _react.useRef)(false);
50
51
 
51
52
  var _useState = (0, _react.useState)(false),
52
53
  _useState2 = _slicedToArray(_useState, 2),
53
- securityBeforeUnload = _useState2[0],
54
- setSecurityBeforeUnload = _useState2[1];
55
-
56
- var _useState3 = (0, _react.useState)(false),
57
- _useState4 = _slicedToArray(_useState3, 2),
58
- showQuestion = _useState4[0],
59
- setShowQuestion = _useState4[1];
54
+ showQuestion = _useState2[0],
55
+ setShowQuestion = _useState2[1];
60
56
 
61
57
  var newHandlerClose = function newHandlerClose() {
62
- if (changedData.current && securityBeforeUnload) {
58
+ if (changedData.current && securityBeforeUnload.current) {
63
59
  setShowQuestion(true);
64
60
  } else {
65
61
  handlerClose();
@@ -78,6 +74,10 @@ var withFormSecurity = function withFormSecurity(WrappedComponent) {
78
74
  changedData.current = value;
79
75
  };
80
76
 
77
+ var setSecurityBeforeUnload = function setSecurityBeforeUnload(value) {
78
+ securityBeforeUnload.current = value;
79
+ };
80
+
81
81
  return /*#__PURE__*/_react["default"].createElement(FormSecurityContext.Provider, {
82
82
  value: {
83
83
  onChangedData: onChangedData,