linear-react-components-ui 0.4.76-beta.1 → 0.4.76-beta.10

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/README.md CHANGED
@@ -53,8 +53,18 @@ Caso queira gerar uma build com versão beta e fazer a publicação no npm rode
53
53
 
54
54
  `npm run publish:npm --tag beta`
55
55
 
56
- no local onde esta denominado o campo versão, você deverá colocar a nova versão do pacote, um exemplo: 0.4.75 ou para o caso de uma
57
- versão beta siga o seguinte exemplo: 0.4.75-beta.1, ficando da seguinte maneira:
56
+ Caso queira gerar uma build com versão candidata e fazer a publicação no npm rode os comandos da seguinte forma:
57
+
58
+ `npm version <versão>`
59
+
60
+ `npm run publish:npm --tag rc`
61
+
62
+ no local onde esta denominado o campo versão, você deverá colocar a nova versão do pacote, alguns exemplos para o campo versão:
63
+ - release: 0.4.75
64
+ - beta: 0.4.75-beta.0
65
+ - candidata: 0.4.75-rc.0
66
+
67
+ ficando da seguinte maneira:
58
68
 
59
69
  `npm version 0.4.75`
60
70
 
@@ -129,6 +129,9 @@
129
129
  justify-content: center;
130
130
  flex: 1;
131
131
  width: 100%;
132
+ text-decoration: none;
133
+ color: #666666;
134
+ text-align: center;
132
135
  }
133
136
  &.iconcontainer {
134
137
  padding-bottom: 10px;
@@ -95,7 +95,8 @@
95
95
  > .menucontainer {
96
96
  display: flex;
97
97
  flex-wrap: nowrap;
98
- width: 100%;
98
+ max-width: 100%;
99
+ overflow: hidden;
99
100
  @extend %tab-component-menus;
100
101
  > .dropdownbutton {
101
102
  border-bottom: 1px solid $component-border-color;
@@ -52,7 +52,7 @@ var BaseDialog = function BaseDialog(props) {
52
52
  var dialogAlert = document.getElementsByClassName('dialog-alert-wrapper');
53
53
 
54
54
  if (wrapperEl !== null && wrapperEl.current !== null && target !== wrapperEl.current && !wrapperEl.current.contains(target)) {
55
- if (dialogAlert.length > 0 && dialogAlert[dialogAlert.length - 1].contains(target) || target.className !== 'button-component') return;
55
+ if (dialogAlert.length > 0 && dialogAlert[dialogAlert.length - 1].contains(target) || target.classList.contains('button-component')) return;
56
56
  handlerClose();
57
57
  }
58
58
  };
package/lib/form/index.js CHANGED
@@ -51,317 +51,238 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
51
51
 
52
52
  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
53
 
54
+ 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; }
55
+
56
+ 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); }
57
+
54
58
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
55
59
 
56
60
  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
61
 
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
62
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
61
63
 
62
64
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
63
65
 
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; }
66
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
65
67
 
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; }
68
+ 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
69
 
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); }
69
-
70
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
70
+ 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); }
71
71
 
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); } }
72
+ 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; }
73
73
 
