linear-react-components-ui 0.4.76-beta.4 → 0.4.76-beta.8
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/assets/styles/tabs.scss +2 -1
- package/lib/dialog/base/index.js +1 -1
- package/lib/form/index.js +273 -195
- package/lib/form/withFormSecurity.js +8 -8
- package/lib/tabs/index.js +74 -50
- package/lib/treeview/index.js +5 -11
- package/package.json +1 -1
- package/.DS_Store +0 -0
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.className !== 'button-component') return;
|
|
56
56
|
handlerClose();
|
|
57
57
|
}
|
|
58
58
|
};
|
package/lib/form/index.js
CHANGED
|
@@ -51,239 +51,317 @@ 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
|
-
|
|
58
54
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
59
55
|
|
|
60
56
|
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."); }
|
|
61
57
|
|
|
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
|
+
|
|
62
60
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
63
61
|
|
|
64
62
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
65
63
|
|
|
66
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
67
|
-
|
|
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."); }
|
|
69
|
-
|
|
70
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
71
|
-
|
|
72
64
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
73
65
|
|
|
74
|
-
function
|
|
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
|
-
};
|
|
66
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
131
67
|
|
|
132
|
-
|
|
133
|
-
var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
134
|
-
var dataValidate = value || data;
|
|
135
|
-
var currentFieldErrors = {};
|
|
68
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
136
69
|
|
|
137
|
-
|
|
138
|
-
var fieldValue = _lodash["default"].get(dataValidate, fieldName);
|
|
70
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
139
71
|
|
|
140
|
-
|
|
72
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
141
73
|
|
|
142
|
-
|
|
143
|
-
currentFieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
74
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
146
75
|
|
|
147
|
-
|
|
148
|
-
return _lodash["default"].isEmpty(currentFieldErrors);
|
|
149
|
-
};
|
|
76
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
150
77
|
|
|
151
|
-
|
|
152
|
-
var _e$target = e.target,
|
|
153
|
-
name = _e$target.name,
|
|
154
|
-
value = _e$target.value;
|
|
78
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
155
79
|
|
|
156
|
-
|
|
80
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
157
81
|
|
|
158
|
-
|
|
159
|
-
var onChangedData = context.onChangedData;
|
|
82
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
160
83
|
|
|
161
|
-
|
|
162
|
-
if (!_lodash["default"].isEqual(newData, originalData)) {
|
|
163
|
-
onChangedData(true);
|
|
164
|
-
} else {
|
|
165
|
-
onChangedData(false);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
84
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
169
85
|
|
|
170
|
-
|
|
86
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
171
87
|
|
|
172
|
-
|
|
173
|
-
if (onDataChange) onDataChange(newData);
|
|
174
|
-
};
|
|
88
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
175
89
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
var currentFieldErrors = fieldErrors;
|
|
179
|
-
var errors = getValidatesErrorMessages(validators, fieldValue);
|
|
90
|
+
var Form = /*#__PURE__*/function (_Component) {
|
|
91
|
+
_inherits(Form, _Component);
|
|
180
92
|
|
|
181
|
-
|
|
182
|
-
currentFieldErrors = _lodash["default"].omit(currentFieldErrors, fieldName);
|
|
183
|
-
} else {
|
|
184
|
-
currentFieldErrors = _extends({}, currentFieldErrors, _defineProperty({}, fieldName, errors));
|
|
185
|
-
}
|
|
93
|
+
var _super = _createSuper(Form);
|
|
186
94
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
95
|
+
function Form(props) {
|
|
96
|
+
var _this;
|
|
190
97
|
|
|
191
|
-
|
|
192
|
-
if (event) event.preventDefault();
|
|
193
|
-
if (checkIsValid(data)) onSubmit(data);
|
|
194
|
-
};
|
|
98
|
+
_classCallCheck(this, Form);
|
|
195
99
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
100
|
+
_this = _super.call(this, props);
|
|
101
|
+
Object.defineProperty(_assertThisInitialized(_this), "onBeforeUnload", {
|
|
102
|
+
configurable: true,
|
|
103
|
+
enumerable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: function value(e) {
|
|
106
|
+
e.preventDefault();
|
|
200
107
|
|
|
201
|
-
|
|
202
|
-
|
|
108
|
+
if (Object.is(_this.state.data, _this.state.originalData)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
203
111
|
|
|
204
|
-
|
|
205
|
-
|
|
112
|
+
e.returnValue = true;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(_assertThisInitialized(_this), "onFieldChange", {
|
|
116
|
+
configurable: true,
|
|
117
|
+
enumerable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: function value(e) {
|
|
120
|
+
var _this$props = _this.props,
|
|
121
|
+
onValidateForm = _this$props.onValidateForm,
|
|
122
|
+
onDataChange = _this$props.onDataChange;
|
|
123
|
+
var data = _this.state.data;
|
|
124
|
+
var _e$target = e.target,
|
|
125
|
+
name = _e$target.name,
|
|
126
|
+
value = _e$target.value;
|
|
127
|
+
var onChangedData = _this.context.onChangedData;
|
|
128
|
+
|
|
129
|
+
_lodash["default"].set(data, name, value);
|
|
130
|
+
|
|
131
|
+
_this.setState({
|
|
132
|
+
data: data
|
|
133
|
+
});
|
|
206
134
|
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
209
140
|
|
|
210
|
-
if (_lodash["default"].isEqual(data, originalData)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
141
|
|
|
214
|
-
|
|
215
|
-
|
|
142
|
+
if (onValidateForm) onValidateForm(_this.checkIsValid(data, false));
|
|
143
|
+
if (onDataChange) onDataChange(data);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(_assertThisInitialized(_this), "onValidate", {
|
|
147
|
+
configurable: true,
|
|
148
|
+
enumerable: true,
|
|
149
|
+
writable: true,
|
|
150
|
+
value: function value(fieldName, fieldValue, validators) {
|
|
151
|
+
if (validators) {
|
|
152
|
+
var fieldErrors = _this.state.fieldErrors;
|
|
153
|
+
|
|
154
|
+
var errors = _this.getValidatesErrorMessages(validators, fieldValue);
|
|
155
|
+
|
|
156
|
+
if (errors.length === 0) {
|
|
157
|
+
fieldErrors = _lodash["default"].omit(fieldErrors, fieldName);
|
|
158
|
+
} else {
|
|
159
|
+
fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, errors));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_this.setState({
|
|
163
|
+
fieldErrors: fieldErrors
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(_assertThisInitialized(_this), "onSubmit", {
|
|
169
|
+
configurable: true,
|
|
170
|
+
enumerable: true,
|
|
171
|
+
writable: true,
|
|
172
|
+
value: function value(event) {
|
|
173
|
+
if (event) event.preventDefault();
|
|
174
|
+
var data = _this.state.data;
|
|
175
|
+
if (_this.checkIsValid(data)) _this.props.onSubmit(data);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(_assertThisInitialized(_this), "onReset", {
|
|
179
|
+
configurable: true,
|
|
180
|
+
enumerable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
value: function value() {
|
|
183
|
+
_this.setState({
|
|
184
|
+
data: JSON.parse(JSON.stringify(_this.state.originalData)),
|
|
185
|
+
fieldErrors: {}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(_assertThisInitialized(_this), "onRemoveFieldValidators", {
|
|
190
|
+
configurable: true,
|
|
191
|
+
enumerable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: function value(fieldName) {
|
|
194
|
+
_this.fieldsValidators = _lodash["default"].omit(_this.fieldsValidators, fieldName);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(_assertThisInitialized(_this), "getValidatesErrorMessages", {
|
|
198
|
+
configurable: true,
|
|
199
|
+
enumerable: true,
|
|
200
|
+
writable: true,
|
|
201
|
+
value: function value(validators, fieldValue) {
|
|
202
|
+
var validatorsArray = !(validators instanceof Array) ? [validators] : validators;
|
|
203
|
+
var errors = [];
|
|
204
|
+
validatorsArray.forEach(function (validator) {
|
|
205
|
+
var result = validator(fieldValue);
|
|
206
|
+
if (result) errors = [].concat(_toConsumableArray(errors), [result]);
|
|
207
|
+
});
|
|
208
|
+
return errors;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(_assertThisInitialized(_this), "getContextValue", {
|
|
212
|
+
configurable: true,
|
|
213
|
+
enumerable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: function value() {
|
|
216
|
+
return {
|
|
217
|
+
handlerFieldChange: _this.onFieldChange,
|
|
218
|
+
handlerFieldValidade: _this.onValidate,
|
|
219
|
+
handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
|
|
220
|
+
_this.fieldsValidators = _extends({}, _this.fieldsValidators, _defineProperty({}, fieldName, fieldValidates));
|
|
221
|
+
},
|
|
222
|
+
handlerRemoveValidators: _this.onRemoveFieldValidators,
|
|
223
|
+
data: _this.state.data,
|
|
224
|
+
fieldErrors: _this.state.fieldErrors,
|
|
225
|
+
externalFieldErrors: _this.props.externalFieldErrors
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(_assertThisInitialized(_this), "checkIsValid", {
|
|
230
|
+
configurable: true,
|
|
231
|
+
enumerable: true,
|
|
232
|
+
writable: true,
|
|
233
|
+
value: function value(data) {
|
|
234
|
+
var updateState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
235
|
+
var dataValidate = data || _this.state.data;
|
|
236
|
+
var fieldErrors = {};
|
|
237
|
+
|
|
238
|
+
_lodash["default"].forEach(_this.fieldsValidators, function (validators, fieldName) {
|
|
239
|
+
var fieldValue = _lodash["default"].get(dataValidate, fieldName);
|
|
240
|
+
|
|
241
|
+
var messages = _this.getValidatesErrorMessages(validators, fieldValue);
|
|
242
|
+
|
|
243
|
+
if (messages.length > 0) {
|
|
244
|
+
fieldErrors = _extends({}, fieldErrors, _defineProperty({}, fieldName, messages));
|
|
245
|
+
}
|
|
246
|
+
});
|
|
216
247
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
event.preventDefault();
|
|
220
|
-
if (submitFormOnEnter) onFormSubmit();
|
|
221
|
-
}
|
|
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));
|
|
248
|
+
if (updateState) _this.setState({
|
|
249
|
+
fieldErrors: fieldErrors
|
|
231
250
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
|
237
273
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
274
|
+
return _this;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_createClass(Form, [{
|
|
278
|
+
key: "componentDidMount",
|
|
279
|
+
value: function componentDidMount() {
|
|
280
|
+
var _this$props2 = this.props,
|
|
281
|
+
handlerReset = _this$props2.handlerReset,
|
|
282
|
+
handlerSubmit = _this$props2.handlerSubmit,
|
|
283
|
+
handlerValidates = _this$props2.handlerValidates,
|
|
284
|
+
securityBeforeUnload = _this$props2.securityBeforeUnload;
|
|
285
|
+
var setSecurityBeforeUnload = this.context.setSecurityBeforeUnload;
|
|
286
|
+
handlerSubmit(this.onSubmit);
|
|
287
|
+
if (handlerReset) handlerReset(this.onReset);
|
|
288
|
+
if (handlerValidates) handlerValidates(this.checkIsValid);
|
|
289
|
+
|
|
290
|
+
if (securityBeforeUnload) {
|
|
291
|
+
setSecurityBeforeUnload(true);
|
|
292
|
+
window.addEventListener('beforeunload', this.onBeforeUnload);
|
|
293
|
+
}
|
|
249
294
|
}
|
|
295
|
+
}, {
|
|
296
|
+
key: "componentWillUnmount",
|
|
297
|
+
value: function componentWillUnmount() {
|
|
298
|
+
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
|
299
|
+
}
|
|
300
|
+
}, {
|
|
301
|
+
key: "render",
|
|
302
|
+
value: function render() {
|
|
303
|
+
var _this2 = this;
|
|
304
|
+
|
|
305
|
+
var _this$props3 = this.props,
|
|
306
|
+
style = _this$props3.style,
|
|
307
|
+
customClass = _this$props3.customClass,
|
|
308
|
+
children = _this$props3.children,
|
|
309
|
+
securityBeforeUnload = _this$props3.securityBeforeUnload,
|
|
310
|
+
securityTitle = _this$props3.securityTitle,
|
|
311
|
+
securityText = _this$props3.securityText;
|
|
312
|
+
var _this$context = this.context,
|
|
313
|
+
showQuestion = _this$context.showQuestion,
|
|
314
|
+
onUnconfirmClick = _this$context.onUnconfirmClick,
|
|
315
|
+
onConfirmClick = _this$context.onConfirmClick;
|
|
316
|
+
return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_helpers.FormContext.Provider, {
|
|
317
|
+
value: this.getContextValue()
|
|
318
|
+
}, /*#__PURE__*/_react["default"].createElement("form", {
|
|
319
|
+
style: style,
|
|
320
|
+
onSubmit: function onSubmit(e) {
|
|
321
|
+
e.preventDefault();
|
|
322
|
+
},
|
|
323
|
+
onKeyPress: function onKeyPress(e) {
|
|
324
|
+
_this2.submitOnEnter(e);
|
|
325
|
+
},
|
|
326
|
+
role: "presentation",
|
|
327
|
+
className: "form-component ".concat(customClass)
|
|
328
|
+
}, children)), /*#__PURE__*/_react["default"].createElement(_dialog.DialogQuestion, {
|
|
329
|
+
zIndex: "99999999",
|
|
330
|
+
customClassName: "classTeste",
|
|
331
|
+
title: securityTitle || 'Dados Alterados',
|
|
332
|
+
text: securityText || 'Vocẽ possui dados alterados, confirma o fechamento?',
|
|
333
|
+
visible: securityBeforeUnload && showQuestion,
|
|
334
|
+
onConfirmClick: onConfirmClick,
|
|
335
|
+
onUnconfirmClick: onUnconfirmClick
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
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
|
+
}
|
|
250
351
|
|
|
251
|
-
|
|
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);
|
|
352
|
+
return null;
|
|
262
353
|
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
};
|
|
354
|
+
}]);
|
|
355
|
+
|
|
356
|
+
return Form;
|
|
357
|
+
}(_react.Component);
|
|
286
358
|
|
|
359
|
+
Object.defineProperty(Form, "contextType", {
|
|
360
|
+
configurable: true,
|
|
361
|
+
enumerable: true,
|
|
362
|
+
writable: true,
|
|
363
|
+
value: _withFormSecurity.FormSecurityContext
|
|
364
|
+
});
|
|
287
365
|
Form.propTypes = {
|
|
288
366
|
dataSource: _propTypes["default"].object.isRequired,
|
|
289
367
|
children: _propTypes["default"].any.isRequired,
|
|
@@ -47,15 +47,19 @@ 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);
|
|
51
50
|
|
|
52
51
|
var _useState = (0, _react.useState)(false),
|
|
53
52
|
_useState2 = _slicedToArray(_useState, 2),
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
securityBeforeUnload = _useState2[0],
|
|
54
|
+
setSecurityBeforeUnload = _useState2[1];
|
|
55
|
+
|
|
56
|
+
var _useState3 = (0, _react.useState)(false),
|
|
57
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
58
|
+
showQuestion = _useState4[0],
|
|
59
|
+
setShowQuestion = _useState4[1];
|
|
56
60
|
|
|
57
61
|
var newHandlerClose = function newHandlerClose() {
|
|
58
|
-
if (changedData.current && securityBeforeUnload
|
|
62
|
+
if (changedData.current && securityBeforeUnload) {
|
|
59
63
|
setShowQuestion(true);
|
|
60
64
|
} else {
|
|
61
65
|
handlerClose();
|
|
@@ -74,10 +78,6 @@ var withFormSecurity = function withFormSecurity(WrappedComponent) {
|
|
|
74
78
|
changedData.current = value;
|
|
75
79
|
};
|
|
76
80
|
|
|
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/tabs/index.js
CHANGED
|
@@ -96,18 +96,77 @@ var Tabs = function Tabs(props) {
|
|
|
96
96
|
tabsContentWidth = _useState14[0],
|
|
97
97
|
setTabsContentWidth = _useState14[1];
|
|
98
98
|
|
|
99
|
-
var
|
|
99
|
+
var _useState15 = (0, _react.useState)(false),
|
|
100
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
101
|
+
hasMenuAttributes = _useState16[0],
|
|
102
|
+
setHasMenuAttributes = _useState16[1];
|
|
100
103
|
|
|
101
|
-
var
|
|
104
|
+
var _useState17 = (0, _react.useState)(0),
|
|
105
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
106
|
+
dropdownWidth = _useState18[0],
|
|
107
|
+
setDropdownWidth = _useState18[1];
|
|
102
108
|
|
|
103
|
-
var
|
|
109
|
+
var componentRef = (0, _react.useRef)(null);
|
|
110
|
+
|
|
111
|
+
var _menuRef = (0, _react.useRef)(null);
|
|
112
|
+
|
|
113
|
+
var _toolBarRef = (0, _react.useRef)(null);
|
|
114
|
+
|
|
115
|
+
var getTabListWidth = function getTabListWidth() {
|
|
116
|
+
var tabMenu = _menuRef.current.children[0];
|
|
117
|
+
|
|
118
|
+
var tabList = _toConsumableArray(tabMenu.children);
|
|
119
|
+
|
|
120
|
+
var tabsListWidth = tabList.reduce(function (total, tab) {
|
|
121
|
+
return total + tab.clientWidth;
|
|
122
|
+
}, 0);
|
|
123
|
+
return tabsListWidth;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var getMenuAttributes = function getMenuAttributes() {
|
|
127
|
+
var menuSize = _menuRef.current.clientWidth;
|
|
128
|
+
var toolbarSize = toolbar && _toolBarRef ? _toolBarRef.current.clientWidth : 0;
|
|
129
|
+
var contentWidth = (toolbar ? menuSize - toolbarSize : menuSize) - dropdownWidth;
|
|
130
|
+
setTabsContentWidth(contentWidth);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var getTabsList = function getTabsList() {
|
|
134
|
+
var tabsListWidth = getTabListWidth();
|
|
135
|
+
|
|
136
|
+
var dropdownTabs = _toConsumableArray(dropdownPanels);
|
|
137
|
+
|
|
138
|
+
var currentTabs = _toConsumableArray(panels);
|
|
139
|
+
|
|
140
|
+
if (dropdownTabs.length) {
|
|
141
|
+
var dropDownTabsIds = dropdownTabs.map(function (dd) {
|
|
142
|
+
return dd.props.id;
|
|
143
|
+
});
|
|
144
|
+
currentTabs = currentTabs.filter(function (tab) {
|
|
145
|
+
return !dropDownTabsIds.includes(tab.props.id);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
console.log(tabsListWidth, tabsContentWidth);
|
|
150
|
+
|
|
151
|
+
if (tabsListWidth > tabsContentWidth) {
|
|
152
|
+
var lastPanel = currentTabs[currentTabs.length - 1];
|
|
153
|
+
dropdownTabs.push(lastPanel);
|
|
154
|
+
currentTabs.pop();
|
|
155
|
+
} else if (tabsListWidth + 110 < tabsContentWidth && dropdownTabs.length) {
|
|
156
|
+
currentTabs.push(dropdownTabs[0]);
|
|
157
|
+
dropdownTabs.shift();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
setCurrentPanels(currentTabs);
|
|
161
|
+
setDropdownPanels(dropdownTabs);
|
|
162
|
+
};
|
|
104
163
|
|
|
105
164
|
var onMenuClick = function onMenuClick(tabId) {
|
|
106
165
|
var includedInDropdown = dropdownPanels.filter(function (item) {
|
|
107
166
|
return item.props.id === tabId;
|
|
108
167
|
});
|
|
109
168
|
|
|
110
|
-
if (includedInDropdown.length > 0) {
|
|
169
|
+
if (includedInDropdown.length > 0 && getTabListWidth() > 0) {
|
|
111
170
|
var newDropdownPanels = dropdownPanels.filter(function (item) {
|
|
112
171
|
return item.props.id !== tabId;
|
|
113
172
|
});
|
|
@@ -148,53 +207,14 @@ var Tabs = function Tabs(props) {
|
|
|
148
207
|
if (handlerCloseTab) handlerCloseTab(closedPanelId, newSelectedTabId);
|
|
149
208
|
};
|
|
150
209
|
|
|
151
|
-
var getMenuAttributes = function getMenuAttributes() {
|
|
152
|
-
var menuSize = _menuRef.current.clientWidth;
|
|
153
|
-
var dropdownWidth = dropdownPanels.length > 0 ? _menuRef.current.children[1].clientWidth : 0;
|
|
154
|
-
var toolbarSize = toolbar && _toolBarRef ? _toolBarRef.current.clientWidth : 0;
|
|
155
|
-
var contentWidth = (toolbar ? menuSize - toolbarSize : menuSize) - dropdownWidth;
|
|
156
|
-
setTabsContentWidth(contentWidth);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
var getTabsList = function getTabsList() {
|
|
160
|
-
var tabMenu = _menuRef.current.children[0];
|
|
161
|
-
|
|
162
|
-
var tabList = _toConsumableArray(tabMenu.children);
|
|
163
|
-
|
|
164
|
-
var tabsListWidth = tabList.reduce(function (total, tab) {
|
|
165
|
-
return total + tab.clientWidth;
|
|
166
|
-
}, 0);
|
|
167
|
-
|
|
168
|
-
var dropdownTabs = _toConsumableArray(dropdownPanels);
|
|
169
|
-
|
|
170
|
-
var currentTabs = _toConsumableArray(panels);
|
|
171
|
-
|
|
172
|
-
if (dropdownTabs.length) {
|
|
173
|
-
var dropDownTabsIds = dropdownTabs.map(function (dd) {
|
|
174
|
-
return dd.props.id;
|
|
175
|
-
});
|
|
176
|
-
currentTabs = currentTabs.filter(function (tab) {
|
|
177
|
-
return !dropDownTabsIds.includes(tab.props.id);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (tabsListWidth > tabsContentWidth) {
|
|
182
|
-
var lastPanel = currentTabs[currentTabs.length - 1];
|
|
183
|
-
dropdownTabs.push(lastPanel);
|
|
184
|
-
currentTabs.pop();
|
|
185
|
-
} else if (tabsListWidth + 110 < tabsContentWidth && dropdownTabs.length) {
|
|
186
|
-
currentTabs.push(dropdownTabs[0]);
|
|
187
|
-
dropdownTabs.shift();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
setCurrentPanels(currentTabs);
|
|
191
|
-
setDropdownPanels(dropdownTabs);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
210
|
var onResize = function onResize() {
|
|
195
211
|
if (componentRef.current && _menuRef.current) {
|
|
196
212
|
setContentHeight(componentRef.current.offsetHeight - _menuRef.current.offsetHeight);
|
|
197
|
-
|
|
213
|
+
|
|
214
|
+
if (!hasMenuAttributes && _menuRef.current && _menuRef.current.clientWidth > 0 && dropdownWidth) {
|
|
215
|
+
getMenuAttributes();
|
|
216
|
+
setHasMenuAttributes(true);
|
|
217
|
+
}
|
|
198
218
|
}
|
|
199
219
|
};
|
|
200
220
|
|
|
@@ -231,14 +251,18 @@ var Tabs = function Tabs(props) {
|
|
|
231
251
|
return function () {
|
|
232
252
|
return window.removeEventListener('resize', onResize);
|
|
233
253
|
};
|
|
234
|
-
}, []);
|
|
254
|
+
}, [_menuRef.current, dropdownWidth]);
|
|
235
255
|
(0, _react.useEffect)(function () {
|
|
236
256
|
if (selectedTab) setSelectedTabId(selectedTab);
|
|
237
257
|
if (children) setPanels((0, _tabHelpers.buildPanels)(children));
|
|
238
258
|
}, [selectedTab, children]);
|
|
239
259
|
(0, _react.useEffect)(function () {
|
|
240
260
|
getTabsList();
|
|
241
|
-
}, [panels.length, currentPanels.length]);
|
|
261
|
+
}, [panels.length, currentPanels.length, tabsContentWidth]);
|
|
262
|
+
(0, _react.useEffect)(function () {
|
|
263
|
+
var currentDropdownWidth = dropdownPanels.length > 0 ? _menuRef.current.children[1].clientWidth : 0;
|
|
264
|
+
setDropdownWidth(currentDropdownWidth);
|
|
265
|
+
}, [dropdownPanels.length]);
|
|
242
266
|
|
|
243
267
|
var getContextValues = function getContextValues() {
|
|
244
268
|
return {
|
package/lib/treeview/index.js
CHANGED
|
@@ -546,18 +546,14 @@ var TreeView = /*#__PURE__*/function (_Component) {
|
|
|
546
546
|
key: "getDerivedStateFromProps",
|
|
547
547
|
value: function getDerivedStateFromProps(props, state) {
|
|
548
548
|
var data = props.data,
|
|
549
|
-
selectedIds = props.selectedIds
|
|
550
|
-
enableDynamicData = props.enableDynamicData;
|
|
549
|
+
selectedIds = props.selectedIds;
|
|
551
550
|
var propSelectedIds = state.propSelectedIds;
|
|
552
551
|
|
|
553
552
|
var isSameSelectedIds = _lodash["default"].isEqual(propSelectedIds.sort(), selectedIds.sort());
|
|
554
553
|
|
|
555
|
-
if (
|
|
556
|
-
return {
|
|
557
|
-
data: data
|
|
558
|
-
};
|
|
559
|
-
} else if (!isSameSelectedIds) {
|
|
554
|
+
if (data !== state.data || !isSameSelectedIds) {
|
|
560
555
|
return {
|
|
556
|
+
data: data,
|
|
561
557
|
selectedIds: selectedIds,
|
|
562
558
|
propSelectedIds: selectedIds
|
|
563
559
|
};
|
|
@@ -593,8 +589,7 @@ TreeView.propTypes = {
|
|
|
593
589
|
nodeMenuButtonSize: _propTypes["default"].oneOf(['mini', 'small', 'medium', 'large', 'default']),
|
|
594
590
|
onNodeClick: _propTypes["default"].func,
|
|
595
591
|
onNodeOpen: _propTypes["default"].func,
|
|
596
|
-
nodeElementsValidations: _propTypes["default"].object
|
|
597
|
-
enableDynamicData: _propTypes["default"].bool
|
|
592
|
+
nodeElementsValidations: _propTypes["default"].object
|
|
598
593
|
};
|
|
599
594
|
TreeView.defaultProps = {
|
|
600
595
|
customClass: '',
|
|
@@ -615,8 +610,7 @@ TreeView.defaultProps = {
|
|
|
615
610
|
nodeMenuButtonSize: 'small',
|
|
616
611
|
onNodeClick: undefined,
|
|
617
612
|
onNodeOpen: undefined,
|
|
618
|
-
nodeElementsValidations: undefined
|
|
619
|
-
enableDynamicData: false
|
|
613
|
+
nodeElementsValidations: undefined
|
|
620
614
|
};
|
|
621
615
|
var _default = TreeView;
|
|
622
616
|
exports["default"] = _default;
|
package/package.json
CHANGED
package/.DS_Store
DELETED
|
Binary file
|