@iobroker/adapter-react-v5 2.1.11 → 3.0.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.
Files changed (84) hide show
  1. package/Components/CustomModal.js +168 -0
  2. package/Components/CustomModal.js.map +1 -0
  3. package/Components/JsonConfigComponent/ChipInput.js +926 -0
  4. package/Components/JsonConfigComponent/ChipInput.js.map +1 -0
  5. package/Components/JsonConfigComponent/ConfigAlive.js +135 -0
  6. package/Components/JsonConfigComponent/ConfigAlive.js.map +1 -0
  7. package/Components/JsonConfigComponent/ConfigAutocomplete.js +204 -0
  8. package/Components/JsonConfigComponent/ConfigAutocomplete.js.map +1 -0
  9. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js +311 -0
  10. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -0
  11. package/Components/JsonConfigComponent/ConfigCRON.js +195 -0
  12. package/Components/JsonConfigComponent/ConfigCRON.js.map +1 -0
  13. package/Components/JsonConfigComponent/ConfigCertificateSelect.js +178 -0
  14. package/Components/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -0
  15. package/Components/JsonConfigComponent/ConfigCheckbox.js +112 -0
  16. package/Components/JsonConfigComponent/ConfigCheckbox.js.map +1 -0
  17. package/Components/JsonConfigComponent/ConfigChip.js +149 -0
  18. package/Components/JsonConfigComponent/ConfigChip.js.map +1 -0
  19. package/Components/JsonConfigComponent/ConfigColor.js +156 -0
  20. package/Components/JsonConfigComponent/ConfigColor.js.map +1 -0
  21. package/Components/JsonConfigComponent/ConfigCoordinates.js +165 -0
  22. package/Components/JsonConfigComponent/ConfigCoordinates.js.map +1 -0
  23. package/Components/JsonConfigComponent/ConfigCustomEasyAccess.js +180 -0
  24. package/Components/JsonConfigComponent/ConfigCustomEasyAccess.js.map +1 -0
  25. package/Components/JsonConfigComponent/ConfigDatePicker.js +117 -0
  26. package/Components/JsonConfigComponent/ConfigDatePicker.js.map +1 -0
  27. package/Components/JsonConfigComponent/ConfigGeneric.js +660 -0
  28. package/Components/JsonConfigComponent/ConfigGeneric.js.map +1 -0
  29. package/Components/JsonConfigComponent/ConfigIP.js +151 -0
  30. package/Components/JsonConfigComponent/ConfigIP.js.map +1 -0
  31. package/Components/JsonConfigComponent/ConfigImageUpload.js +215 -0
  32. package/Components/JsonConfigComponent/ConfigImageUpload.js.map +1 -0
  33. package/Components/JsonConfigComponent/ConfigInstanceSelect.js +197 -0
  34. package/Components/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -0
  35. package/Components/JsonConfigComponent/ConfigJsonEditor.js +211 -0
  36. package/Components/JsonConfigComponent/ConfigJsonEditor.js.map +1 -0
  37. package/Components/JsonConfigComponent/ConfigLanguage.js +175 -0
  38. package/Components/JsonConfigComponent/ConfigLanguage.js.map +1 -0
  39. package/Components/JsonConfigComponent/ConfigNumber.js +194 -0
  40. package/Components/JsonConfigComponent/ConfigNumber.js.map +1 -0
  41. package/Components/JsonConfigComponent/ConfigObjectId.js +201 -0
  42. package/Components/JsonConfigComponent/ConfigObjectId.js.map +1 -0
  43. package/Components/JsonConfigComponent/ConfigPanel.js +421 -0
  44. package/Components/JsonConfigComponent/ConfigPanel.js.map +1 -0
  45. package/Components/JsonConfigComponent/ConfigPassword.js +236 -0
  46. package/Components/JsonConfigComponent/ConfigPassword.js.map +1 -0
  47. package/Components/JsonConfigComponent/ConfigPattern.js +94 -0
  48. package/Components/JsonConfigComponent/ConfigPattern.js.map +1 -0
  49. package/Components/JsonConfigComponent/ConfigSelect.js +163 -0
  50. package/Components/JsonConfigComponent/ConfigSelect.js.map +1 -0
  51. package/Components/JsonConfigComponent/ConfigSelectSendTo.js +258 -0
  52. package/Components/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -0
  53. package/Components/JsonConfigComponent/ConfigSendto.js +282 -0
  54. package/Components/JsonConfigComponent/ConfigSendto.js.map +1 -0
  55. package/Components/JsonConfigComponent/ConfigSetState.js +266 -0
  56. package/Components/JsonConfigComponent/ConfigSetState.js.map +1 -0
  57. package/Components/JsonConfigComponent/ConfigStaticDivider.js +88 -0
  58. package/Components/JsonConfigComponent/ConfigStaticDivider.js.map +1 -0
  59. package/Components/JsonConfigComponent/ConfigStaticHeader.js +81 -0
  60. package/Components/JsonConfigComponent/ConfigStaticHeader.js.map +1 -0
  61. package/Components/JsonConfigComponent/ConfigStaticImage.js +88 -0
  62. package/Components/JsonConfigComponent/ConfigStaticImage.js.map +1 -0
  63. package/Components/JsonConfigComponent/ConfigStaticText.js +104 -0
  64. package/Components/JsonConfigComponent/ConfigStaticText.js.map +1 -0
  65. package/Components/JsonConfigComponent/ConfigTable.js +651 -0
  66. package/Components/JsonConfigComponent/ConfigTable.js.map +1 -0
  67. package/Components/JsonConfigComponent/ConfigTabs.js +166 -0
  68. package/Components/JsonConfigComponent/ConfigTabs.js.map +1 -0
  69. package/Components/JsonConfigComponent/ConfigText.js +170 -0
  70. package/Components/JsonConfigComponent/ConfigText.js.map +1 -0
  71. package/Components/JsonConfigComponent/ConfigTextSendTo.js +168 -0
  72. package/Components/JsonConfigComponent/ConfigTextSendTo.js.map +1 -0
  73. package/Components/JsonConfigComponent/ConfigTimePicker.js +111 -0
  74. package/Components/JsonConfigComponent/ConfigTimePicker.js.map +1 -0
  75. package/Components/JsonConfigComponent/ConfigTopic.js +140 -0
  76. package/Components/JsonConfigComponent/ConfigTopic.js.map +1 -0
  77. package/Components/JsonConfigComponent/ConfigUser.js +176 -0
  78. package/Components/JsonConfigComponent/ConfigUser.js.map +1 -0
  79. package/Components/JsonConfigComponent/index.js +511 -0
  80. package/Components/JsonConfigComponent/index.js.map +1 -0
  81. package/Components/UploadImage.js +357 -0
  82. package/Components/UploadImage.js.map +1 -0
  83. package/README.md +3 -0
  84. package/package.json +3 -1
