@iobroker/adapter-react-v5 4.6.12 → 4.7.0

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 (36) hide show
  1. package/Components/FileViewer.js +1 -1
  2. package/Components/FileViewer.js.map +1 -1
  3. package/Components/JsonConfigComponent/ConfigColor.d.ts +2 -1
  4. package/Components/JsonConfigComponent/ConfigFile.js +1 -1
  5. package/Components/JsonConfigComponent/ConfigFile.js.map +1 -1
  6. package/Components/JsonConfigComponent/ConfigFileSelector.js +4 -4
  7. package/Components/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
  8. package/Components/JsonConfigComponent/ConfigGeneric.d.ts +68 -67
  9. package/Components/JsonConfigComponent/ConfigGeneric.js +600 -665
  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/ConfigNumber.d.ts +16 -2
  18. package/Components/JsonConfigComponent/ConfigNumber.js +105 -201
  19. package/Components/JsonConfigComponent/ConfigPattern.d.ts +2 -1
  20. package/Components/JsonConfigComponent/ConfigPort.d.ts +1 -1
  21. package/Components/JsonConfigComponent/ConfigPort.js +159 -210
  22. package/Components/JsonConfigComponent/ConfigUUID.d.ts +2 -1
  23. package/Components/JsonConfigComponent/wrapper/AdminConnection.d.ts +2 -0
  24. package/Components/JsonConfigComponent/wrapper/AdminConnection.js +7 -0
  25. package/Components/MDUtils.js +3 -3
  26. package/Components/MDUtils.js.map +1 -1
  27. package/Components/SimpleCron/cron2text.js +31 -36
  28. package/Components/SimpleCron/cron2text.js.map +1 -1
  29. package/Components/SimpleCron/index.js +10 -10
  30. package/Components/SimpleCron/index.js.map +1 -1
  31. package/LegacyConnection.js.map +1 -1
  32. package/README.md +1 -1
  33. package/package.json +1 -1
  34. package/Components/JsonConfigComponent/ConfigGeneric.js.map +0 -1
  35. package/Components/JsonConfigComponent/ConfigNumber.js.map +0 -1
  36. package/Components/JsonConfigComponent/ConfigPort.js.map +0 -1
@@ -1,702 +1,637 @@
1
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
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;
7
17
  });
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
- }
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();
64
80
  }
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);
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
+ }
83
97
  }, 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
98
  }
92
- }, 100);
93
99
  }
94
- } else if (this.props.schema.defaultSendTo) {
95
- this.sendTo();
96
- }
100
+ else if (this.props.schema.defaultSendTo) {
101
+ this.sendTo();
102
+ }
97
103
  }
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
- });
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
+ }
133
116
  }
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
- }
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
+ }
150
146
  }
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();
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
+ }
175
153
  }
176
- }, {
177
- key: "renderConfirmDialog",
178
- value: function renderConfirmDialog() {
179
- var _this4 = this;
180
- if (!this.state.confirmDialog) {
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
+ }
181
171
  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
- });
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
+ }
231
303
  }
232
- });
304
+ icon = react_1.default.createElement(Icon_1.default, { src: iconSettings, style: { width: 22, height: 22 } });
233
305
  }
234
- });
306
+ return icon;
235
307
  }
236
-
237
308
  /**
238
309
  * Trigger onChange, to activate save button on change
239
310
  *
240
311
  * @param attr the changed attribute
241
312
  * @param newValue new value of the attribute
242
- * @param {(() => void)?} cb optional callback function, else returns a Promise
243
- * @return {Promise<void>}
313
+ * @param cb optional callback function, else returns a Promise
244
314
  */
245
315
  // 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') {
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') {
286
329
  cb();
287
- } else {
330
+ }
331
+ else {
288
332
  resolve();
289
- }
290
- });
291
- })
292
- };
293
- }
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
+ }
294
363
  }
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);
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
+ }
313
383
  }
314
- if (_newValue !== val) {
315
- ConfigGeneric.setValue(data, dep.attr, _newValue);
316
- changed.push(dep.attr);
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);
317
389
  }
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();
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();
362
425
  }
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
- }
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
+ }
380
446
  }
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
- }
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
+ }
398
467
  }
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
- };
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
+ };
423
504
  }
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);
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);
433
513
  }
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);
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);
439
517
  }
440
-
441
518
  // 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;
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;
542
527
  }
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;
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));
632
532
  }
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
- }
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
+ }
653
561
  }
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();
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;
667
631
  }
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
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;