74
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
74
+ 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; }
75
+
76
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
77
+
78
+ var Form = function Form(_ref) {
79
+ var submitOnPressEnterKey = _ref.submitOnPressEnterKey,
80
+ dataSource = _ref.dataSource,
81
+ securityBeforeUnload = _ref.securityBeforeUnload,
82
+ handlerReset = _ref.handlerReset,
83
+ handlerSubmit = _ref.handlerSubmit,
84
+ children = _ref.children,
85
+ handlerValidates = _ref.handlerValidates,
86
+ style = _ref.style,
87
+ customClass = _ref.customClass,
88
+ securityTitle = _ref.securityTitle,
89
+ securityText = _ref.securityText,
90
+ onDataChange = _ref.onDataChange,
91
+ onValidateForm = _ref.onValidateForm,
92
+ externalFieldErrors = _ref.externalFieldErrors,
93
+ onSubmit = _ref.onSubmit;
94
+
95
+ var _useState = (0, _react.useState)(dataSource),
96
+ _useState2 = _slicedToArray(_useState, 2),
97
+ data = _useState2[0],
98
+ setData = _useState2[1];
99
+
100
+ var _useState3 = (0, _react.useState)(dataSource),
101
+ _useState4 = _slicedToArray(_useState3, 2),
102
+ originalData = _useState4[0],
103
+ setOriginalData = _useState4[1];
104
+
105
+ var _useState5 = (0, _react.useState)(submitOnPressEnterKey),
106
+ _useState6 = _slicedToArray(_useState5, 2),
107
+ submitFormOnEnter = _useState6[0],
108
+ setSubmitFormOnEnter = _useState6[1];
109
+
110
+ var _useState7 = (0, _react.useState)({}),
111
+ _useState8 = _slicedToArray(_useState7, 2),
112
+ fieldErrors = _useState8[0],
113
+ setFieldErrors = _useState8[1];
114
+
115
+ var _useState9 = (0, _react.useState)({}),
116
+ _useState10 = _slicedToArray(_useState9, 2),
117
+ fieldsValidators = _useState10[0],
118
+ setFieldsValidators = _useState10[1];
119
+
120
+ var context = (0, _react.useContext)(_withFormSecurity.FormSecurityContext);
121
+
122
+ var getValidatesErrorMessages = function getValidatesErrorMessages(validators, fieldValue) {
123
+ var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
124
+ var errors = [];
125
+ validatorsArray.forEach(function (validator) {
126
+ var result = validator(fieldValue);
127
+ if (result) errors = [].concat(_toConsumableArray(errors), [result]);
128
+ });
129
+ return errors;
130
+ };
75
131
 
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); }
132
+ var checkIsValid = function checkIsValid(value) {
133
+ var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
134
+ var dataValidate = value || data;
135
+ var currentFieldErrors = {};
77
136
 
78
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
137
+ _lodash["default"].forEach(fieldsValidators, function (validators, fieldName) {
138
+ var fieldValue = _lodash["default"].get(dataValidate, fieldName);
79
139
 
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); }; }
140
+ var messages = getValidatesErrorMessages(validators, fieldValue);
81
141
 
82
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
142
+ if (messages.length > 0) {
143
+ currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
144
+ }
145
+ });
83
146
 
