@iobroker/adapter-react-v5 4.6.13 → 4.7.1

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.
@@ -0,0 +1,637 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.isObject = void 0;
30
+ const react_1 = __importStar(require("react"));
31
+ const material_1 = require("@mui/material");
32
+ const icons_material_1 = require("@mui/icons-material");
33
+ const i18n_1 = __importDefault(require("./wrapper/i18n"));
34
+ const Utils_1 = __importDefault(require("./wrapper/Components/Utils"));
35
+ const Confirm_1 = __importDefault(require("./wrapper/Dialogs/Confirm"));
36
+ const Icon_1 = __importDefault(require("./wrapper/Components/Icon"));
37
+ // because this class is used in adapter-react-v5, do not include here any foreign files like from '../../helpers/utils.ts'
38
+ function isObject(it) {
39
+ // This is necessary because:
40
+ // typeof null === 'object'
41
+ // typeof [] === 'object'
42
+ // [] instanceof Object === true
43
+ return Object.prototype.toString.call(it) === '[object Object]'; // this code is 25% faster than below one
44
+ // return it && typeof it === 'object' && !(it instanceof Array);
45
+ }
46
+ exports.isObject = isObject;
47
+ class ConfigGeneric extends react_1.Component {
48
+ constructor(props) {
49
+ super(props);
50
+ this.onUpdate = (data) => {
51
+ const value = ConfigGeneric.getValue(data || this.props.data, this.props.attr) || '';
52
+ if (this.state.value !== value) {
53
+ this.setState({ value });
54
+ }
55
+ else {
56
+ this.forceUpdate();
57
+ }
58
+ };
59
+ // @ts-expect-error of course, as we just
60
+ this.state = {
61
+ confirmDialog: false,
62
+ confirmNewValue: null,
63
+ confirmAttr: null,
64
+ confirmData: null,
65
+ };
66
+ this.isError = {};
67
+ if (props.schema) {
68
+ if (props.custom) {
69
+ this.defaultValue = props.schema.defaultFunc
70
+ ? this.executeCustom(props.schema.defaultFunc, props.schema.default, props.data, props.instanceObj, props.arrayIndex, props.globalData)
71
+ : props.schema.default;
72
+ }
73
+ else {
74
+ this.defaultValue = props.schema.defaultFunc
75
+ ? this.execute(props.schema.defaultFunc, props.schema.default, props.data, props.arrayIndex, props.globalData)
76
+ : props.schema.default;
77
+ }
78
+ }
79
+ this.lang = i18n_1.default.getLanguage();
80
+ }
81
+ componentDidMount() {
82
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr, this.onUpdate);
83
+ const LIKE_SELECT = ['select', 'autocomplete', 'autocompleteSendTo'];
84
+ // init default value
85
+ if (this.defaultValue !== undefined) {
86
+ const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
87
+ if (value === undefined ||
88
+ (LIKE_SELECT.includes(this.props.schema.type) && (value === '' || value === null))) {
89
+ setTimeout(() => {
90
+ if (this.props.custom) {
91
+ this.props.onChange(this.props.attr, this.defaultValue, () => setTimeout(() => this.props.forceUpdate([this.props.attr], this.props.data), 100));
92
+ }
93
+ else {
94
+ ConfigGeneric.setValue(this.props.data, this.props.attr, this.defaultValue);
95
+ this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
96
+ }
97
+ }, 100);
98
+ }
99
+ }
100
+ else if (this.props.schema.defaultSendTo) {
101
+ this.sendTo();
102
+ }
103
+ }
104
+ sendTo() {
105
+ if (this.props.alive) {
106
+ this.defaultSendToDone = true;
107
+ let data = this.props.schema.data;
108
+ if (data === undefined && this.props.schema.jsonData) {
109
+ data = this.getPattern(this.props.schema.jsonData);
110
+ try {
111
+ data = JSON.parse(data);
112
+ }
113
+ catch (e) {
114
+ console.error(`Cannot parse json data: ${data}`);
115
+ }
116
+ }
117
+ else {
118
+ data = {
119
+ attr: this.props.attr,
120
+ value: ConfigGeneric.getValue(this.props.data, this.props.attr),
121
+ };
122
+ }
123
+ if (data === undefined) {
124
+ data = null;
125
+ }
126
+ this.props.socket
127
+ .sendTo(`${this.props.adapterName}.${this.props.instance}`, this.props.schema.defaultSendTo, data)
128
+ .then((value) => {
129
+ if (value !== null && value !== undefined) {
130
+ if (this.props.custom) {
131
+ this.props.onChange(this.props.attr, value, () => this.props.forceUpdate([this.props.attr], this.props.data));
132
+ // this.onChange(this.props.attr, this.defaultValue);
133
+ }
134
+ else {
135
+ ConfigGeneric.setValue(this.props.data, this.props.attr, value);
136
+ this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
137
+ }
138
+ }
139
+ });
140
+ }
141
+ else {
142
+ this.defaultSendToDone = false;
143
+ // show error, that instance does not started
144
+ this.onError(this.props.attr, i18n_1.default.t('ra_Instance %s is not alive', this.props.instance.toString()));
145
+ }
146
+ }
147
+ componentWillUnmount() {
148
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr);
149
+ if (this.sendToTimeout) {
150
+ clearTimeout(this.sendToTimeout);
151
+ this.sendToTimeout = null;
152
+ }
153
+ }
154
+ /**
155
+ * Extract attribute out of data
156
+ *
157
+ * @param data
158
+ * @param attr
159
+ */
160
+ static getValue(data, attr) {
161
+ if (typeof attr === 'string') {
162
+ return ConfigGeneric.getValue(data, attr.split('.'));
163
+ }
164
+ if (attr.length === 1) {
165
+ return data[attr[0]];
166
+ }
167
+ const part = attr.shift();
168
+ if (typeof part === 'string' && typeof data[part] === 'object') {
169
+ return ConfigGeneric.getValue(data[part], attr);
170
+ }
171
+ return null;
172
+ }
173
+ static setValue(data, attr, value) {
174
+ if (typeof attr === 'string') {
175
+ ConfigGeneric.setValue(data, attr.split('.'), value);
176
+ return;
177
+ }
178
+ if (attr.length === 1) {
179
+ if (value === null) {
180
+ delete data[attr[0]];
181
+ }
182
+ else {
183
+ data[attr[0]] = value;
184
+ }
185
+ }
186
+ else {
187
+ const part = attr.shift();
188
+ if (typeof part !== 'string') {
189
+ return;
190
+ }
191
+ if (!data[part] || typeof data[part] === 'object') {
192
+ data[part] = data[part] || {};
193
+ }
194
+ ConfigGeneric.setValue(data[part], attr, value);
195
+ }
196
+ }
197
+ getText(text, noTranslation) {
198
+ if (!text) {
199
+ return '';
200
+ }
201
+ if (typeof text === 'string') {
202
+ const strText = noTranslation ? text : i18n_1.default.t(text);
203
+ if (strText.includes('${')) {
204
+ return this.getPattern(strText);
205
+ }
206
+ return strText;
207
+ }
208
+ if (isObject(text)) {
209
+ if (text.func) {
210
+ // calculate pattern
211
+ if (typeof text.func === 'object') {
212
+ return this.getPattern(text.func[this.lang] || text.func.en || '');
213
+ }
214
+ return this.getPattern(text.func);
215
+ }
216
+ return text[this.lang] || text.en || '';
217
+ }
218
+ return text.toString();
219
+ }
220
+ renderConfirmDialog() {
221
+ if (!this.state.confirmDialog) {
222
+ return null;
223
+ }
224
+ const confirm = this.state.confirmData || this.props.schema.confirm;
225
+ let icon = null;
226
+ if (confirm.type === 'warning') {
227
+ icon = react_1.default.createElement(icons_material_1.Warning, null);
228
+ }
229
+ else if (confirm.type === 'error') {
230
+ icon = react_1.default.createElement(icons_material_1.Error, null);
231
+ }
232
+ else if (confirm.type === 'info') {
233
+ icon = react_1.default.createElement(icons_material_1.Info, null);
234
+ }
235
+ return (react_1.default.createElement(Confirm_1.default, { title: this.getText(confirm.title) || i18n_1.default.t('ra_Please confirm'), text: this.getText(confirm.text), ok: this.getText(confirm.ok) || i18n_1.default.t('ra_Ok'), cancel: this.getText(confirm.cancel) || i18n_1.default.t('ra_Cancel'), icon: icon, onClose: isOk => this.setState({ confirmDialog: false }, () => {
236
+ if (isOk) {
237
+ const data = JSON.parse(JSON.stringify(this.props.data));
238
+ if (this.state.confirmDepAttr) {
239
+ ConfigGeneric.setValue(data, this.state.confirmDepAttr, this.state.confirmDepNewValue);
240
+ }
241
+ ConfigGeneric.setValue(data, this.state.confirmAttr, this.state.confirmNewValue);
242
+ this.setState({
243
+ confirmDialog: false,
244
+ confirmDepAttr: null,
245
+ confirmDepNewValue: null,
246
+ confirmNewValue: null,
247
+ confirmAttr: null,
248
+ confirmData: null,
249
+ }, () => this.props.onChange(data));
250
+ }
251
+ else {
252
+ this.setState({
253
+ confirmDialog: false,
254
+ confirmDepAttr: null,
255
+ confirmDepNewValue: null,
256
+ confirmNewValue: null,
257
+ confirmAttr: null,
258
+ confirmData: null,
259
+ });
260
+ }
261
+ }) }));
262
+ }
263
+ // eslint-disable-next-line react/no-unused-class-component-methods
264
+ getIcon(iconSettings) {
265
+ iconSettings = iconSettings || this.props.schema.icon;
266
+ let icon = null;
267
+ if (iconSettings === 'auth') {
268
+ icon = react_1.default.createElement(icons_material_1.Key, null);
269
+ }
270
+ else if (iconSettings === 'send') {
271
+ icon = react_1.default.createElement(icons_material_1.Send, null);
272
+ }
273
+ else if (iconSettings === 'web') {
274
+ icon = react_1.default.createElement(icons_material_1.Public, null);
275
+ }
276
+ else if (iconSettings === 'warning') {
277
+ icon = react_1.default.createElement(icons_material_1.Warning, null);
278
+ }
279
+ else if (iconSettings === 'error') {
280
+ icon = react_1.default.createElement(icons_material_1.Error, null);
281
+ }
282
+ else if (iconSettings === 'info') {
283
+ icon = react_1.default.createElement(icons_material_1.Info, null);
284
+ }
285
+ else if (iconSettings === 'search') {
286
+ icon = react_1.default.createElement(icons_material_1.Search, null);
287
+ }
288
+ else if (iconSettings === 'book') {
289
+ icon = react_1.default.createElement(icons_material_1.MenuBook, null);
290
+ }
291
+ else if (iconSettings === 'help') {
292
+ icon = react_1.default.createElement(icons_material_1.Help, null);
293
+ }
294
+ else if (iconSettings === 'upload') {
295
+ icon = react_1.default.createElement(icons_material_1.UploadFile, null);
296
+ }
297
+ else if (iconSettings) {
298
+ if (iconSettings.endsWith('.png') || iconSettings.endsWith('.svg') || iconSettings.endsWith('.jpg')) {
299
+ // this path is relative to ./adapter/NAME
300
+ if (!iconSettings.startsWith('http://') && !iconSettings.startsWith('https://')) {
301
+ iconSettings = `./adapter/${this.props.adapterName}/${iconSettings}`;
302
+ }
303
+ }
304
+ icon = react_1.default.createElement(Icon_1.default, { src: iconSettings, style: { width: 22, height: 22 } });
305
+ }
306
+ return icon;
307
+ }
308
+ /**
309
+ * Trigger onChange, to activate save button on change
310
+ *
311
+ * @param attr the changed attribute
312
+ * @param newValue new value of the attribute
313
+ * @param cb optional callback function, else returns a Promise
314
+ */
315
+ // eslint-disable-next-line react/no-unused-class-component-methods
316
+ onChange(attr, newValue, cb) {
317
+ const data = JSON.parse(JSON.stringify(this.props.data));
318
+ ConfigGeneric.setValue(data, attr, newValue);
319
+ if (this.props.schema.confirm &&
320
+ this.execute(this.props.schema.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
321
+ return new Promise(resolve => {
322
+ this.setState({
323
+ confirmDialog: true,
324
+ confirmNewValue: newValue,
325
+ confirmAttr: attr,
326
+ confirmData: null,
327
+ }, () => {
328
+ if (typeof cb === 'function') {
329
+ cb();
330
+ }
331
+ else {
332
+ resolve();
333
+ }
334
+ });
335
+ });
336
+ }
337
+ // find any inputs with confirmation
338
+ if (this.props.schema.confirmDependsOn) {
339
+ for (let z = 0; z < this.props.schema.confirmDependsOn.length; z++) {
340
+ const dep = this.props.schema.confirmDependsOn[z];
341
+ if (dep.confirm) {
342
+ const val = ConfigGeneric.getValue(data, dep.attr);
343
+ if (this.execute(dep.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
344
+ return new Promise(resolve => {
345
+ this.setState({
346
+ confirmDialog: true,
347
+ confirmNewValue: newValue,
348
+ confirmAttr: attr,
349
+ confirmDepNewValue: val,
350
+ confirmDepAttr: dep.attr,
351
+ confirmData: dep.confirm,
352
+ }, () => {
353
+ if (typeof cb === 'function') {
354
+ cb();
355
+ }
356
+ else {
357
+ resolve();
358
+ }
359
+ });
360
+ });
361
+ }
362
+ }
363
+ }
364
+ }
365
+ const changed = [];
366
+ if (this.props.schema.onChangeDependsOn) {
367
+ for (let z = 0; z < this.props.schema.onChangeDependsOn.length; z++) {
368
+ const dep = this.props.schema.onChangeDependsOn[z];
369
+ if (dep.onChange) {
370
+ const val = ConfigGeneric.getValue(data, dep.attr);
371
+ let _newValue;
372
+ if (this.props.custom) {
373
+ _newValue = this.executeCustom(dep.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData);
374
+ }
375
+ else {
376
+ _newValue = this.execute(dep.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
377
+ }
378
+ if (_newValue !== val) {
379
+ ConfigGeneric.setValue(data, dep.attr, _newValue);
380
+ changed.push(dep.attr);
381
+ }
382
+ }
383
+ }
384
+ }
385
+ if (this.props.schema.hiddenDependsOn) {
386
+ for (let z = 0; z < this.props.schema.hiddenDependsOn.length; z++) {
387
+ const dep = this.props.schema.hiddenDependsOn[z];
388
+ dep.hidden && changed.push(dep.attr);
389
+ }
390
+ }
391
+ if (this.props.schema.labelDependsOn) {
392
+ for (let z = 0; z < this.props.schema.labelDependsOn.length; z++) {
393
+ const dep = this.props.schema.labelDependsOn[z];
394
+ dep.hidden && changed.push(dep.attr);
395
+ }
396
+ }
397
+ if (this.props.schema.helpDependsOn) {
398
+ for (let z = 0; z < this.props.schema.helpDependsOn.length; z++) {
399
+ const dep = this.props.schema.helpDependsOn[z];
400
+ dep.hidden && changed.push(dep.attr);
401
+ }
402
+ }
403
+ if (this.props.schema.onChange && !this.props.schema.onChange.ignoreOwnChanges) {
404
+ const val = ConfigGeneric.getValue(data, this.props.attr);
405
+ const newValue_ = this.props.custom
406
+ ? this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
407
+ : this.execute(this.props.schema.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
408
+ if (newValue_ !== val) {
409
+ ConfigGeneric.setValue(data, this.props.attr, newValue_);
410
+ }
411
+ }
412
+ if (this.props.custom) {
413
+ this.props.onChange(attr, newValue, () => cb && cb());
414
+ changed &&
415
+ changed.length &&
416
+ changed.forEach((_attr, i) => setTimeout(() => this.props.onChange(_attr, ConfigGeneric.getValue(data, _attr)), i * 50));
417
+ }
418
+ else {
419
+ this.props.onChange(data, undefined, () => {
420
+ changed.length && this.props.forceUpdate(changed, data);
421
+ cb && cb();
422
+ });
423
+ }
424
+ return Promise.resolve();
425
+ }
426
+ execute(func, defaultValue, data, arrayIndex, globalData) {
427
+ let fun;
428
+ if (isObject(func)) {
429
+ fun = func.func;
430
+ }
431
+ else {
432
+ fun = func;
433
+ }
434
+ if (!fun) {
435
+ return defaultValue;
436
+ }
437
+ try {
438
+ // eslint-disable-next-line no-new-func
439
+ const f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
440
+ 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);
441
+ }
442
+ catch (e) {
443
+ console.error(`Cannot execute ${func}: ${e}`);
444
+ return defaultValue;
445
+ }
446
+ }
447
+ executeCustom(func, data, customObj, instanceObj, arrayIndex, globalData) {
448
+ let fun;
449
+ if (isObject(func)) {
450
+ fun = func.func;
451
+ }
452
+ else {
453
+ fun = func;
454
+ }
455
+ if (!fun) {
456
+ return null;
457
+ }
458
+ try {
459
+ // eslint-disable-next-line no-new-func
460
+ const f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
461
+ return f(data || this.props.data, this.props.originalData, this.props.systemConfig, instanceObj, customObj, this.props.socket, arrayIndex, globalData, this.props.changed);
462
+ }
463
+ catch (e) {
464
+ console.error(`Cannot execute ${fun}: ${e}`);
465
+ return null;
466
+ }
467
+ }
468
+ calculate(schema) {
469
+ let error;
470
+ let disabled;
471
+ let hidden;
472
+ let defaultValue;
473
+ if (this.props.custom) {
474
+ error = schema.validator
475
+ ? !this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
476
+ : false;
477
+ disabled = schema.disabled
478
+ ? this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
479
+ : false;
480
+ hidden = schema.hidden
481
+ ? this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
482
+ : false;
483
+ defaultValue = schema.defaultFunc
484
+ ? this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
485
+ : schema.default;
486
+ }
487
+ else {
488
+ error = schema.validator
489
+ ? !this.execute(schema.validator, false, this.props.data, this.props.arrayIndex, this.props.globalData)
490
+ : false;
491
+ disabled = schema.disabled
492
+ ? this.execute(schema.disabled, false, this.props.data, this.props.arrayIndex, this.props.globalData)
493
+ : false;
494
+ hidden = schema.hidden
495
+ ? this.execute(schema.hidden, false, this.props.data, this.props.arrayIndex, this.props.globalData)
496
+ : false;
497
+ defaultValue = schema.defaultFunc
498
+ ? this.execute(schema.defaultFunc, schema.default, this.props.data, this.props.arrayIndex, this.props.globalData)
499
+ : schema.default;
500
+ }
501
+ return {
502
+ error, disabled, hidden, defaultValue,
503
+ };
504
+ }
505
+ onError(attr, error) {
506
+ if (!error) {
507
+ delete this.isError[attr];
508
+ }
509
+ else {
510
+ this.isError[attr] = error;
511
+ }
512
+ this.props.onError && this.props.onError(attr, error);
513
+ }
514
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
515
+ renderItem(_error, _disabled, _defaultValue) {
516
+ return this.getText(this.props.schema.label) || this.getText(this.props.schema.text);
517
+ }
518
+ // eslint-disable-next-line react/no-unused-class-component-methods
519
+ renderHelp(text, link, noTranslation) {
520
+ if (!link) {
521
+ text = this.getText(text, noTranslation) || '';
522
+ if (text &&
523
+ (text.includes('<a ') || text.includes('<br') || text.includes('<b>') || text.includes('<i>'))) {
524
+ return Utils_1.default.renderTextWithA(text);
525
+ }
526
+ return text;
527
+ }
528
+ return react_1.default.createElement("a", { href: link, target: "_blank", rel: "noreferrer", style: {
529
+ color: this.props.themeType === 'dark' ? '#a147ff' : '#5b238f',
530
+ textDecoration: 'underline',
531
+ } }, this.getText(text, noTranslation));
532
+ }
533
+ getPattern(pattern, data) {
534
+ data = data || this.props.data;
535
+ if (!pattern) {
536
+ return '';
537
+ }
538
+ if (typeof pattern === 'object') {
539
+ if (pattern.func) {
540
+ pattern = pattern.func;
541
+ }
542
+ else {
543
+ console.log(`Object must be stringified: ${JSON.stringify(pattern)}`);
544
+ pattern = JSON.stringify(pattern);
545
+ }
546
+ }
547
+ try {
548
+ if (this.props.custom) {
549
+ // eslint-disable-next-line no-new-func
550
+ const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
551
+ 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);
552
+ }
553
+ // eslint-disable-next-line no-new-func
554
+ const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
555
+ 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);
556
+ }
557
+ catch (e) {
558
+ console.error(`Cannot execute ${pattern}: ${e}`);
559
+ return pattern;
560
+ }
561
+ }
562
+ render() {
563
+ const schema = this.props.schema;
564
+ if (!schema) {
565
+ return null;
566
+ }
567
+ if (this.props.alive && this.defaultSendToDone === false) {
568
+ this.sendToTimeout = setTimeout(() => {
569
+ this.sendToTimeout = null;
570
+ this.sendTo();
571
+ }, 200);
572
+ }
573
+ const { error, disabled, hidden, defaultValue, } = this.calculate(schema);
574
+ if (hidden) {
575
+ // Remove all errors if element is hidden
576
+ if (Object.keys(this.isError).length) {
577
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
578
+ this.isError = {};
579
+ }
580
+ if (schema.hideOnlyControl) {
581
+ const item = react_1.default.createElement(material_1.Grid, { item: true, xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: (Object.assign(Object.assign({ marginBottom: 0, textAlign: 'left' }, schema.style), (this.props.themeType === 'dark' ? schema.darkStyle : {}))) });
582
+ if (schema.newLine) {
583
+ return react_1.default.createElement(react_1.default.Fragment, null,
584
+ react_1.default.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
585
+ item);
586
+ }
587
+ return item;
588
+ }
589
+ return null;
590
+ }
591
+ // Add error
592
+ if (schema.validatorNoSaveOnError) {
593
+ if (error && !Object.keys(this.isError).length) {
594
+ this.isError = {
595
+ [this.props.attr]: schema.validatorErrorText ? i18n_1.default.t(schema.validatorErrorText) : true,
596
+ };
597
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr, isError[attr])), 100, JSON.parse(JSON.stringify(this.isError)));
598
+ }
599
+ else if (!error && Object.keys(this.isError).length) {
600
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
601
+ this.isError = {};
602
+ }
603
+ }
604
+ const renderedItem = this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue);
605
+ if (this.noPlaceRequired) {
606
+ return renderedItem;
607
+ }
608
+ const item = react_1.default.createElement(material_1.Grid, { item: true, title: this.getText(schema.tooltip), xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: (Object.assign(Object.assign({ marginBottom: 0,
609
+ // marginRight: 8,
610
+ textAlign: 'left', width: schema.type === 'divider' || schema.type === 'header'
611
+ ? schema.width || '100%'
612
+ : undefined }, schema.style), (this.props.themeType === 'dark' ? schema.darkStyle : {}))) }, this.props.schema.defaultSendTo && this.props.schema.button ?
613
+ react_1.default.createElement(material_1.Grid, { container: true, style: { width: '100%' } },
614
+ react_1.default.createElement(material_1.Grid, { item: true, flex: 1 }, renderedItem),
615
+ react_1.default.createElement(material_1.Grid, { item: true },
616
+ react_1.default.createElement(material_1.Button, { variant: "outlined", onClick: () => this.sendTo(), title: this.props.schema.buttonTooltip
617
+ ? this.getText(this.props.schema.buttonTooltip, this.props.schema.buttonTooltipNoTranslation)
618
+ : i18n_1.default.t('ra_Request data by instance') }, this.getText(this.props.schema.button)))) : renderedItem);
619
+ if (schema.newLine) {
620
+ return react_1.default.createElement(react_1.default.Fragment, null,
621
+ react_1.default.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
622
+ this.renderConfirmDialog(),
623
+ item);
624
+ }
625
+ if (this.state.confirmDialog) {
626
+ return react_1.default.createElement(react_1.default.Fragment, null,
627
+ this.renderConfirmDialog(),
628
+ item);
629
+ }
630
+ return item;
631
+ }
632
+ }
633
+ ConfigGeneric.DIFFERENT_VALUE = '__different__';
634
+ ConfigGeneric.DIFFERENT_LABEL = 'ra___different__';
635
+ ConfigGeneric.NONE_VALUE = '';
636
+ ConfigGeneric.NONE_LABEL = 'ra_none';
637
+ exports.default = ConfigGeneric;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import type AdminConnection from './wrapper/AdminConnection';
3
+ import { ConfigGenericProps } from './ConfigGeneric';
4
+ interface ConfigNumberProps extends ConfigGenericProps {
5
+ socket: AdminConnection;
6
+ themeType: string;
7
+ themeName: string;
8
+ style: Record<string, any>;
9
+ className: string;
10
+ data: Record<string, any>;
11
+ schema: Record<string, any>;
12
+ onError: () => void;
13
+ onChange: () => void;
14
+ classes: Record<string, any>;
15
+ }
16
+ declare const _default: React.JSXElementConstructor<Omit<ConfigNumberProps, "classes"> & import("@mui/styles").StyledComponentProps<"indeterminate" | "control"> & object>;
17
+ export default _default;