linear-react-components-ui 0.4.75-rc.0 → 0.4.76-beta.2
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/.DS_Store +0 -0
- package/lib/dialog/base/index.js +1 -1
- package/lib/form/index.js +195 -273
- package/lib/form/withFormSecurity.js +8 -8
- package/lib/treeview/index.js +9 -19
- package/package.json +1 -1
package/.DS_Store
ADDED
|
Binary file
|
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
|
@@ -51,317 +51,239 @@ 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
|
|
66
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
65
67
|
|
|
66
|
-
function
|
|
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
|
|
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); }
|
|
69
71
|
|
|
70
|
-
function
|
|
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; }
|
|
71
73
|
|
|
72
|
-
function
|
|
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
|
+
};
|
|
73
131
|
|
|
74
|
-
|
|
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 = {};
|
|
75
136
|
|
|
76
|
-
|
|
137
|
+
_lodash["default"].forEach(fieldsValidators, function (validators, fieldName) {
|
|
138
|
+
var fieldValue = _lodash["default"].get(dataValidate, fieldName);
|
|
77
139
|
|
|
78
|
-
|
|
140
|
+
var messages = getValidatesErrorMessages(validators, fieldValue);
|
|
79
141
|
|
|
80
|
-
|
|
142
|
+
if (messages.length > 0) {
|
|
143
|
+
currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
81
146
|
|
|
82
|
-
|
|
147
|
+
if (updateState) setFieldErrors(currentFieldErrors);
|
|
148
|
+
return _lodash["default"].isEmpty(currentFieldErrors);
|
|
149
|
+
};
|
|
83
150
|
|
|
84
|
-
|
|
151
|
+
var onFieldChange = function onFieldChange(e) {
|
|
152
|
+
var _e$target = e.target,
|
|
153
|
+
name = _e$target.name,
|
|
154
|
+
value = _e$target.value;
|
|
85
155
|
|
|
86
|
-
|
|
156
|
+
var newData = _extends({}, data, _defineProperty({}, name, value));
|
|
87
157
|
|
|
88
|
-
|
|
158
|
+
if (context) {
|
|
159
|
+
var onChangedData = context.onChangedData;
|
|
89
160
|
|
|
90
|
-
|
|
91
|
-
|
|
161
|
+
if (onChangedData) {
|
|
162
|
+
if (!_lodash["default"].isEqual(newData, originalData)) {
|
|
163
|
+
onChangedData(true);
|
|
164
|
+
} else {
|
|
165
|
+
onChangedData(false);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
92
169
|
|
|
93
|
-
|
|
170
|
+
setData(newData); // TODO - Usar debounce para evitar chamada a cada letra digitada
|
|
94
171
|
|
|
95
|
-
|
|
96
|
-
|
|
172
|
+
if (onValidateForm) onValidateForm(checkIsValid(newData, false));
|
|
173
|
+
if (onDataChange) onDataChange(newData);
|
|
174
|
+
};
|
|
97
175
|
|
|
98
|
-
|
|
176
|
+
var onValidate = function onValidate(fieldName, fieldValue, validators) {
|
|
177
|
+
if (validators) {
|
|
178
|
+
var currentFieldErrors = fieldErrors;
|
|
179
|
+
var errors = getValidatesErrorMessages(validators, fieldValue);
|
|
99
180
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
value: function value(e) {
|
|
106
|
-
e.preventDefault();
|
|
181
|
+
if (errors.length === 0) {
|
|
182
|
+
currentFieldErrors = _lodash["default"].omit(currentFieldErrors, fieldName);
|
|
183
|
+
} else {
|
|
184
|
+
currentFieldErrors = _extends({}, currentFieldErrors, _defineProperty({}, fieldName, errors));
|
|
185
|
+
}
|
|
107
186
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
187
|
+
setFieldErrors(currentFieldErrors);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
111
190
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
});
|
|
191
|
+
var onFormSubmit = function onFormSubmit(event) {
|
|
192
|
+
if (event) event.preventDefault();
|
|
193
|
+
if (checkIsValid(data)) onSubmit(data);
|
|
194
|
+
};
|
|
134
195
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} // TODO - Usar debounce para evitar chamada a cada letra digitada
|
|
196
|
+
var onReset = function onReset() {
|
|
197
|
+
setData(JSON.parse(JSON.stringify(originalData)));
|
|
198
|
+
setFieldErrors({});
|
|
199
|
+
};
|
|
140
200
|
|
|
201
|
+
var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
|
|
202
|
+
var newFieldsValidators = _lodash["default"].omit(fieldsValidators, fieldName);
|
|
141
203
|
|
|
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
|
-
});
|
|
204
|
+
setFieldsValidators(newFieldsValidators);
|
|
205
|
+
};
|
|
247
206
|
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
}
|
|
207
|
+
var onBeforeUnload = function onBeforeUnload(e) {
|
|
208
|
+
e.preventDefault();
|
|
276
209
|
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
}
|
|
210
|
+
if (_lodash["default"].isEqual(data, originalData)) {
|
|
211
|
+
return;
|
|
294
212
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}, []);
|
|
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
|
-
|
|
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
|
-
|
|
357
|
-
}
|
|
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
|
+
customClassName: "classTeste",
|
|
279
|
+
title: securityTitle || 'Dados Alterados',
|
|
280
|
+
text: securityText || 'Vocẽ possui dados alterados, confirma o fechamento?',
|
|
281
|
+
visible: !!context && context.showQuestion,
|
|
282
|
+
onConfirmClick: context ? context.onConfirmClick : function () {},
|
|
283
|
+
onUnconfirmClick: context ? context.onUnconfirmClick : function () {}
|
|
284
|
+
}));
|
|
285
|
+
};
|
|
358
286
|
|
|
359
|
-
Object.defineProperty(Form, "contextType", {
|
|
360
|
-
configurable: true,
|
|
361
|
-
enumerable: true,
|
|
362
|
-
writable: true,
|
|
363
|
-
value: _withFormSecurity.FormSecurityContext
|
|
364
|
-
});
|
|
365
287
|
Form.propTypes = {
|
|
366
288
|
dataSource: _propTypes["default"].object.isRequired,
|
|
367
289
|
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,
|
package/lib/treeview/index.js
CHANGED
|
@@ -78,6 +78,15 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
78
78
|
|
|
79
79
|
var _super = _createSuper(TreeView);
|
|
80
80
|
|
|
81
|
+
// static getDerivedStateFromProps(props, state) {
|
|
82
|
+
// const { data, selectedIds } = props;
|
|
83
|
+
// const { propSelectedIds } = state;
|
|
84
|
+
// const isSameSelectedIds = _.isEqual(propSelectedIds.sort(), selectedIds.sort());
|
|
85
|
+
// if (data !== state.data || !isSameSelectedIds) {
|
|
86
|
+
// return { data, selectedIds, propSelectedIds: selectedIds };
|
|
87
|
+
// }
|
|
88
|
+
// return null;
|
|
89
|
+
// }
|
|
81
90
|
function TreeView(props) {
|
|
82
91
|
var _this;
|
|
83
92
|
|
|
@@ -542,25 +551,6 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
542
551
|
className: "treeviewcontainer ".concat(bordered && '-bordered')
|
|
543
552
|
}, this.buildTree(data))));
|
|
544
553
|
}
|
|
545
|
-
}], [{
|
|
546
|
-
key: "getDerivedStateFromProps",
|
|
547
|
-
value: function getDerivedStateFromProps(props, state) {
|
|
548
|
-
var data = props.data,
|
|
549
|
-
selectedIds = props.selectedIds;
|
|
550
|
-
var propSelectedIds = state.propSelectedIds;
|
|
551
|
-
|
|
552
|
-
var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), selectedIds.sort());
|
|
553
|
-
|
|
554
|
-
if (data !== state.data || !isSameSelectedIds) {
|
|
555
|
-
return {
|
|
556
|
-
data: data,
|
|
557
|
-
selectedIds: selectedIds,
|
|
558
|
-
propSelectedIds: selectedIds
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
return null;
|
|
563
|
-
}
|
|
564
554
|
}]);
|
|
565
555
|
|
|
566
556
|
return TreeView;
|