84
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
147
+ if (updateState) setFieldErrors(currentFieldErrors);
148
+ return _lodash["default"].isEmpty(currentFieldErrors);
149
+ };
85
150
 
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; } }
151
+ var onFieldChange = function onFieldChange(e) {
152
+ var _e$target = e.target,
153
+ name = _e$target.name,
154
+ value = _e$target.value;
87
155
 
88
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
156
+ _lodash["default"].set(data, name, value);
89
157
 
90
- var Form = /*#__PURE__*/function (_Component) {
91
- _inherits(Form, _Component);
158
+ var newData = _extends({}, data);
92
159
 
93
- var _super = _createSuper(Form);
160
+ if (context && context.onChangedData) {
161
+ var onChangedData = context.onChangedData;
94
162
 
95
- function Form(props) {
96
- var _this;
163
+ if (!_lodash["default"].isEqual(newData, originalData)) {
164
+ onChangedData(true);
165
+ } else {
166
+ onChangedData(false);
167
+ }
168
+ }
97
169
 
98
- _classCallCheck(this, Form);
170
+ setData(newData); // TODO - Usar debounce para evitar chamada a cada letra digitada
99
171
 
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();
172
+ if (onValidateForm) onValidateForm(checkIsValid(newData, false));
173
+ if (onDataChange) onDataChange(newData);
174
+ };
107
175
 
108
- if (Object.is(_this.state.data, _this.state.originalData)) {
109
- return;
110
- }
176
+ var onValidate = function onValidate(fieldName, fieldValue, validators) {
177
+ if (validators) {
178
+ var currentFieldErrors = fieldErrors;
179
+ var errors = getValidatesErrorMessages(validators, fieldValue);
111
180
 
112
- e.returnValue = true;
181
+ if (errors.length === 0) {
182
+ currentFieldErrors = _lodash["default"].omit(currentFieldErrors, fieldName);
183
+ } else {
184
+ currentFieldErrors = _extends({}, currentFieldErrors, _defineProperty({}, fieldName, errors));
113
185
  }
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
- var onChangedData = _this.context.onChangedData;
128
-
129
- _lodash["default"].set(data, name, value);
130
-
131
- _this.setState({
132
- data: data
133
- });
134
186
 
135
- if (!Object.is(data, _this.state.originalData)) {
136
- onChangedData(true);
137
- } else {
138
- onChangedData(false);
139
- } // TODO - Usar debounce para evitar chamada a cada letra digitada
187
+ setFieldErrors(currentFieldErrors);
188
+ }
189
+ };
140
190
 
191
+ var onFormSubmit = function onFormSubmit(event) {
192
+ if (event) event.preventDefault();
193
+ if (checkIsValid(data)) onSubmit(data);
194
+ };
141
195
 
142
- if (onValidateForm) onValidateForm(_this.checkIsValid(data, false));
143
- if (onDataChange) onDataChange(data);
144
- }
145
- });
146
- Object.defineProperty(_assertThisInitialized(_this), "onValidate", {
147
- configurable: true,
148
- enumerable: true,
149
- writable: true,
150
- value: function value(fieldName, fieldValue, validators) {
151
- if (validators) {
152
- var fieldErrors = _this.state.fieldErrors;
153
-
154
- var errors = _this.getValidatesErrorMessages(validators, fieldValue);
155
-
156
- if (errors.length === 0) {
157
- fieldErrors = _lodash["default"].omit(fieldErrors, fieldName);
158
- } else {
159
- fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, errors));
160
- }
161
-
162
- _this.setState({
163
- fieldErrors: fieldErrors
164
- });
165
- }
166
- }
167
- });
168
- Object.defineProperty(_assertThisInitialized(_this), "onSubmit", {
169
- configurable: true,
170
- enumerable: true,
171
- writable: true,
172
- value: function value(event) {
173
- if (event) event.preventDefault();
174
- var data = _this.state.data;
175
- if (_this.checkIsValid(data)) _this.props.onSubmit(data);
176
- }
177
- });
178
- Object.defineProperty(_assertThisInitialized(_this), "onReset", {
179
- configurable: true,
180
- enumerable: true,
181
- writable: true,
182
- value: function value() {
183
- _this.setState({
184
- data: JSON.parse(JSON.stringify(_this.state.originalData)),
185
- fieldErrors: {}
186
- });
187
- }
188
- });
189
- Object.defineProperty(_assertThisInitialized(_this), "onRemoveFieldValidators", {
190
- configurable: true,
191
- enumerable: true,
192
- writable: true,
193
- value: function value(fieldName) {
194
- _this.fieldsValidators = _lodash["default"].omit(_this.fieldsValidators, fieldName);
195
- }
196
- });
197
- Object.defineProperty(_assertThisInitialized(_this), "getValidatesErrorMessages", {
198
- configurable: true,
199
- enumerable: true,
200
- writable: true,
201
- value: function value(validators, fieldValue) {
202
- var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
203
- var errors = [];
204
- validatorsArray.forEach(function (validator) {
205
- var result = validator(fieldValue);
206
- if (result) errors = [].concat(_toConsumableArray(errors), [result]);
207
- });
208
- return errors;
209
- }
210
- });
211
- Object.defineProperty(_assertThisInitialized(_this), "getContextValue", {
212
- configurable: true,
213
- enumerable: true,
214
- writable: true,
215
- value: function value() {
216
- return {
217
- handlerFieldChange: _this.onFieldChange,
218
- handlerFieldValidade: _this.onValidate,
219
- handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
220
- _this.fieldsValidators = _extends({}, _this.fieldsValidators, _defineProperty({}, fieldName, fieldValidates));
221
- },
222
- handlerRemoveValidators: _this.onRemoveFieldValidators,
223
- data: _this.state.data,
224
- fieldErrors: _this.state.fieldErrors,
225
- externalFieldErrors: _this.props.externalFieldErrors
226
- };
227
- }
228
- });
229
- Object.defineProperty(_assertThisInitialized(_this), "checkIsValid", {
230
- configurable: true,
231
- enumerable: true,
232
- writable: true,
233
- value: function value(data) {
234
- var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
235
- var dataValidate = data || _this.state.data;
236
- var fieldErrors = {};
237
-
238
- _lodash["default"].forEach(_this.fieldsValidators, function (validators, fieldName) {
239
- var fieldValue = _lodash["default"].get(dataValidate, fieldName);
240
-
241
- var messages = _this.getValidatesErrorMessages(validators, fieldValue);
242
-
243
- if (messages.length > 0) {
244
- fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
245
- }
246
- });
196
+ var onReset = function onReset() {
197
+ setData(JSON.parse(JSON.stringify(originalData)));
198
+ setFieldErrors({});
199
+ };
247
200
 
248
- if (updateState) _this.setState({
249
- fieldErrors: fieldErrors
250
- });
251
- return _lodash["default"].isEmpty(fieldErrors);
252
- }
253
- });
254
- Object.defineProperty(_assertThisInitialized(_this), "submitOnEnter", {
255
- configurable: true,
256
- enumerable: true,
257
- writable: true,
258
- value: function value(event) {
259
- if (event.key === 'Enter') {
260
- event.preventDefault();
261
- if (_this.state.submitFormOnEnter) _this.onSubmit();
262
- }
263
- }
264
- });
265
- _this.fieldsValidators = {};
266
- var dataSource = props.dataSource,
267
- submitOnPressEnterKey = props.submitOnPressEnterKey;
268
- _this.state = {
269
- data: dataSource,
270
- originalData: dataSource,
271
- fieldErrors: {},
272
- submitFormOnEnter: submitOnPressEnterKey
273
- };
274
- return _this;
275
- }
201
+ var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
202
+ var newFieldsValidators = _lodash["default"].omit(fieldsValidators, fieldName);
276
203
 
