linear-react-components-ui 0.4.76-rc.4 → 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.
- package/lib/dialog/base/index.js +1 -1
- package/lib/form/index.js +198 -274
- package/lib/form/withFormSecurity.js +8 -8
- package/lib/internals/withTooltip.js +4 -5
- package/lib/tooltip/index.js +2 -2
- package/package.json +1 -1
package/lib/dialog/base/index.js
CHANGED
|
@@ -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.
|
|
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
|
@@ -45,323 +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
|
|
68
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
65
69
|
|
|
66
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
139
|
+
_lodash["default"].forEach(fieldsValidators, function (validators, fieldName) {
|
|
140
|
+
var fieldValue = _lodash["default"].get(dataValidate, fieldName);
|
|
77
141
|
|
|
78
|
-
|
|
142
|
+
var messages = getValidatesErrorMessages(validators, fieldValue);
|
|
79
143
|
|
|
80
|
-
|
|
144
|
+
if (messages.length > 0) {
|
|
145
|
+
currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
81
148
|
|
|
82
|
-
|
|
149
|
+
if (updateState) setFieldErrors(currentFieldErrors);
|
|
150
|
+
return _lodash["default"].isEmpty(currentFieldErrors);
|
|
151
|
+
};
|
|
83
152
|
|
|
84
|
-
|
|
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
|
-
|
|
158
|
+
var newData = _extends({}, data, _defineProperty({}, name, value));
|
|
87
159
|
|
|
88
|
-
|
|
160
|
+
if (context) {
|
|
161
|
+
var onChangedData = context.onChangedData;
|
|
89
162
|
|
|
90
|
-
|
|
91
|
-
|
|
163
|
+
if (onChangedData) {
|
|
164
|
+
if (!_lodash["default"].isEqual(newData, originalData)) {
|
|
165
|
+
onChangedData(true);
|
|
166
|
+
} else {
|
|
167
|
+
onChangedData(false);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
92
171
|
|
|
93
|
-
|
|
172
|
+
setData(newData); // TODO - Usar debounce para evitar chamada a cada letra digitada
|
|
94
173
|
|
|
95
|
-
|
|
96
|
-
|
|
174
|
+
if (onValidateForm) onValidateForm(checkIsValid(newData, false));
|
|
175
|
+
if (onDataChange) onDataChange(newData);
|
|
176
|
+
};
|
|
97
177
|
|
|
98
|
-
|
|
178
|
+
var onValidate = function onValidate(fieldName, fieldValue, validators) {
|
|
179
|
+
if (validators) {
|
|
180
|
+
var currentFieldErrors = fieldErrors;
|
|
181
|
+
var errors = getValidatesErrorMessages(validators, fieldValue);
|
|
99
182
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
189
|
+
setFieldErrors(currentFieldErrors);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
111
192
|
|
|
112
|
-
|
|
113
|
-
|
|
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: {}
|
|
114
202
|
});
|
|
115
|
-
|
|
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
|
-
|
|
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
|
|
203
|
+
};
|
|
140
204
|
|
|
205
|
+
var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
|
|
206
|
+
var newFieldsValidators = _lodash["default"].omit(fieldsValidators, fieldName);
|
|
141
207
|
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
});
|
|
247
|
-
|
|
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
|
-
}
|
|
208
|
+
setFieldsValidators(newFieldsValidators);
|
|
209
|
+
};
|
|
276
210
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
}
|
|
211
|
+
var onBeforeUnload = function onBeforeUnload(e) {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
|
|
214
|
+
if (_lodash["default"].isEqual(data, originalData)) {
|
|
215
|
+
return;
|
|
294
216
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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();
|
|
299
225
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
}));
|
|
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);
|
|
337
251
|
}
|
|
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
252
|
|
|
352
|
-
|
|
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);
|
|
353
264
|
}
|
|
354
|
-
}]);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
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
|
+
};
|
|
358
288
|
|
|
359
|
-
Object.defineProperty(Form, "contextType", {
|
|
360
|
-
configurable: true,
|
|
361
|
-
enumerable: true,
|
|
362
|
-
writable: true,
|
|
363
|
-
value: _withFormSecurity.FormSecurityContext
|
|
364
|
-
});
|
|
365
289
|
Form.propTypes = {
|
|
366
290
|
dataSource: _propTypes["default"].object.isRequired,
|
|
367
291
|
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
|
-
|
|
54
|
-
|
|
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,
|
|
@@ -76,7 +76,7 @@ var withTooltip = function withTooltip(WrappedComponent) {
|
|
|
76
76
|
var targetElement = (0, _react.useRef)();
|
|
77
77
|
|
|
78
78
|
var onMouseOver = function onMouseOver(e) {
|
|
79
|
-
if (targetElement
|
|
79
|
+
if (targetElement.current.contains(e.target)) {
|
|
80
80
|
setShowTooltip(true);
|
|
81
81
|
} else setShowTooltip(false);
|
|
82
82
|
};
|
|
@@ -116,7 +116,6 @@ var withTooltip = function withTooltip(WrappedComponent) {
|
|
|
116
116
|
height = tooltipDimensions.height;
|
|
117
117
|
var targetDimensions = targetElement.current.getBoundingClientRect();
|
|
118
118
|
var targetVerticalCenter = (targetDimensions.top + targetDimensions.bottom) / 2;
|
|
119
|
-
var formattedWidth = typeof width === 'string' ? Number(width.slice(0, -2)) : width;
|
|
120
119
|
var style = "width: ".concat(width, "px");
|
|
121
120
|
var left = targetDimensions.left + targetDimensions.width / 2 - width / 2;
|
|
122
121
|
left = Math.min(left, document.body.clientWidth - width - space);
|
|
@@ -142,17 +141,17 @@ var withTooltip = function withTooltip(WrappedComponent) {
|
|
|
142
141
|
break;
|
|
143
142
|
|
|
144
143
|
case 'left':
|
|
145
|
-
if (targetDimensions.left <
|
|
144
|
+
if (targetDimensions.left < width) {
|
|
146
145
|
setTooltipPosition('right');
|
|
147
146
|
} else {
|
|
148
147
|
style += "; top: ".concat(targetVerticalCenter + window.scrollY - height / 2, "px");
|
|
149
|
-
style += "; left: ".concat(targetDimensions.left -
|
|
148
|
+
style += "; left: ".concat(targetDimensions.left - width - 6, "px");
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
break;
|
|
153
152
|
|
|
154
153
|
case 'right':
|
|
155
|
-
if (window.innerWidth - targetDimensions.right <
|
|
154
|
+
if (window.innerWidth - targetDimensions.right < width) {
|
|
156
155
|
setTooltipPosition('left');
|
|
157
156
|
} else {
|
|
158
157
|
style += "; top: ".concat(targetVerticalCenter + window.scrollY - height / 2, "px");
|
package/lib/tooltip/index.js
CHANGED
|
@@ -42,8 +42,8 @@ var Tooltip = function Tooltip(props) {
|
|
|
42
42
|
var tooltipEl = document.querySelector("div#".concat(tooltipComponent.current.id));
|
|
43
43
|
var width = tooltipEl.offsetWidth;
|
|
44
44
|
|
|
45
|
-
if (tooltipDimensions.width
|
|
46
|
-
width =
|
|
45
|
+
if (tooltipDimensions.width) {
|
|
46
|
+
width = tooltipDimensions.width;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
var height = tooltipEl.offsetHeight;
|