@@ -0,0 +1,660 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
+
18
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
+
20
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
21
+
22
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
23
+
24
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
25
+
26
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
27
+
28
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
29
+
30
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
31
+
32
+ var _react = _interopRequireWildcard(require("react"));
33
+
34
+ var _propTypes = _interopRequireDefault(require("prop-types"));
35
+
36
+ var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
37
+
38
+ var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
39
+
40
+ var _Warning = _interopRequireDefault(require("@mui/icons-material/Warning"));
41
+
42
+ var _Error = _interopRequireDefault(require("@mui/icons-material/Error"));
43
+
44
+ var _i18n = _interopRequireDefault(require("@iobroker/adapter-react-v5/i18n"));
45
+
46
+ var _Utils = _interopRequireDefault(require("@iobroker/adapter-react-v5/Components/Utils"));
47
+
48
+ var _Confirm = _interopRequireDefault(require("@iobroker/adapter-react-v5/Dialogs/Confirm"));
49
+
50
+ 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
+
52
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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
+
54
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
55
+
56
+ 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; } }
57
+
58
+ var ConfigGeneric = /*#__PURE__*/function (_Component) {
59
+ (0, _inherits2["default"])(ConfigGeneric, _Component);
60
+
61
+ var _super = _createSuper(ConfigGeneric);
62
+
63
+ function ConfigGeneric(props) {
64
+ var _this;
65
+
66
+ (0, _classCallCheck2["default"])(this, ConfigGeneric);
67
+ _this = _super.call(this, props);
68
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onUpdate", function (data) {
69
+ var value = ConfigGeneric.getValue(data || _this.props.data, _this.props.attr) || '';
70
+
71
+ if (_this.state.value !== value) {
72
+ _this.setState({
73
+ value: value
74
+ });
75
+ } else {
76
+ _this.forceUpdate();
77
+ }
78
+ });
79
+ _this.state = {
80
+ confirmDialog: false,
81
+ confirmNewValue: null,
82
+ confirmAttr: null,
83
+ confirmData: null
84
+ };
85
+ _this.isError = {};
86
+
87
+ if (_this.props.schema) {
88
+ if (_this.props.custom) {
89
+ _this.defaultValue = _this.props.schema.defaultFunc ? _this.executeCustom(_this.props.schema.defaultFunc, _this.props.schema["default"], _this.props.data, _this.props.instanceObj) : _this.props.schema["default"];
90
+ } else {
91
+ _this.defaultValue = _this.props.schema.defaultFunc ? _this.execute(_this.props.schema.defaultFunc, _this.props.schema["default"], _this.props.data) : _this.props.schema["default"];
92
+ }
93
+ }
94
+
95
+ _this.lang = _i18n["default"].getLanguage();
96
+ return _this;
97
+ }
98
+
99
+ (0, _createClass2["default"])(ConfigGeneric, [{
100
+ key: "componentDidMount",
101
+ value: function componentDidMount() {
102
+ var _this2 = this;
103
+
104
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr, this.onUpdate);
105
+ var LIKE_SELECT = ['select', 'autocomplete', 'autocompleteSendTo']; // init default value
106
+
107
+ if (this.defaultValue !== undefined) {
108
+ var value = ConfigGeneric.getValue(this.props.data, this.props.attr);
109
+
110
+ if (value === undefined || LIKE_SELECT.includes(this.props.schema.type) && (value === '' || value === null)) {
111
+ setTimeout(function () {
112
+ if (_this2.props.custom) {
113
+ _this2.props.onChange(_this2.props.attr, _this2.defaultValue, function () {
114
+ return _this2.props.forceUpdate([_this2.props.attr], _this2.props.data);
115
+ }); //this.onChange(this.props.attr, this.defaultValue);
116
+
117
+ } else {
118
+ ConfigGeneric.setValue(_this2.props.data, _this2.props.attr, _this2.defaultValue);
119
+
120
+ _this2.props.onChange(_this2.props.data, undefined, function () {
121
+ return _this2.props.forceUpdate([_this2.props.attr], _this2.props.data);
122
+ });
123
+ }
124
+ }, 100);
125
+ }
126
+ }
127
+ }
128
+ }, {
129
+ key: "componentWillUnmount",
130
+ value: function componentWillUnmount() {
131
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr);
132
+ }
133
+ }, {
134
+ key: "getText",
135
+ value: function getText(text, noTranslation) {
136
+ if (!text) {
137
+ return '';
138
+ }
139
+
140
+ if (typeof text === 'string') {
141
+ text = noTranslation ? text : _i18n["default"].t(text);
142
+
143
+ if (text.includes('${')) {
144
+ return this.getPattern(text);
145
+ } else {
146
+ return text;
147
+ }
148
+ } else if (text && (0, _typeof2["default"])(text) === 'object') {
149
+ if (text.func) {
150
+ // calculate pattern
151
+ if ((0, _typeof2["default"])(text.func) === 'object') {
152
+ return this.getPattern(text.func[this.lang] || text.func.en || '');
153
+ } else {
154
+ this.getPattern(text.func);
155
+ }
156
+ } else {
157
+ return text[this.lang] || text.en || '';
158
+ }
159
+ }
160
+ }
161
+ }, {
162
+ key: "renderConfirmDialog",
163
+ value: function renderConfirmDialog() {
164
+ var _this3 = this;
165
+
166
+ if (!this.state.confirmDialog) {
167
+ return null;
168
+ }
169
+
170
+ var confirm = this.state.confirmData || this.props.schema.confirm;
171
+ var icon = null;
172
+
173
+ if (confirm.type === 'warning') {
174
+ icon = /*#__PURE__*/_react["default"].createElement(_Warning["default"], null);
175
+ } else if (confirm.type === 'error') {
176
+ icon = /*#__PURE__*/_react["default"].createElement(_Error["default"], null);
177
+ } else if (confirm.type === 'info') {
178
+ icon = /*#__PURE__*/_react["default"].createElement(_Info["default"], null);
179
+ }
180
+
181
+ return /*#__PURE__*/_react["default"].createElement(_Confirm["default"], {
182
+ title: this.getText(confirm.title) || _i18n["default"].t('Please confirm'),
183
+ text: this.getText(confirm.text),
184
+ ok: this.getText(confirm.ok) || _i18n["default"].t('Ok'),
185
+ cancel: this.getText(confirm.cancel) || _i18n["default"].t('Cancel'),
186
+ icon: icon,
187
+ onClose: function onClose(isOk) {
188
+ return _this3.setState({
189
+ confirmDialog: false
190
+ }, function () {
191
+ if (isOk) {
192
+ var data = JSON.parse(JSON.stringify(_this3.props.data));
193
+
194
+ if (_this3.state.confirmDepAttr) {
195
+ ConfigGeneric.setValue(data, _this3.state.confirmDepAttr, _this3.state.confirmDepNewValue);
196
+ }
197
+
198
+ ConfigGeneric.setValue(data, _this3.state.confirmAttr, _this3.state.confirmNewValue);
199
+
200
+ _this3.setState({
201
+ confirmDialog: false,
202
+ confirmDepAttr: null,
203
+ confirmDepNewValue: null,
204
+ confirmNewValue: null,
205
+ confirmAttr: null,
206
+ confirmOldValue: null,
207
+ confirmData: null
208
+ }, function () {
209
+ return _this3.props.onChange(data);
210
+ });
211
+ } else {
212
+ _this3.setState({
213
+ confirmDialog: false,
214
+ confirmDepAttr: null,
215
+ confirmDepNewValue: null,
216
+ confirmNewValue: null,
217
+ confirmAttr: null,
218
+ confirmOldValue: null,
219
+ confirmData: null
220
+ });
221
+ }
222
+ });
223
+ }
224
+ });
225
+ }
226
+ }, {
227
+ key: "onChange",
228
+ value: function onChange(attr, newValue) {
229
+ var _this4 = this;
230
+
231
+ var data = JSON.parse(JSON.stringify(this.props.data));
232
+ ConfigGeneric.setValue(data, attr, newValue);
233
+
234
+ if (this.props.schema.confirm && this.execute(this.props.schema.confirm.condition, false, data)) {
235
+ return this.setState({
236
+ confirmDialog: true,
237
+ confirmNewValue: newValue,
238
+ confirmAttr: attr,
239
+ confirmData: null
240
+ });
241
+ } else {
242
+ // find any inputs with confirmation
243
+ if (this.props.schema.confirmDependsOn) {
244
+ for (var z = 0; z < this.props.schema.confirmDependsOn.length; z++) {
245
+ var dep = this.props.schema.confirmDependsOn[z];
246
+
247
+ if (dep.confirm) {
248
+ var val = ConfigGeneric.getValue(data, dep.attr);
249
+
250
+ if (this.execute(dep.confirm.condition, false, data)) {
251
+ return this.setState({
252
+ confirmDialog: true,
253
+ confirmNewValue: newValue,
254
+ confirmAttr: attr,
255
+ confirmDepNewValue: val,
256
+ confirmDepAttr: dep.attr,
257
+ confirmData: dep.confirm
258
+ });
259
+ }
260
+ }
261
+ }
262
+ }
263
+
264
+ var changed = [];
265
+
266
+ if (this.props.schema.onChangeDependsOn) {
267
+ for (var _z = 0; _z < this.props.schema.onChangeDependsOn.length; _z++) {
268
+ var _dep = this.props.schema.onChangeDependsOn[_z];
269
+
270
+ if (_dep.onChange) {
271
+ var _val = ConfigGeneric.getValue(data, _dep.attr);
272
+
273
+ var _newValue = this.props.custom ? this.executeCustom(_dep.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj) : this.execute(_dep.onChange.calculateFunc, _val, data);
274
+
275
+ if (_newValue !== _val) {
276
+ ConfigGeneric.setValue(data, _dep.attr, _newValue);
277
+ changed.push(_dep.attr);
278
+ }
279
+ }
280
+ }
281
+ }
282
+
283
+ if (this.props.schema.hiddenDependsOn) {
284
+ for (var _z2 = 0; _z2 < this.props.schema.hiddenDependsOn.length; _z2++) {
285
+ var _dep2 = this.props.schema.hiddenDependsOn[_z2];
286
+ _dep2.hidden && changed.push(_dep2.attr);
287
+ }
288
+ }
289
+
290
+ if (this.props.schema.labelDependsOn) {
291
+ for (var _z3 = 0; _z3 < this.props.schema.labelDependsOn.length; _z3++) {
292
+ var _dep3 = this.props.schema.labelDependsOn[_z3];
293
+ _dep3.hidden && changed.push(_dep3.attr);
294
+ }
295
+ }
296
+
297
+ if (this.props.schema.helpDependsOn) {
298
+ for (var _z4 = 0; _z4 < this.props.schema.helpDependsOn.length; _z4++) {
299
+ var _dep4 = this.props.schema.helpDependsOn[_z4];
300
+ _dep4.hidden && changed.push(_dep4.attr);
301
+ }
302
+ }
303
+
304
+ if (this.props.schema.onChange && !this.props.schema.onChange.ignoreOwnChanges) {
305
+ var _val2 = ConfigGeneric.getValue(data, this.props.attr);
306
+
307
+ var _newValue2 = this.props.custom ? this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj) : this.execute(this.props.schema.onChange.calculateFunc, _val2, data);
308
+
309
+ if (_newValue2 !== _val2) {
310
+ ConfigGeneric.setValue(data, this.props.attr, _newValue2);
311
+ }
312
+ }
313
+
314
+ if (this.props.custom) {
315
+ this.props.onChange(attr, newValue);
316
+ changed && changed.length && changed.forEach(function (_attr, i) {
317
+ return setTimeout(function () {
318
+ return _this4.props.onChange(_attr, data[_attr]);
319
+ }, i * 50);
320
+ });
321
+ } else {
322
+ this.props.onChange(data, undefined, function () {
323
+ return changed.length && _this4.props.forceUpdate(changed, data);
324
+ });
325
+ }
326
+ }
327
+ }
328
+ }, {
329
+ key: "execute",
330
+ value: function execute(func, defaultValue, data) {
331
+ if (func && (0, _typeof2["default"])(func) === 'object') {
332
+ func = func.func;
333
+ }
334
+
335
+ if (!func) {
336
+ return defaultValue;
337
+ } else {
338
+ try {
339
+ // eslint-disable-next-line no-new-func
340
+ var f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', func.includes('return') ? func : 'return ' + func);
341
+ var result = f(data || this.props.data, this.props.originalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.instance); // console.log(result);
342
+
343
+ return result;
344
+ } catch (e) {
345
+ console.error("Cannot execute ".concat(func, ": ").concat(e));
346
+ return defaultValue;
347
+ }
348
+ }
349
+ }
350
+ }, {
351
+ key: "executeCustom",
352
+ value: function executeCustom(func, data, customObj, instanceObj) {
353
+ if (func && (0, _typeof2["default"])(func) === 'object') {
354
+ func = func.func;
355
+ }
356
+
357
+ if (!func) {
358
+ return null;
359
+ } else {
360
+ try {
361
+ // eslint-disable-next-line no-new-func
362
+ var f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', func.includes('return') ? func : 'return ' + func);
363
+ var result = f(data || this.props.data, this.props.originalData, this.props.systemConfig, instanceObj, customObj, this.props.socket);
364
+ console.log(result);
365
+ return result;
366
+ } catch (e) {
367
+ console.error("Cannot execute ".concat(func, ": ").concat(e));
368
+ return null;
369
+ }
370
+ }
371
+ }
372
+ }, {
373
+ key: "calculate",
374
+ value: function calculate(schema) {
375
+ var error;
376
+ var disabled;
377
+ var hidden;
378
+ var defaultValue;
379
+
380
+ if (this.props.custom) {
381
+ error = schema.validator ? !this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.instanceObj) : false;
382
+ disabled = schema.disabled ? this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.instanceObj) : false;
383
+ hidden = schema.hidden ? this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.instanceObj) : false;
384
+ defaultValue = schema.defaultFunc ? this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.instanceObj) : schema["default"];
385
+ } else {
386
+ error = schema.validator ? !this.execute(schema.validator, false) : false;
387
+ disabled = schema.disabled ? this.execute(schema.disabled, false) : false;
388
+ hidden = schema.hidden ? this.execute(schema.hidden, false) : false;
389
+ defaultValue = schema.defaultFunc ? this.execute(schema.defaultFunc, schema["default"], this.props.data) : schema["default"];
390
+ }
391
+
392
+ return {
393
+ error: error,
394
+ disabled: disabled,
395
+ hidden: hidden,
396
+ defaultValue: defaultValue
397
+ };
398
+ }
399
+ }, {
400
+ key: "onError",
401
+ value: function onError(attr, error) {
402
+ if (!error) {
403
+ delete this.isError[attr];
404
+ } else {
405
+ this.isError[attr] = error;
406
+ }
407
+
408
+ this.props.onError && this.props.onError(attr, error);
409
+ }
410
+ }, {
411
+ key: "renderItem",
412
+ value: function renderItem(error, disabled, defaultValue) {
413
+ return this.getText(this.props.schema.label) || this.getText(this.props.schema.text);
414
+ }
415
+ }, {
416
+ key: "renderHelp",
417
+ value: function renderHelp(text, link, noTranslation) {
418
+ if (!link) {
419
+ text = this.getText(text, noTranslation) || '';
420
+
421
+ if (text && text.includes('<a ')) {
422
+ return _Utils["default"].renderTextWithA(text);
423
+ } else {
424
+ return text;
425
+ }
426
+ } else {
427
+ return /*#__PURE__*/_react["default"].createElement("a", {
428
+ href: link,
429
+ target: "_blank",
430
+ rel: "noreferrer",
431
+ style: {
432
+ color: this.props.themeType === 'dark' ? '#eee' : '#111'
433
+ }
434
+ }, this.getText(text, noTranslation));
435
+ }
436
+ }
437
+ }, {
438
+ key: "getPattern",
439
+ value: function getPattern(pattern) {
440
+ if (!pattern) {
441
+ return '';
442
+ } else {
443
+ if ((0, _typeof2["default"])(pattern) === 'object') {
444
+ pattern = pattern.func;
445
+ }
446
+
447
+ try {
448
+ if (this.props.custom) {
449
+ // eslint-disable-next-line no-new-func
450
+ var f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'return `' + pattern.replace(/`/g, '\\`') + '`');
451
+ var result = f(this.props.data, this.props.originalData, this.props.systemConfig, this.props.instanceObj, this.props.customObj, this.props.socket);
452
+ return result;
453
+ } else {
454
+ // eslint-disable-next-line no-new-func
455
+ var _f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', 'return `' + pattern.replace(/`/g, '\\`') + '`');
456
+
457
+ return _f(this.props.data, this.props.originalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket);
458
+ }
459
+ } catch (e) {
460
+ console.error("Cannot execute ".concat(pattern, ": ").concat(e));
461
+ return pattern;
462
+ }
463
+ }
464
+ }
465
+ }, {
466
+ key: "render",
467
+ value: function render() {
468
+ var _this5 = this;
469
+
470
+ var schema = this.props.schema;
471
+
472
+ if (!schema) {
473
+ return null;
474
+ }
475
+
476
+ var _this$calculate = this.calculate(schema),
477
+ error = _this$calculate.error,
478
+ disabled = _this$calculate.disabled,
479
+ hidden = _this$calculate.hidden,
480
+ defaultValue = _this$calculate.defaultValue;
481
+
482
+ if (hidden) {
483
+ // Remove all errors if element is hidden
484
+ if (Object.keys(this.isError).length) {
485
+ setTimeout(function (isError) {
486
+ return Object.keys(isError).forEach(function (attr) {
487
+ return _this5.props.onError(attr);
488
+ });
489
+ }, 100, JSON.parse(JSON.stringify(this.isError)));
490
+ this.isError = {};
491
+ }
492
+
493
+ if (schema.hideOnlyControl) {
494
+ var item = /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
495
+ item: true,
496
+ xs: schema.xs || undefined,
497
+ lg: schema.lg || undefined,
498
+ md: schema.md || undefined,
499
+ sm: schema.sm || undefined,
500
+ style: Object.assign({}, {
501
+ marginBottom: 0,
502
+
503
+ /*marginRight: 8, */
504
+ textAlign: 'left'
505
+ }, schema.style, this.props.themeType === 'dark' ? schema.darkStyle : {})
506
+ });
507
+
508
+ if (schema.newLine) {
509
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
510
+ style: {
511
+ flexBasis: '100%',
512
+ height: 0
513
+ }
514
+ }), item);
515
+ } else {
516
+ return item;
517
+ }
518
+ } else {
519
+ return null;
520
+ }
521
+ } else {
522
+ // Add error
523
+ if (schema.validatorNoSaveOnError) {
524
+ if (error && !Object.keys(this.isError).length) {
525
+ this.isError = (0, _defineProperty2["default"])({}, this.props.attr, schema.validatorErrorText ? _i18n["default"].t(schema.validatorErrorText) : true);
526
+ setTimeout(function (isError) {
527
+ return Object.keys(isError).forEach(function (attr) {
528
+ return _this5.props.onError(attr, isError[attr]);
529
+ });
530
+ }, 100, JSON.parse(JSON.stringify(this.isError)));
531
+ } else if (!error && Object.keys(this.isError).length) {
532
+ setTimeout(function (isError) {
533
+ return Object.keys(isError).forEach(function (attr) {
534
+ return _this5.props.onError(attr);
535
+ });
536
+ }, 100, JSON.parse(JSON.stringify(this.isError)));
537
+ this.isError = {};
538
+ }
539
+ }
540
+
541
+ var _item = /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
542
+ item: true,
543
+ title: this.getText(schema.tooltip),
544
+ xs: schema.xs || undefined,
545
+ lg: schema.lg || undefined,
546
+ md: schema.md || undefined,
547
+ sm: schema.sm || undefined,
548
+ style: Object.assign({}, {
549
+ marginBottom: 0,
550
+ //marginRight: 8,
551
+ textAlign: 'left',
552
+ width: schema.type === 'divider' || schema.type === 'header' ? schema.width || '100%' : undefined
553
+ }, schema.style, this.props.themeType === 'dark' ? schema.darkStyle : {})
554
+ }, this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue));
555
+
556
+ if (schema.newLine) {
557
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
558
+ style: {
559
+ flexBasis: '100%',
560
+ height: 0
561
+ }
562
+ }), this.renderConfirmDialog(), _item);
563
+ } else {
564
+ if (this.state.confirmDialog) {
565
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderConfirmDialog(), _item);
566
+ } else {
567
+ return _item;
568
+ }
569
+ }
570
+ }
571
+ }
572
+ }], [{
573
+ key: "getValue",
574
+ value: function getValue(data, attr) {
575
+ if (typeof attr === 'string') {
576
+ return ConfigGeneric.getValue(data, attr.split('.'));
577
+ } else {
578
+ if (attr.length === 1) {
579
+ return data[attr[0]];
580
+ } else {
581
+ var part = attr.shift();
582
+
583
+ if ((0, _typeof2["default"])(data[part]) === 'object') {
584
+ return ConfigGeneric.getValue(data[part], attr);
585
+ } else {
586
+ return null;
587
+ }
588
+ }
589
+ }
590
+ }
591
+ }, {
592
+ key: "setValue",
593
+ value: function setValue(data, attr, value) {
594
+ if (typeof attr === 'string') {
595
+ return ConfigGeneric.setValue(data, attr.split('.'), value);
596
+ } else {
597
+ if (attr.length === 1) {
598
+ if (value === null) {
599
+ delete data[attr[0]];
600
+ } else {
601
+ data[attr[0]] = value;
602
+ }
603
+ } else {
604
+ var part = attr.shift();
605
+
606
+ if (!data[part] || (0, _typeof2["default"])(data[part]) === 'object') {
607
+ data[part] = data[part] || {};
608
+ }
609
+
610
+ return ConfigGeneric.setValue(data[part], attr, value);
611
+ }
612
+ }
613
+ }
614
+ }]);
615
+ return ConfigGeneric;
616
+ }(_react.Component);
617
+
618
+ (0, _defineProperty2["default"])(ConfigGeneric, "DIFFERENT_VALUE", '__different__');
619
+ (0, _defineProperty2["default"])(ConfigGeneric, "DIFFERENT_LABEL", _i18n["default"].t('__different__'));
620
+ (0, _defineProperty2["default"])(ConfigGeneric, "NONE_VALUE", '');
621
+ (0, _defineProperty2["default"])(ConfigGeneric, "NONE_LABEL", _i18n["default"].t('none'));
622
+ (0, _defineProperty2["default"])(ConfigGeneric, "AsyncFunction", Object.getPrototypeOf( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
623
+ return _regenerator["default"].wrap(function _callee$(_context) {
624
+ while (1) {
625
+ switch (_context.prev = _context.next) {
626
+ case 0:
627
+ case "end":
628
+ return _context.stop();
629
+ }
630
+ }
631
+ }, _callee);
632
+ }))).constructor);
633
+ ConfigGeneric.propTypes = {
634
+ socket: _propTypes["default"].object.isRequired,
635
+ data: _propTypes["default"].object,
636
+ originalData: _propTypes["default"].object,
637
+ schema: _propTypes["default"].object,
638
+ attr: _propTypes["default"].string,
639
+ value: _propTypes["default"].any,
640
+ themeName: _propTypes["default"].string,
641
+ style: _propTypes["default"].object,
642
+ onError: _propTypes["default"].func,
643
+ onChange: _propTypes["default"].func,
644
+ customs: _propTypes["default"].object,
645
+ forceUpdate: _propTypes["default"].func.isRequired,
646
+ disabled: _propTypes["default"].bool,
647
+ systemConfig: _propTypes["default"].object,
648
+ alive: _propTypes["default"].bool,
649
+ common: _propTypes["default"].object,
650
+ adapterName: _propTypes["default"].string,
651
+ instance: _propTypes["default"].number,
652
+ dateFormat: _propTypes["default"].string,
653
+ isFloatComma: _propTypes["default"].bool,
654
+ customObj: _propTypes["default"].object,
655
+ instanceObj: _propTypes["default"].object,
656
+ custom: _propTypes["default"].bool
657
+ };
658
+ var _default = ConfigGeneric;
659
+ exports["default"] = _default;
660
+ //# sourceMappingURL=ConfigGeneric.js.map