277
- _createClass(Form, [{
278
- key: "componentDidMount",
279
- value: function componentDidMount() {
280
- var _this$props2 = this.props,
281
- handlerReset = _this$props2.handlerReset,
282
- handlerSubmit = _this$props2.handlerSubmit,
283
- handlerValidates = _this$props2.handlerValidates,
284
- securityBeforeUnload = _this$props2.securityBeforeUnload;
285
- var setSecurityBeforeUnload = this.context.setSecurityBeforeUnload;
286
- handlerSubmit(this.onSubmit);
287
- if (handlerReset) handlerReset(this.onReset);
288
- if (handlerValidates) handlerValidates(this.checkIsValid);
289
-
290
- if (securityBeforeUnload) {
291
- setSecurityBeforeUnload(true);
292
- window.addEventListener('beforeunload', this.onBeforeUnload);
293
- }
204
+ setFieldsValidators(newFieldsValidators);
205
+ };
206
+
207
+ var onBeforeUnload = function onBeforeUnload(e) {
208
+ e.preventDefault();
209
+
210
+ if (_lodash["default"].isEqual(data, originalData)) {
211
+ return;
294
212
  }
295
- }, {
296
- key: "componentWillUnmount",
297
- value: function componentWillUnmount() {
298
- window.removeEventListener('beforeunload', this.onBeforeUnload);
213
+
214
+ e.returnValue = true;
215
+ };
216
+
217
+ var submitOnEnter = function submitOnEnter(event) {
218
+ if (event.key === 'Enter') {
219
+ event.preventDefault();
220
+ if (submitFormOnEnter) onFormSubmit();
299
221
  }
300
- }, {
301
- key: "render",
302
- value: function render() {
303
- var _this2 = this;
304
-
305
- var _this$props3 = this.props,
306
- style = _this$props3.style,
307
- customClass = _this$props3.customClass,
308
- children = _this$props3.children,
309
- securityBeforeUnload = _this$props3.securityBeforeUnload,
310
- securityTitle = _this$props3.securityTitle,
311
- securityText = _this$props3.securityText;
312
- var _this$context = this.context,
313
- showQuestion = _this$context.showQuestion,
314
- onUnconfirmClick = _this$context.onUnconfirmClick,
315
- onConfirmClick = _this$context.onConfirmClick;
316
- return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_helpers.FormContext.Provider, {
317
- value: this.getContextValue()
318
- }, /*#__PURE__*/_react["default"].createElement("form", {
319
- style: style,
320
- onSubmit: function onSubmit(e) {
321
- e.preventDefault();
322
- },
323
- onKeyPress: function onKeyPress(e) {
324
- _this2.submitOnEnter(e);
325
- },
326
- role: "presentation",
327
- className: "form-component ".concat(customClass)
328
- }, children)), /*#__PURE__*/_react["default"].createElement(_dialog.DialogQuestion, {
329
- zIndex: "99999999",
330
- customClassName: "classTeste",
331
- title: securityTitle || 'Dados Alterados',
332
- text: securityText || 'Vocẽ possui dados alterados, confirma o fechamento?',
333
- visible: securityBeforeUnload && showQuestion,
334
- onConfirmClick: onConfirmClick,
335
- onUnconfirmClick: onUnconfirmClick
336
- }));
222
+ };
223
+
224
+ var getContextValue = function getContextValue() {
225
+ return {
226
+ handlerFieldChange: onFieldChange,
227
+ handlerFieldValidade: onValidate,
228
+ handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
229
+ setFieldsValidators(function (prevState) {
230
+ return _extends({}, prevState, _defineProperty({}, fieldName, fieldValidates));
231
+ });
232
+ },
233
+ handlerRemoveValidators: onRemoveFieldValidators,
234
+ data: data,
235
+ fieldErrors: fieldErrors,
236
+ externalFieldErrors: externalFieldErrors
237
+ };
238
+ };
239
+
240
+ (0, _react.useEffect)(function () {
241
+ handlerSubmit(onFormSubmit);
242
+ if (handlerReset) handlerReset(onReset);
243
+ if (handlerValidates) handlerValidates(checkIsValid);
244
+ }, [data]);
245
+ (0, _react.useEffect)(function () {
246
+ if (securityBeforeUnload) {
247
+ if (context) context.setSecurityBeforeUnload(true);
248
+ window.addEventListener('beforeunload', onBeforeUnload);
337
249
  }
338
- }], [{
339
- key: "getDerivedStateFromProps",
340
- value: function getDerivedStateFromProps(props, state) {
341
- var submitOnPressEnterKey = props.submitOnPressEnterKey,
342
- dataSource = props.dataSource;
343
-
344
- if (submitOnPressEnterKey !== state.submitFormOnEnter || dataSource !== state.originalData) {
345
- return {
346
- submitFormOnEnter: submitOnPressEnterKey,
347
- data: dataSource,
348
- originalData: state.originalData || dataSource
349
- };
350
- }
351
250
 
352
- return null;
251
+ return function () {
252
+ return window.removeEventListener('beforeunload', onBeforeUnload);
253
+ };
254
+ }, [securityBeforeUnload, onBeforeUnload]);
255
+ (0, _react.useEffect)(function () {
256
+ if (submitOnPressEnterKey !== submitFormOnEnter || dataSource !== originalData) {
257
+ setData(dataSource);
258
+ setOriginalData(function (prevState) {
259
+ return prevState || dataSource;
260
+ });
261
+ setSubmitFormOnEnter(submitOnPressEnterKey);
353
262
  }
354
- }]);
355
-
356
- return Form;
357
- }(_react.Component);
263
+ }, [submitOnPressEnterKey, dataSource]);
264
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_helpers.FormContext.Provider, {
265
+ value: getContextValue()
266
+ }, /*#__PURE__*/_react["default"].createElement("form", {
267
+ style: style,
268
+ onSubmit: function onSubmit(e) {
269
+ return e.preventDefault();
270
+ },
271
+ onKeyPress: function onKeyPress(e) {
272
+ return submitOnEnter(e);
273
+ },
274
+ role: "presentation",
275
+ className: "form-component ".concat(customClass)
276
+ }, children)), /*#__PURE__*/_react["default"].createElement(_dialog.DialogQuestion, {
277
+ zIndex: "99999999",
278
+ title: securityTitle || 'Dados Alterados',
279
+ text: securityText || 'Você possui dados alterados, confirma o fechamento?',
280
+ visible: !!context && context.showQuestion,
281
+ onConfirmClick: context ? context.onConfirmClick : function () {},
282
+ onUnconfirmClick: context ? context.onUnconfirmClick : function () {}
283
+ }));
284
+ };
358
285
 
359
- Object.defineProperty(Form, "contextType", {
360
- configurable: true,
361
- enumerable: true,
362
- writable: true,
363
- value: _withFormSecurity.FormSecurityContext
364
- });
365
286
  Form.propTypes = {
366
287
  dataSource: _propTypes["default"].object.isRequired,
367
288
  children: _propTypes["default"].any.isRequired,
@@ -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,