linear-react-components-ui 1.0.10-beta.20 → 1.0.10-beta.22

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
@@ -86,7 +86,8 @@ var Field = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
86
86
  onChange = props.onChange,
87
87
  onBlur = props.onBlur,
88
88
  name = props.name,
89
- validators = props.validators;
89
+ validators = props.validators,
90
+ data = props.data;
90
91
  var _useState = (0, _react.useState)(false),
91
92
  _useState2 = _slicedToArray(_useState, 2),
92
93
  showValidateMessages = _useState2[0],
@@ -94,6 +95,12 @@ var Field = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
94
95
  var _useContext = (0, _react.useContext)(_helpers.withFieldContext),
95
96
  handlerSetValidatorFromComponent = _useContext.handlerSetValidatorFromComponent,
96
97
  validatorFromComponent = _useContext.validatorFromComponent;
98
+ var currentValue = _lodash.default.get(data, name);
99
+ (0, _react.useEffect)(function () {
100
+ if (currentValue && (!!currentValue || currentValue === 0 || Array.isArray(currentValue) && currentValue.length > 0)) {
101
+ setShowValidateMessages(true);
102
+ }
103
+ }, [currentValue]);
97
104
  return /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getEvents({
98
105
  name: name,
99
106
  validators: validators,
@@ -66,11 +66,19 @@ var FieldArray = function FieldArray(props) {
66
66
  label = props.label,
67
67
  bordered = props.bordered,
68
68
  labelContainerStyle = props.labelContainerStyle,
69
- skipLabel = props.skipLabel;
69
+ skipLabel = props.skipLabel,
70
+ data = props.data,
71
+ name = props.name;
70
72
  var _useState = (0, _react.useState)(false),
71
73
  _useState2 = _slicedToArray(_useState, 2),
72
74
  showValidateMessages = _useState2[0],
73
75
  setShowValidateMessages = _useState2[1];
76
+ var currentValue = _lodash.default.get(data, name);
77
+ (0, _react.useEffect)(function () {
78
+ if (Array.isArray(currentValue) && currentValue.length > 0) {
79
+ setShowValidateMessages(true);
80
+ }
81
+ }, [currentValue]);
74
82
  var content = null;
75
83
  if (props.component) {
76
84
  if (!skipLabel && label) {
@@ -53,10 +53,16 @@ var getEventProps = function getEventProps(_ref) {
53
53
  var FieldMask = function FieldMask(props) {
54
54
  var data = props.data,
55
55
  name = props.name;
56
+ var currentValue = _lodash.default.get(data, name);
56
57
  var _useState = (0, _react.useState)(false),
57
58
  _useState2 = _slicedToArray(_useState, 2),
58
59
  showValidateMessages = _useState2[0],
59
60
  setShowValidateMessages = _useState2[1];
61
+ (0, _react.useEffect)(function () {
62
+ if (currentValue && !!currentValue) {
63
+ setShowValidateMessages(true);
64
+ }
65
+ }, [currentValue]);
60
66
  return /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, getEventProps(_objectSpread(_objectSpread({}, props), {}, {
61
67
  handleShowValidateMessages: function handleShowValidateMessages(value) {
62
68
  return setShowValidateMessages(value);
@@ -65,7 +71,7 @@ var FieldMask = function FieldMask(props) {
65
71
  errorMessages: (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
66
72
  fieldErrors: showValidateMessages ? props.fieldErrors : {}
67
73
  })),
68
- value: _lodash.default.get(data, name)
74
+ value: currentValue
69
75
  }));
70
76
  };
71
77
  var _default = (0, _withFieldHOC.default)(FieldMask);
@@ -33,6 +33,12 @@ var FieldPeriod = function FieldPeriod(props) {
33
33
  _useState2 = _slicedToArray(_useState, 2),
34
34
  showValidateMessages = _useState2[0],
35
35
  setShowValidateMessages = _useState2[1];
36
+ var currentValue = _lodash.default.get(data, nameDateInitial);
37
+ (0, _react.useEffect)(function () {
38
+ if (currentValue && (!!currentValue || currentValue === 0 || Array.isArray(currentValue) && currentValue.length > 0)) {
39
+ setShowValidateMessages(true);
40
+ }
41
+ }, [currentValue]);
36
42
  var errorMessages = (0, _helpers.getErrorMessages)({
37
43
  name: nameDateInitial,
38
44
  fieldErrors: showValidateMessages ? fieldErrors : {},
@@ -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: (data: 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,26 +13,23 @@ 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); }
18
16
  var securityBeforeUnload = 'securityBeforeUnload';
19
17
  exports.securityBeforeUnload = securityBeforeUnload;
20
18
  var FormContext = /*#__PURE__*/_react.default.createContext({});
21
19
  exports.FormContext = FormContext;
22
20
  var withFieldContext = /*#__PURE__*/_react.default.createContext({});
23
21
  exports.withFieldContext = withFieldContext;
24
- var changeValue = function changeValue(_ref, target) {
25
- var newData = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
22
+ var changeValue = function changeValue(data, target) {
26
23
  var name = target.name,
27
24
  value = target.value;
28
- return _lodash.default.set(JSON.parse(JSON.stringify(newData)), name, value);
25
+ return _lodash.default.set(JSON.parse(JSON.stringify(data)), name, value);
29
26
  };
30
27
  exports.changeValue = changeValue;
31
- var getErrorMessages = function getErrorMessages(_ref2) {
32
- var name = _ref2.name,
33
- fieldErrors = _ref2.fieldErrors,
34
- externalFieldErrors = _ref2.externalFieldErrors,
35
- externalMessagesErrors = _ref2.externalMessagesErrors;
28
+ var getErrorMessages = function getErrorMessages(_ref) {
29
+ var name = _ref.name,
30
+ fieldErrors = _ref.fieldErrors,
31
+ externalFieldErrors = _ref.externalFieldErrors,
32
+ externalMessagesErrors = _ref.externalMessagesErrors;
36
33
  var errors = externalMessagesErrors ? _toConsumableArray(externalMessagesErrors) : [];
37
34
  if (fieldErrors && fieldErrors[name]) {
38
35
  errors = [].concat(_toConsumableArray(errors), _toConsumableArray(fieldErrors[name]));
package/lib/form/index.js CHANGED
@@ -112,7 +112,10 @@ var Form = function Form(_ref) {
112
112
  };
113
113
  var getErrorMessages = function getErrorMessages(currentData, currentValidators) {
114
114
  var dataValidate = currentData || usedData;
115
- var currentFieldErrors = _objectSpread({}, fieldErrors);
115
+ var currentFieldErrors = _lodash.default.pickBy(fieldErrors, function (error, fieldName) {
116
+ var fieldValidatorsNames = Object.keys(currentValidators);
117
+ return fieldValidatorsNames.includes(fieldName);
118
+ });
116
119
  _lodash.default.forEach(currentValidators, function (validators, fieldName) {
117
120
  var fieldValue = _lodash.default.get(dataValidate, fieldName);
118
121
  var messages = getValidatesErrorMessages(validators, fieldValue);
@@ -43,9 +43,12 @@ type FormProps = BaseFormProps & ({
43
43
  useInternalState: true;
44
44
  onDataChange?: (data: object) => void;
45
45
  });
46
+ type Data = {
47
+ [key: string]: any;
48
+ };
46
49
  interface IFieldProps extends WithFieldProps {
47
- data?: object;
48
- dataSource?: object;
50
+ data?: Data;
51
+ dataSource?: Data;
49
52
  name: string;
50
53
  value?: string;
51
54
  label?: string;
@@ -84,8 +87,8 @@ interface CustomEvent {
84
87
  };
85
88
  }
86
89
  interface IFieldArrayProps extends WithFieldProps {
87
- data?: object;
88
- dataSource?: object;
90
+ data?: Data;
91
+ dataSource?: Data;
89
92
  name: string;
90
93
  handlerFieldChange?: (event: CustomEvent) => void;
91
94
  fieldErrors?: {
@@ -120,7 +123,7 @@ type PeriodFieldChangeEvent = {
120
123
  };
121
124
  };
122
125
  interface IFieldPeriodProps extends WithFieldProps {
123
- data?: object;
126
+ data?: Data;
124
127
  nameDateInitial: string;
125
128
  nameDateFinal: string;
126
129
  handlerFieldChange?: (event: PeriodFieldChangeEvent) => PeriodFieldChangeEvent;
@@ -9,7 +9,6 @@ var _imask = _interopRequireDefault(require("imask"));
9
9
  var helpers = _interopRequireWildcard(require("./helpers"));
10
10
  var _permissionValidations = require("../../permissionValidations");
11
11
  var _format_number = require("../number/format_number");
12
- var _this = void 0;
13
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
13
  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); }
15
14
  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; }
@@ -100,7 +99,7 @@ var IMaskHOC = function IMaskHOC(ComposedComponent) {
100
99
  maskRef.current.value = String(newValue);
101
100
  }
102
101
  };
103
- var onAccept = function onAccept() {
102
+ var onAccept = (0, _react.useCallback)(function () {
104
103
  if (onChange && !disableCallbacks && maskRef.current) {
105
104
  var _maskRef$current = maskRef.current,
106
105
  unmaskedValue = _maskRef$current.unmaskedValue,
@@ -113,8 +112,8 @@ var IMaskHOC = function IMaskHOC(ComposedComponent) {
113
112
  }
114
113
  }, props.unmask ? unmaskedValue : maskRef.current.value);
115
114
  }
116
- };
117
- var onComplete = function onComplete() {
115
+ }, [onChange]);
116
+ var onComplete = (0, _react.useCallback)(function () {
118
117
  if (props.onComplete && !disableCallbacks && maskRef.current) {
119
118
  var _maskRef$current2 = maskRef.current,
120
119
  unmaskedValue = _maskRef$current2.unmaskedValue,
@@ -127,13 +126,14 @@ var IMaskHOC = function IMaskHOC(ComposedComponent) {
127
126
  }
128
127
  }, props.unmask ? unmaskedValue : maskRef.current.value);
129
128
  }
130
- };
129
+ }, [props.onComplete]);
131
130
  var getMask = function getMask() {
132
131
  var element = elementRef.current;
133
132
  if (element) {
134
133
  var maskCurrent = maskRef.current;
135
134
  if (!maskCurrent) {
136
- maskRef.current = (0, _imask.default)(element, maskOptions).on('accept', onAccept.bind(_this)).on('complete', onComplete.bind(_this));
135
+ maskRef.current = (0, _imask.default)(element, maskOptions);
136
+ if (value && typeof value !== 'number' && value.trim() !== '' || value && typeof value === 'number') onAccept();
137
137
  setValue(value);
138
138
  } else {
139
139
  maskCurrent.updateOptions(maskOptions);
@@ -150,14 +150,19 @@ var IMaskHOC = function IMaskHOC(ComposedComponent) {
150
150
  if (props.handlerSetOnDenied) props.handlerSetOnDenied(onDenied);
151
151
  if (!props.mask || dontInitMask) return;
152
152
  getMask();
153
+ }, [maskOptions]);
154
+ (0, _react.useEffect)(function () {
155
+ if (!maskRef.current) return;
156
+ var maskCurrent = maskRef.current;
157
+ maskCurrent.on('accept', onAccept);
158
+ maskCurrent.on('complete', onComplete);
153
159
 
154
160
  // eslint-disable-next-line consistent-return
155
161
  return function () {
156
- var _maskRef$current3, _maskRef$current4;
157
- (_maskRef$current3 = maskRef.current) === null || _maskRef$current3 === void 0 ? void 0 : _maskRef$current3.off('accept', onAccept);
158
- (_maskRef$current4 = maskRef.current) === null || _maskRef$current4 === void 0 ? void 0 : _maskRef$current4.off('complete', onComplete);
162
+ maskCurrent.off('accept', onAccept);
163
+ maskCurrent.off('complete', onComplete);
159
164
  };
160
- }, [maskOptions]);
165
+ }, [onAccept, onComplete]);
161
166
  (0, _react.useEffect)(function () {
162
167
  if (maskOptions.mask && !dontInitMask) {
163
168
  if (maskRef.current) {
@@ -182,7 +187,6 @@ var IMaskHOC = function IMaskHOC(ComposedComponent) {
182
187
  },
183
188
  inputRef: function inputRef(el) {
184
189
  elementRef.current = el;
185
- // Propagate the input ref for who call it
186
190
  if (_inputRef) {
187
191
  if (_typeof(_inputRef) === 'object') _inputRef.current = el;else _inputRef(el);
188
192
  }
@@ -24,13 +24,12 @@ var returnEventFormattedValue = function returnEventFormattedValue(props, event)
24
24
  var _event$target = event.target,
25
25
  value = _event$target.value,
26
26
  name = _event$target.name;
27
- var teste = _objectSpread(_objectSpread({}, event), {}, {
27
+ return _objectSpread(_objectSpread({}, event), {}, {
28
28
  target: {
29
29
  value: (0, _format_number.numberToEnUS)(value),
30
30
  name: name
31
31
  }
32
32
  });
33
- return teste;
34
33
  }
35
34
  return event;
36
35
  };
@@ -14,7 +14,7 @@ exports.numberToPtBR = numberToPtBR;
14
14
  var numberToEnUS = function numberToEnUS(value) {
15
15
  var formattedNumber;
16
16
  if (value) {
17
- formattedNumber = value.replace('.', '').replace(',', '.');
17
+ formattedNumber = value.replaceAll('.', '').replaceAll(',', '.');
18
18
  return Number(formattedNumber);
19
19
  }
20
20
  return value;
@@ -31,7 +31,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
31
31
  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; } }
32
32
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
33
  var PeriodPicker = function PeriodPicker(props) {
34
- var _props$value2, _props$value3;
35
34
  var _props$showButtonOpen = props.showButtonOpen,
36
35
  showButtonOpen = _props$showButtonOpen === void 0 ? true : _props$showButtonOpen,
37
36
  _props$openOnFocus = props.openOnFocus,
@@ -138,7 +137,7 @@ var PeriodPicker = function PeriodPicker(props) {
138
137
  setValueInitial(newValueInitial);
139
138
  setValueFinal(newValueFinal);
140
139
  }
141
- }, [(_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : _props$value2.initial, (_props$value3 = props.value) === null || _props$value3 === void 0 ? void 0 : _props$value3.final]);
140
+ }, [props.value]);
142
141
  var openCalendar = function openCalendar() {
143
142
  setShowCalendar(true);
144
143
  setShowPeriodSelection(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.0.10-beta.20",
3
+ "version": "1.0.10-beta.22",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",