linear-react-components-ui 1.0.10-beta.18 → 1.0.10-beta.19

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/lib/form/Field.js CHANGED
@@ -34,7 +34,7 @@ var getEvents = function getEvents(_ref) {
34
34
  handlerFieldChange = _ref.handlerFieldChange,
35
35
  _onChange = _ref.onChange,
36
36
  handleShowValidateMessages = _ref.handleShowValidateMessages;
37
- if (!(validators || validatorFromComponent || _onBlur)) return {};
37
+ if (!(validators || validatorFromComponent || _onBlur || _onChange)) return {};
38
38
  var validatorsArray = (0, _helpers.getValidatorsArray)(validators, validatorFromComponent);
39
39
  return {
40
40
  onBlur: function onBlur(e) {
@@ -54,7 +54,7 @@ var getEvents = function getEvents(_ref) {
54
54
  }
55
55
  };
56
56
  };
57
- var getCustomProps = function getCustomProps(props, setValidatorFromComponent) {
57
+ var getCustomProps = function getCustomProps(props, handlerSetComponentValidator) {
58
58
  var value = props.value,
59
59
  data = props.data,
60
60
  name = props.name,
@@ -74,7 +74,7 @@ var getCustomProps = function getCustomProps(props, setValidatorFromComponent) {
74
74
  } else if (component.displayName === 'CpfField' || component.displayName === 'CnpjField') {
75
75
  return {
76
76
  value: _lodash.default.get(data, name),
77
- handlerSetComponentValidator: setValidatorFromComponent
77
+ handlerSetComponentValidator: handlerSetComponentValidator
78
78
  };
79
79
  }
80
80
  return {
@@ -83,26 +83,21 @@ var getCustomProps = function getCustomProps(props, setValidatorFromComponent) {
83
83
  };
84
84
  var Field = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
85
85
  var handlerFieldChange = props.handlerFieldChange,
86
- onChange = props.onChange;
86
+ onChange = props.onChange,
87
+ onBlur = props.onBlur,
88
+ name = props.name,
89
+ validators = props.validators;
87
90
  var _useState = (0, _react.useState)(false),
88
91
  _useState2 = _slicedToArray(_useState, 2),
89
92
  showValidateMessages = _useState2[0],
90
93
  setShowValidateMessages = _useState2[1];
91
- var _useState3 = (0, _react.useState)(undefined),
92
- _useState4 = _slicedToArray(_useState3, 2),
93
- validatorFromComponent = _useState4[0],
94
- setValidatorFromComponent = _useState4[1];
95
94
  var _useContext = (0, _react.useContext)(_helpers.withFieldContext),
96
- handlerSetValidatorFromComponent = _useContext.handlerSetValidatorFromComponent;
97
- (0, _react.useEffect)(function () {
98
- if (validatorFromComponent && handlerSetValidatorFromComponent) {
99
- handlerSetValidatorFromComponent(validatorFromComponent);
100
- }
101
- }, [validatorFromComponent]);
95
+ handlerSetValidatorFromComponent = _useContext.handlerSetValidatorFromComponent,
96
+ validatorFromComponent = _useContext.validatorFromComponent;
102
97
  return /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getEvents({
103
- name: props.name,
104
- validators: props.validators,
105
- onBlur: props.onBlur,
98
+ name: name,
99
+ validators: validators,
100
+ onBlur: onBlur,
106
101
  validatorFromComponent: validatorFromComponent,
107
102
  handlerFieldValidade: props.handlerFieldValidade ? props.handlerFieldValidade : function () {},
108
103
  handlerFieldChange: handlerFieldChange,
@@ -110,7 +105,7 @@ var Field = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
110
105
  handleShowValidateMessages: function handleShowValidateMessages(value) {
111
106
  return setShowValidateMessages(value);
112
107
  }
113
- }), getCustomProps(props, setValidatorFromComponent), {
108
+ }), getCustomProps(props, handlerSetValidatorFromComponent), {
114
109
  ref: ref,
115
110
  errorMessages: (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
116
111
  fieldErrors: showValidateMessages ? props.fieldErrors : {}
@@ -15,6 +15,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
15
15
  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; }
16
16
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
17
17
  function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
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
+ 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
+ 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."); }
22
+ 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); }
23
+ 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; }
24
+ 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; } }
25
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
26
  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; }
