@iobroker/adapter-react-v5 4.6.11 → 4.6.13

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