19
27
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
28
  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); }
@@ -38,12 +46,31 @@ var getDefaultProps = function getDefaultProps(props) {
38
46
  if (handlerSelecionados) handlerSelecionados(ids);
39
47
  }), _ref;
40
48
  };
49
+ var getEvents = function getEvents(_ref2) {
50
+ var _onBlur = _ref2.onBlur,
51
+ _onSelect = _ref2.onSelect,
52
+ handleShowValidateMessages = _ref2.handleShowValidateMessages;
53
+ return {
54
+ onBlur: function onBlur(e) {
55
+ handleShowValidateMessages(true);
56
+ if (_onBlur) _onBlur(e);
57
+ },
58
+ onSelect: function onSelect(e) {
59
+ handleShowValidateMessages(true);
60
+ if (_onSelect) _onSelect(e);
61
+ }
62
+ };
63
+ };
41
64
  var FieldArray = function FieldArray(props) {
42
65
  var cols = props.cols,
43
66
  label = props.label,
44
67
  bordered = props.bordered,
45
68
  labelContainerStyle = props.labelContainerStyle,
46
69
  skipLabel = props.skipLabel;
70
+ var _useState = (0, _react.useState)(false),
71
+ _useState2 = _slicedToArray(_useState, 2),
72
+ showValidateMessages = _useState2[0],
73
+ setShowValidateMessages = _useState2[1];
47
74
  var content = null;
48
75
  if (props.component) {
49
76
  if (!skipLabel && label) {
@@ -52,9 +79,21 @@ var FieldArray = function FieldArray(props) {
52
79
  customClass: "arraycontainer ".concat(bordered && '-bordered'),
53
80
  style: labelContainerStyle,
54
81
  titleCustomClass: "label"
55
- }, /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getDefaultProps(props))), (0, _helpers.getErrorMessages)(props));
82
+ }, /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getDefaultProps(props), getEvents(_objectSpread(_objectSpread({}, props), {}, {
83
+ handleShowValidateMessages: function handleShowValidateMessages(value) {
84
+ return setShowValidateMessages(value);
85
+ }
86
+ })))), (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
87
+ fieldErrors: showValidateMessages ? props.fieldErrors : {}
88
+ })));
56
89
  } else {
57
- content = /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getDefaultProps(props))), (0, _helpers.getErrorMessages)(props));
90
+ content = /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getDefaultProps(props), getEvents(_objectSpread(_objectSpread({}, props), {}, {
91
+ handleShowValidateMessages: function handleShowValidateMessages(value) {
92
+ return setShowValidateMessages(value);
93
+ }
94
+ })))), (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
95
+ fieldErrors: showValidateMessages ? props.fieldErrors : {}
96
+ })));
58
97
  }
59
98
  }
60
99
  if (cols) return /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
@@ -10,7 +10,7 @@ import '../@types/Period.js';
10
10
  declare const securityBeforeUnload = "securityBeforeUnload";
11
11
  declare const FormContext: React__default.Context<FormContextProps>;
12
12
  declare const withFieldContext: React__default.Context<IWithFieldContext>;
13
- declare const changeValue: (newData: object, target: HTMLInputElement) => any;
13
+ declare const changeValue: ({ ...newData }: object, target: HTMLInputElement) => any;
14
14
  declare const getErrorMessages: ({ name, fieldErrors, externalFieldErrors, externalMessagesErrors, }: IGetErrorMessagesParams) => string[];
15
15
  declare const getValidatorsArray: (validators?: Validator | Validator[], validatorFromComponent?: Validator | Validator[]) => Validator[];
16
16
 
@@ -13,23 +13,26 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
13
13
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
14
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
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 _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
17
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
16
18
  var securityBeforeUnload = 'securityBeforeUnload';
17
19
  exports.securityBeforeUnload = securityBeforeUnload;
18
20
  var FormContext = /*#__PURE__*/_react.default.createContext({});
19
21
  exports.FormContext = FormContext;
20
22
  var withFieldContext = /*#__PURE__*/_react.default.createContext({});
21
23
  exports.withFieldContext = withFieldContext;
22
- var changeValue = function changeValue(newData, target) {
24
+ var changeValue = function changeValue(_ref, target) {
25
+ var newData = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
23
26
  var name = target.name,
24
27
  value = target.value;
25
28
  return _lodash.default.set(JSON.parse(JSON.stringify(newData)), name, value);
26
29
  };
27
30
  exports.changeValue = changeValue;
28
- var getErrorMessages = function getErrorMessages(_ref) {
29
- var name = _ref.name,
30
- fieldErrors = _ref.fieldErrors,
31
- externalFieldErrors = _ref.externalFieldErrors,
32
- externalMessagesErrors = _ref.externalMessagesErrors;
31
+ var getErrorMessages = function getErrorMessages(_ref2) {
32
+ var name = _ref2.name,
33
+ fieldErrors = _ref2.fieldErrors,
34
+ externalFieldErrors = _ref2.externalFieldErrors,
35
+ externalMessagesErrors = _ref2.externalMessagesErrors;
33
36
  var errors = externalMessagesErrors ? _toConsumableArray(externalMessagesErrors) : [];
34
37
  if (fieldErrors && fieldErrors[name]) {
35
38
  errors = [].concat(_toConsumableArray(errors), _toConsumableArray(fieldErrors[name]));
@@ -2,7 +2,7 @@ export { default as Field } from './Field.js';
2
2
  export { default as FieldNumber } from './FieldNumber.js';
3
3
  export { default as FieldArray } from './FieldArray.js';
4
4
  export { default as FieldPeriod } from './FieldPeriod.js';
5
- import { IFormProps } from './types.js';
5
+ import { FormProps } from './types.js';
6
6
  import 'react';
7
7
  import '../inputs/select/types.js';
8
8
  import '../@types/Align.js';
@@ -11,6 +11,6 @@ import '../@types/PermissionAttr.js';
11
11
  import '../inputs/base/types.js';
12
12
  import '../@types/Period.js';
13
13
 
14
- declare const Form: ({ submitOnPressEnterKey, dataSource, securityBeforeUnload, handlerReset, handlerSubmit, handlerValidates, style, customClass, securityTitle, securityText, securityData, onDataChange, onValidateForm, externalFieldErrors, onSubmit, skeletonize, disabled, children, }: IFormProps) => JSX.Element;
14
+ declare const Form: ({ submitOnPressEnterKey, dataSource, securityBeforeUnload, handlerReset, handlerSubmit, handlerValidates, style, customClass, securityTitle, securityText, securityData, onDataChange, onValidateForm, externalFieldErrors, onSubmit, skeletonize, disabled, children, useInternalState, }: FormProps) => JSX.Element;
15
15
 
16
16
  export { Form as default };
package/lib/form/index.js CHANGED
@@ -77,7 +77,9 @@ var Form = function Form(_ref) {
77
77
  onSubmit = _ref.onSubmit,
78
78
  skeletonize = _ref.skeletonize,
79
79
  disabled = _ref.disabled,
80
- children = _ref.children;
80
+ children = _ref.children,
81
+ _ref$useInternalState = _ref.useInternalState,
82
+ useInternalState = _ref$useInternalState === void 0 ? false : _ref$useInternalState;
81
83
  var _useState = (0, _react.useState)(dataSource),
82
84
  _useState2 = _slicedToArray(_useState, 2),
83
85
  data = _useState2[0],
@@ -94,11 +96,9 @@ var Form = function Form(_ref) {
94
96
  _useState8 = _slicedToArray(_useState7, 2),
95
97
  fieldErrors = _useState8[0],
96
98
  setFieldErrors = _useState8[1];
97
- var _useState9 = (0, _react.useState)({}),
98
- _useState10 = _slicedToArray(_useState9, 2),
99
- fieldsValidators = _useState10[0],
100
- setFieldValidators = _useState10[1];
99
+ var fieldsValidators = (0, _react.useRef)({});
101
100
  var context = (0, _react.useContext)(_withFormSecurity.FormSecurityContext);
101
+ var usedData = useInternalState ? data : dataSource;
102
102
  var getValidatesErrorMessages = function getValidatesErrorMessages(validators, fieldValue) {
103
103
  var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
104
104
  var errors = [];
@@ -110,15 +110,20 @@ var Form = function Form(_ref) {
110
110
  });
111
111
  return errors;
112
112
  };
113
- var checkIsValid = function checkIsValid(currentData) {
114
- var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
115
- var dataValidate = currentData || data;
113
+ var getErrorMessages = function getErrorMessages(currentData, currentValidators) {
114
+ var dataValidate = currentData || usedData;
116
115
  var currentFieldErrors = _objectSpread({}, fieldErrors);
117
- _lodash.default.forEach(fieldsValidators, function (validators, fieldName) {
116
+ _lodash.default.forEach(currentValidators, function (validators, fieldName) {
118
117
  var fieldValue = _lodash.default.get(dataValidate, fieldName);
119
118
  var messages = getValidatesErrorMessages(validators, fieldValue);
120
119
  currentFieldErrors = _objectSpread(_objectSpread({}, currentFieldErrors), {}, _defineProperty({}, fieldName, messages));
121
120
  });
121
+ return currentFieldErrors;
122
+ };
123
+ var checkIsValid = function checkIsValid(currentData) {
124
+ var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
125
+ var currentValidators = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
126
+ var currentFieldErrors = getErrorMessages(currentData, currentValidators || fieldsValidators.current);
122
127
  if (updateState) setFieldErrors(currentFieldErrors);
123
128
  return Object.values(currentFieldErrors).every(function (value) {
124
129
  return value.length === 0;
@@ -126,9 +131,14 @@ var Form = function Form(_ref) {
126
131
  };
127
132
  var onFieldChange = function onFieldChange(event) {
128
133
  var target = event.target;
129
- setData(function (prevState) {
130
- return (0, _helpers.changeValue)(prevState, target);
131
- });
134
+ if (!useInternalState && onDataChange) {
135
+ var newData = (0, _helpers.changeValue)(dataSource, target);
136
+ onDataChange(newData);
137
+ } else {
138
+ setData(function (prevState) {
139
+ return (0, _helpers.changeValue)(prevState, target);
140
+ });
141
+ }
132
142
  };
133
143
  var onValidate = function onValidate(fieldName, fieldValue, validators) {
134
144
  if (validators) {
@@ -144,20 +154,24 @@ var Form = function Form(_ref) {
144
154
  };
145
155
  var onFormSubmit = function onFormSubmit(event) {
146
156
  if (event) event.preventDefault();
147
- if (checkIsValid(data)) onSubmit(data);
157
+ if (checkIsValid(usedData)) onSubmit(usedData);
148
158
  };
149
159
  var onReset = function onReset() {
150
- setData(JSON.parse(JSON.stringify(originalData)));
160
+ if (!useInternalState && onDataChange) {
161
+ onDataChange(JSON.parse(JSON.stringify(originalData)));
162
+ } else {
163
+ setData(JSON.parse(JSON.stringify(originalData)));
164
+ }
151
165
  setFieldErrors({});
152
166
  };
153
167
  var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
154
168
  var newFieldsValidators = _lodash.default.omit(fieldsValidators, fieldName);
155
- setFieldValidators(newFieldsValidators);
169
+ fieldsValidators.current = newFieldsValidators;
156
170
  };
157
171
  var onBeforeUnload = function onBeforeUnload(e) {
158
172
  var event = e;
159
173
  event.preventDefault();
160
- if (_lodash.default.isEqual(data, originalData)) {
174
+ if (_lodash.default.isEqual(usedData, originalData)) {
161
175
  return;
162
176
  }
163
177
  event.returnValue = true;
@@ -182,25 +196,32 @@ var Form = function Form(_ref) {
182
196
  }
183
197
  return propsForm;
184
198
  };
185
- (0, _react.useEffect)(function () {
199
+ var updateFormState = function updateFormState() {
186
200
  if (!_lodash.default.isEmpty(context)) {
187
201
  var onChangedData = context.onChangedData;
188
- if (securityData && !_lodash.default.isEqual(data, securityData)) {
202
+ if (securityData && !_lodash.default.isEqual(usedData, securityData)) {
189
203
  onChangedData(true);
190
204
  } else {
191
205
  onChangedData(false);
192
206
  }
193
207
  }
208
+ if (onDataChange) onDataChange(usedData);
194
209
 
195
210
  // TODO - Usar debounce para evitar chamada a cada letra digitada
196
- if (onDataChange) onDataChange(data);
197
- if (onValidateForm) onValidateForm(checkIsValid(data, false));
211
+ if (onValidateForm) onValidateForm(checkIsValid(usedData, true));
198
212
  if (!disabled) {
199
213
  handlerSubmit(onFormSubmit);
200
214
  if (handlerReset) handlerReset(onReset);
201
- if (handlerValidates) handlerValidates(checkIsValid(data));
215
+ if (handlerValidates) handlerValidates(checkIsValid(usedData));
202
216
  }
203
- }, [data]);
217
+ if (_lodash.default.isEmpty(usedData)) setOriginalData(usedData);
218
+ };
219
+ (0, _react.useEffect)(function () {
220
+ if (useInternalState) updateFormState();
221
+ }, [JSON.stringify(data), useInternalState]);
222
+ (0, _react.useEffect)(function () {
223
+ if (!useInternalState && onDataChange) updateFormState();
224
+ }, [JSON.stringify(dataSource), useInternalState]);
204
225
  (0, _react.useEffect)(function () {
205
226
  if (securityBeforeUnload) {
206
227
  if (context) context.setSecurityBeforeUnload(true);
@@ -211,37 +232,35 @@ var Form = function Form(_ref) {
211
232
  };
212
233
  }, [securityBeforeUnload, onBeforeUnload]);
213
234
  (0, _react.useEffect)(function () {
214
- if (!disabled) {
215
- if (submitOnPressEnterKey !== submitFormOnEnter || dataSource !== originalData) {
216
- setData(function (prevState) {
217
- return !_lodash.default.isEqual(data, dataSource) ? dataSource : prevState;
218
- });
219
- setOriginalData(function (prevState) {
220
- return prevState || dataSource;
221
- });
222
- setSubmitFormOnEnter(submitOnPressEnterKey);
223
- }
235
+ if (!disabled && submitOnPressEnterKey !== submitFormOnEnter) {
236
+ setSubmitFormOnEnter(submitOnPressEnterKey);
224
237
  }
225
- }, [submitOnPressEnterKey, dataSource]);
238
+ }, [submitOnPressEnterKey]);
226
239
  var contextValues = {
227
240
  skeletonize: skeletonize,
228
241
  handlerFieldChange: onFieldChange,
229
242
  handlerFieldValidade: onValidate,
230
243
  handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
231
- setFieldValidators(function (prevState) {
232
- return _objectSpread(_objectSpread({}, prevState), {}, _defineProperty({}, fieldName, fieldValidates));
233
- });
244
+ var oldFieldsValidators = _objectSpread({}, fieldsValidators.current);
245
+ fieldsValidators.current = _objectSpread(_objectSpread({}, fieldsValidators.current), {}, _defineProperty({}, fieldName, fieldValidates));
246
+ if (onValidateForm && oldFieldsValidators && oldFieldsValidators[fieldName]) {
247
+ var oldValidatorsValue = Object.values(oldFieldsValidators[fieldName]);
248
+ var newValidatorValue = Object.values(fieldValidates);
249
+ var validatorsIsNotEqual = oldValidatorsValue.length !== newValidatorValue.length;
250
+ if (validatorsIsNotEqual) {
251
+ if (!useInternalState && onDataChange) {
252
+ onValidateForm(checkIsValid(dataSource, true, fieldsValidators.current));
253
+ } else {
254
+ onValidateForm(checkIsValid(data, true, fieldsValidators.current));
255
+ }
256
+ }
257
+ }
234
258
  },
235
259
  handlerRemoveValidators: onRemoveFieldValidators,
236
- data: data,
260
+ data: useInternalState ? data : dataSource,
237
261
  fieldErrors: fieldErrors,
238
262
  externalFieldErrors: externalFieldErrors
239
263
  };
240
- (0, _react.useEffect)(function () {
241
- if (onValidateForm) {
242
- onValidateForm(checkIsValid(data, true));
243
- }
244
- }, [fieldsValidators]);
245
264
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_helpers.FormContext.Provider, {
246
265
  value: contextValues
247
266
  }, /*#__PURE__*/_react.default.createElement("form", _extends({
@@ -1,4 +1,4 @@
1
- import { ChangeEvent, ReactNode, CSSProperties, ComponentType, MouseEventHandler } from 'react';
1
+ import { ChangeEvent, ComponentType, MouseEventHandler, ReactNode, CSSProperties } from 'react';
2
2
  import { AllOptions } from '../inputs/select/types.js';
3
3
  import '../@types/Align.js';
4
4
  import '../@types/DataCombo.js';
@@ -17,7 +17,7 @@ type OnFielChangeEvent = Event & {
17
17
  type CustomKeyboardEvent = ChangeEvent<HTMLInputElement> & {
18
18
  keyCode: number;
19
19
  };
20
- interface IFormProps {
20
+ type BaseFormProps = {
21
21
  dataSource: object;
22
22
  children: ReactNode;
23
23
  onSubmit: (data: object) => void;
@@ -28,7 +28,6 @@ interface IFormProps {
28
28
  submitOnPressEnterKey?: boolean;
29
29
  style?: CSSProperties;
30
30
  customClass?: string;
31
- onDataChange?: (data: object) => void;
32
31
  securityBeforeUnload?: boolean;
33
32
  securityTitle?: string;
34
33
  securityText?: string;
@@ -36,7 +35,14 @@ interface IFormProps {
36
35
  externalFieldErrors?: object;
37
36
  skeletonize?: boolean;
38
37
  disabled?: boolean;
39
- }
38
+ };
39
+ type FormProps = BaseFormProps & ({
40
+ useInternalState?: false;
41
+ onDataChange: (data: object) => void;
42
+ } | {
43
+ useInternalState: true;
44
+ onDataChange?: (data: object) => void;
45
+ });
40
46
  interface IFieldProps extends WithFieldProps {
41
47
  data?: object;
42
48
  dataSource?: object;
@@ -146,6 +152,7 @@ interface WithFieldProps {
146
152
  validators?: Validator | Validator[] | PeriodValidator | PeriodValidator[];
147
153
  }
148
154
  interface IWithFieldContext {
155
+ validatorFromComponent: Validator | Validator[] | undefined;
149
156
  handlerSetValidatorFromComponent: (validator: Validator | Validator[]) => void;
150
157
  }
151
158
  interface IWithFormSecurity {
@@ -190,4 +197,4 @@ type FieldValidator = {
190
197
  [name: string]: Validator | Validator[];
191
198
  };
192
199
 
193
- export { CustomEvent, CustomKeyboardEvent, FieldErrors, FieldValidator, FormContextProps, IEventParams, IFieldArrayProps, IFieldPeriodProps, IFieldProps, IFormProps, IFormSecurityContext, IGetErrorMessagesParams, IWithFieldContext, IWithFormSecurity, OnFielChangeEvent, PeriodChangeEvent, PeriodValidator, Validator, WithFieldProps };
200
+ export { CustomEvent, CustomKeyboardEvent, FieldErrors, FieldValidator, FormContextProps, FormProps, IEventParams, IFieldArrayProps, IFieldPeriodProps, IFieldProps, IFormSecurityContext, IGetErrorMessagesParams, IWithFieldContext, IWithFormSecurity, OnFielChangeEvent, PeriodChangeEvent, PeriodValidator, Validator, WithFieldProps };
@@ -40,6 +40,7 @@ var withFieldHOC = function withFieldHOC(WrappedComponent) {
40
40
  updateValidators();
41
41
  }, [validators]);
42
42
  var contextValues = {
43
+ validatorFromComponent: validatorFromComponent,
43
44
  handlerSetValidatorFromComponent: function handlerSetValidatorFromComponent(validator) {
44
45
  setValidatorFromComponent(validator);
45
46
  }
@@ -29,6 +29,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
29
  var CALENDAR_BUTTON_WIDTH = 24;
30
30
  var CALENDAR_MIN_WIDTH = 250;
31
31
  var DatePicker = function DatePicker(props) {
32
+ var _window;
32
33
  var _props$showButtonOpen = props.showButtonOpen,
33
34
  showButtonOpen = _props$showButtonOpen === void 0 ? true : _props$showButtonOpen,
34
35
  _props$openOnFocus = props.openOnFocus,
@@ -223,7 +224,7 @@ var DatePicker = function DatePicker(props) {
223
224
  } else {
224
225
  setFormatedLeftPosition(inputDimensions === null || inputDimensions === void 0 ? void 0 : inputDimensions.left);
225
226
  }
226
- }, [getWrapperComponent]);
227
+ }, [(_window = window) === null || _window === void 0 ? void 0 : _window.innerWidth, inputDimensions]);
227
228
  if (onDenied && onDenied.unvisible) return null;
228
229
  (0, _react.useEffect)(function () {
229
230
  window.addEventListener('resize', onScreenResize);
@@ -45,11 +45,11 @@ var CpfField = function CpfField(props) {
45
45
  return debouncedOnChange.cancel;
46
46
  }, []);
47
47
  var onChange = function onChange(e) {
48
+ // console.log('onChange >>>', props.onChange);
48
49
  if (enableValidation && e) {
49
50
  debouncedOnChange(e.target.value);
50
51
  if (props.onChange) props.onChange(e);
51
- }
52
- if (props.onChange) {
52
+ } else if (props.onChange) {
53
53
  props.onChange(e);
54
54
  }
55
55
  };
@@ -61,10 +61,10 @@ var CpfField = function CpfField(props) {
61
61
  }
62
62
  return {};
63
63
  };
64
- return /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({
64
+ return /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({}, props, {
65
65
  onChange: onChange,
66
66
  mask: "000.000.000-00"
67
- }, props, getErrorMessagesProp()));
67
+ }, getErrorMessagesProp()));
68
68
  };
69
69
 
70
70
  // Em caso de alteração na propriedade displayName deverá ser atualizada a lógica na função
@@ -89,10 +89,6 @@ var SimpleSelect = function SimpleSelect(props) {
89
89
  _useState16 = _slicedToArray(_useState15, 2),
90
90
  isTyping = _useState16[0],
91
91
  setIsTyping = _useState16[1];
92
- var _useState17 = (0, _react.useState)(null),
93
- _useState18 = _slicedToArray(_useState17, 2),
94
- valueFromProps = _useState18[0],
95
- setValueFromProps = _useState18[1];
96
92
  var dropdownRef = (0, _react.useRef)(null);
97
93
  var componentId = "select-component".concat(_uuid.default.v1());
98
94
  var componentRef = (0, _react.useRef)(null);
@@ -241,14 +237,13 @@ var SimpleSelect = function SimpleSelect(props) {
241
237
  }
242
238
  }, [gridLayout]);
243
239
  (0, _react.useEffect)(function () {
244
- if (value !== valueFromProps && dataSourceWithAllOptions.length > 0) {
240
+ if (dataSourceWithAllOptions.length > 0) {
245
241
  var newCurrent = null;
246
- if (value) {
242
+ if (value || value === 0) {
247
243
  newCurrent = dataSourceWithAllOptions.find(function (i) {
248
244
  var _i$idKey;
249
- return value && ((_i$idKey = i[idKey]) === null || _i$idKey === void 0 ? void 0 : _i$idKey.toString().toLowerCase()) === (value === null || value === void 0 ? void 0 : value.toString().toLowerCase());
245
+ return (value || value === 0) && ((_i$idKey = i[idKey]) === null || _i$idKey === void 0 ? void 0 : _i$idKey.toString().toLowerCase()) === (value === null || value === void 0 ? void 0 : value.toString().toLowerCase());
250
246
  });
251
- setValueFromProps(value);
252
247
  } else if (dataSourceWithAllOptions.length > 0 && selectFirstOnEnter) {
253
248
  newCurrent = dataSourceWithAllOptions[0];
254
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.0.10-beta.18",
3
+ "version": "1.0.10-beta.19",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",