@iobroker/adapter-react-v5 4.10.2 → 4.11.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.
package/GenericApp.js CHANGED
@@ -1,1082 +1,835 @@
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 _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
16
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
17
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
- var _react = _interopRequireDefault(require("react"));
21
- var _socketClient = require("@iobroker/socket-client");
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
- var Sentry = _interopRequireWildcard(require("@sentry/browser"));
24
- var SentryIntegrations = _interopRequireWildcard(require("@sentry/integrations"));
25
- var _material = require("@mui/material");
26
- var _iconsMaterial = require("@mui/icons-material");
27
- var _Prompt = _interopRequireDefault(require("./Prompt"));
28
- var _Theme = _interopRequireDefault(require("./Theme"));
29
- var _Loader = _interopRequireDefault(require("./Components/Loader"));
30
- var _Router2 = _interopRequireDefault(require("./Components/Router"));
31
- var _Utils = _interopRequireDefault(require("./Components/Utils"));
32
- var _SaveCloseButtons = _interopRequireDefault(require("./Components/SaveCloseButtons"));
33
- var _Confirm = _interopRequireDefault(require("./Dialogs/Confirm"));
34
- var _i18n = _interopRequireDefault(require("./i18n"));
35
- var _Error = _interopRequireDefault(require("./Dialogs/Error"));
36
- 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); }
37
- 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; }
38
- 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; }
39
- 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; }
40
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
41
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
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
+ /**
42
30
  * Copyright 2018-2023 Denis Haev (bluefox) <dogafox@gmail.com>
43
31
  *
44
32
  * MIT License
45
33
  *
46
34
  **/
35
+ const react_1 = __importDefault(require("react"));
36
+ const socket_client_1 = require("@iobroker/socket-client");
37
+ const Sentry = __importStar(require("@sentry/browser"));
38
+ const SentryIntegrations = __importStar(require("@sentry/integrations"));
39
+ const material_1 = require("@mui/material");
40
+ const icons_material_1 = require("@mui/icons-material");
41
+ const Prompt_1 = __importDefault(require("./Prompt"));
42
+ const Theme_1 = __importDefault(require("./Theme"));
43
+ const Loader_1 = __importDefault(require("./Components/Loader"));
44
+ const Router_1 = __importDefault(require("./Components/Router"));
45
+ const Utils_1 = __importDefault(require("./Components/Utils"));
46
+ const SaveCloseButtons_1 = __importDefault(require("./Components/SaveCloseButtons"));
47
+ const Confirm_1 = __importDefault(require("./Dialogs/Confirm"));
48
+ const i18n_1 = __importDefault(require("./i18n"));
49
+ const Error_1 = __importDefault(require("./Dialogs/Error"));
47
50
  // import './index.css';
48
- var cssStyle = "\nhtml {\n height: 100%;\n}\n\nbody {\n margin: 0;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n width: 100%;\n height: 100%;\n overflow: hidden;\n}\n\n/* scrollbar */\n::-webkit-scrollbar-track {\n background-color: #ccc;\n border-radius: 5px;\n}\n\n::-webkit-scrollbar {\n width: 5px;\n height: 5px;\n background-color: #ccc;\n}\n\n::-webkit-scrollbar-thumb {\n background-color: #575757;\n border-radius: 5px;\n}\n\n#root {\n height: 100%;\n}\n\n.App {\n height: 100%;\n}\n\n@keyframes glow {\n from {\n background-color: initial;\n }\n to {\n background-color: #58c458;\n }\n}\n";
49
-
50
- // legacy and could be deleted
51
- if (!window.localStorage) {
52
- window.localStorage = {
53
- getItem: function getItem() {
54
- return null;
55
- },
56
- setItem: function setItem() {
57
- return null;
58
- }
59
- };
51
+ const cssStyle = `
52
+ html {
53
+ height: 100%;
60
54
  }
61
55
 
62
- /**
63
- * @extends {Router<import('./types').GenericAppProps, import('./types').GenericAppState>}
64
- */
65
- var GenericApp = /*#__PURE__*/function (_Router) {
66
- (0, _inherits2["default"])(GenericApp, _Router);
67
- /**
68
- * @param {import('./types').GenericAppProps} props
69
- * @param {import('./types').GenericAppSettings | undefined} settings
70
- */
71
- function GenericApp(props, settings) {
72
- var _ref, _settings$instance;
73
- var _this;
74
- (0, _classCallCheck2["default"])(this, GenericApp);
75
- var ConnectionClass = props.Connection || settings.Connection || _socketClient.Connection;
76
- // const ConnectionClass = props.Connection === 'admin' || settings.Connection = 'admin' ? AdminConnection : (props.Connection || settings.Connection || Connection);
56
+ body {
57
+ margin: 0;
58
+ padding: 0;
59
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
60
+ -webkit-font-smoothing: antialiased;
61
+ -moz-osx-font-smoothing: grayscale;
62
+ width: 100%;
63
+ height: 100%;
64
+ overflow: hidden;
65
+ }
77
66
 
78
- if (!window.document.getElementById('generic-app-iobroker-component')) {
79
- var style = window.document.createElement('style');
80
- style.setAttribute('id', 'generic-app-iobroker-component');
81
- style.innerHTML = cssStyle;
82
- window.document.head.appendChild(style);
83
- }
67
+ /* scrollbar */
68
+ ::-webkit-scrollbar-track {
69
+ background-color: #ccc;
70
+ border-radius: 5px;
71
+ }
84
72
 
85
- // Remove `!Connection.isWeb() && window.adapterName !== 'material'` when iobroker.socket will support native ws
86
- if (!ConnectionClass.isWeb() && window.io && window.location.port === '3000') {
87
- try {
88
- var io = new window.SocketClient();
89
- delete window.io;
90
- window.io = io;
91
- } catch (e) {
92
- // ignore
93
- }
94
- }
95
- _this = _callSuper(this, GenericApp, [props]);
96
- /**
97
- * @type {import('@iobroker/socket-client').Connection | import('@iobroker/socket-client').AdminConnection}
98
- */
99
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "socket", void 0);
100
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSystemConfigChanged", function (id, obj) {
101
- if (obj && id === 'system.config') {
102
- var _obj$common;
103
- if (_this.socket.systemLang !== (obj === null || obj === void 0 ? void 0 : obj.common.language)) {
104
- _this.socket.systemLang = (obj === null || obj === void 0 ? void 0 : obj.common.language) || 'en';
105
- _i18n["default"].setLanguage(_this.socket.systemLang);
106
- }
107
- if (_this._systemConfig.expertMode !== !!(obj !== null && obj !== void 0 && (_obj$common = obj.common) !== null && _obj$common !== void 0 && _obj$common.expertMode)) {
108
- _this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
109
- _this.setState({
110
- expertMode: _this.getExpertMode()
111
- });
112
- } else {
113
- _this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
114
- }
115
- }
116
- });
117
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onReceiveMessage", function (message) {
118
- if (message !== null && message !== void 0 && message.data) {
119
- if (message.data === 'updateTheme') {
120
- var newThemeName = _Utils["default"].getThemeName();
121
- _Utils["default"].setThemeName(_Utils["default"].getThemeName());
122
- var newTheme = _this.createTheme(newThemeName);
123
- _this.setState({
124
- theme: newTheme,
125
- themeName: _this.getThemeName(newTheme),
126
- themeType: _this.getThemeType(newTheme)
127
- }, function () {
128
- _this.props.onThemeChange && _this.props.onThemeChange(newThemeName);
129
- _this.onThemeChanged && _this.onThemeChanged(newThemeName);
130
- });
131
- } else if (message.data === 'updateExpertMode') {
132
- _this.onToggleExpertMode && _this.onToggleExpertMode(_this.getExpertMode());
133
- } else if (message.data !== 'chartReady') {
134
- // if not "echart ready" message
135
- console.debug("Received unknown message: \"".concat(JSON.stringify(message.data), "\". May be it will be processed later"));
136
- }
137
- }
138
- });
139
- /**
140
- * @private
141
- */
142
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onResize", function () {
143
- _this.resizeTimer && clearTimeout(_this.resizeTimer);
144
- _this.resizeTimer = setTimeout(function () {
145
- _this.resizeTimer = null;
146
- _this.setState({
147
- width: GenericApp.getWidth()
148
- });
149
- }, 200);
150
- });
151
- (0, _Prompt["default"])();
152
- var query = (window.location.search || '').replace(/^\?/, '').replace(/#.*$/, '');
153
- var args = {};
154
- query.trim().split('&').filter(function (t) {
155
- return t.trim();
156
- }).forEach(function (b) {
157
- var parts = b.split('=');
158
- args[parts[0]] = parts.length === 2 ? parts[1] : true;
159
- if (args[parts[0]] === 'true') {
160
- args[parts[0]] = true;
161
- } else if (args[parts[0]] === 'false') {
162
- args[parts[0]] = false;
163
- }
164
- });
73
+ ::-webkit-scrollbar {
74
+ width: 5px;
75
+ height: 5px;
76
+ background-color: #ccc;
77
+ }
165
78
 
166
- // extract instance from URL
167
- _this.instance = (_ref = (_settings$instance = settings === null || settings === void 0 ? void 0 : settings.instance) !== null && _settings$instance !== void 0 ? _settings$instance : props.instance) !== null && _ref !== void 0 ? _ref : args.instance !== undefined ? parseInt(args.instance, 10) || 0 : parseInt(window.location.search.slice(1), 10) || 0;
168
- // extract adapter name from URL
169
- var tmp = window.location.pathname.split('/');
170
- _this.adapterName = (settings === null || settings === void 0 ? void 0 : settings.adapterName) || props.adapterName || window.adapterName || tmp[tmp.length - 2] || 'iot';
171
- _this.instanceId = "system.adapter.".concat(_this.adapterName, ".").concat(_this.instance);
172
- _this.newReact = args.newReact === true; // it is admin5
79
+ ::-webkit-scrollbar-thumb {
80
+ background-color: #575757;
81
+ border-radius: 5px;
82
+ }
173
83
 
174
- var location = _Router2["default"].getLocation();
175
- location.tab = location.tab || (window._localStorage || window.localStorage).getItem("".concat(_this.adapterName, "-adapter")) || '';
176
- var themeInstance = _this.createTheme();
177
- _this.state = {
178
- selectedTab: (window._localStorage || window.localStorage).getItem("".concat(_this.adapterName, "-adapter")) || '',
179
- selectedTabNum: -1,
180
- "native": {},
181
- errorText: '',
182
- changed: false,
183
- connected: false,
184
- loaded: false,
185
- isConfigurationError: '',
186
- expertMode: false,
187
- toast: '',
188
- theme: themeInstance,
189
- themeName: _this.getThemeName(themeInstance),
190
- themeType: _this.getThemeType(themeInstance),
191
- bottomButtons: (settings && settings.bottomButtons) === false ? false : (props === null || props === void 0 ? void 0 : props.bottomButtons) !== false,
192
- width: GenericApp.getWidth(),
193
- confirmClose: false,
194
- _alert: false,
195
- _alertType: 'info',
196
- _alertMessage: ''
197
- };
84
+ #root {
85
+ height: 100%;
86
+ }
198
87
 
199
- // init translations
200
- var translations = {
201
- en: require('./i18n/en.json'),
202
- de: require('./i18n/de.json'),
203
- ru: require('./i18n/ru.json'),
204
- pt: require('./i18n/pt.json'),
205
- nl: require('./i18n/nl.json'),
206
- fr: require('./i18n/fr.json'),
207
- it: require('./i18n/it.json'),
208
- es: require('./i18n/es.json'),
209
- pl: require('./i18n/pl.json'),
210
- uk: require('./i18n/uk.json'),
211
- 'zh-cn': require('./i18n/zh-cn.json')
212
- };
88
+ .App {
89
+ height: 100%;
90
+ }
213
91
 
214
- // merge together
215
- if (settings && settings.translations) {
216
- Object.keys(settings.translations).forEach(function (lang) {
217
- return translations[lang] = Object.assign(translations[lang], settings.translations[lang]);
218
- });
219
- } else if (props.translations) {
220
- Object.keys(props.translations).forEach(function (lang) {
221
- return translations[lang] = Object.assign(translations[lang], props.translations[lang]);
222
- });
92
+ @keyframes glow {
93
+ from {
94
+ background-color: initial;
223
95
  }
224
- _i18n["default"].setTranslations(translations);
225
- _this.savedNative = {}; // to detect if the config changed
226
-
227
- _this.encryptedFields = props.encryptedFields || (settings === null || settings === void 0 ? void 0 : settings.encryptedFields) || [];
228
- _this.sentryDSN = settings && settings.sentryDSN || props.sentryDSN;
229
- if (window.socketUrl) {
230
- if (window.socketUrl.startsWith(':')) {
231
- window.socketUrl = "".concat(window.location.protocol, "//").concat(window.location.hostname).concat(window.socketUrl);
232
- } else if (!window.socketUrl.startsWith('http://') && !window.socketUrl.startsWith('https://')) {
233
- window.socketUrl = "".concat(window.location.protocol, "//").concat(window.socketUrl);
234
- }
96
+ to {
97
+ background-color: #58c458;
235
98
  }
236
- _this.alerDialogRendered = false;
237
- window.oldAlert = window.alert;
238
- window.alert = function (message) {
239
- if (!_this.alerDialogRendered) {
240
- window.oldAlert(message);
241
- return;
242
- }
243
- if (message && message.toString().toLowerCase().includes('error')) {
244
- console.error(message);
245
- _this.showAlert(message.toString(), 'error');
246
- } else {
247
- console.log(message);
248
- _this.showAlert(message.toString(), 'info');
249
- }
250
- };
251
- _this.socket = new ConnectionClass(_objectSpread(_objectSpread({}, (props === null || props === void 0 ? void 0 : props.socket) || (settings === null || settings === void 0 ? void 0 : settings.socket)), {}, {
252
- name: _this.adapterName,
253
- doNotLoadAllObjects: settings === null || settings === void 0 ? void 0 : settings.doNotLoadAllObjects,
254
- onProgress: function onProgress(progress) {
255
- if (progress === _socketClient.PROGRESS.CONNECTING) {
256
- _this.setState({
257
- connected: false
258
- });
259
- } else if (progress === _socketClient.PROGRESS.READY) {
260
- _this.setState({
261
- connected: true
262
- });
263
- } else {
264
- _this.setState({
265
- connected: true
266
- });
99
+ }
100
+ `;
101
+ class GenericApp extends Router_1.default {
102
+ /**
103
+ * @param {import('./types').GenericAppProps} props
104
+ * @param {import('./types').GenericAppSettings | undefined} settings
105
+ */
106
+ constructor(props, settings) {
107
+ var _a, _b;
108
+ const ConnectionClass = (props.Connection || (settings === null || settings === void 0 ? void 0 : settings.Connection) || socket_client_1.Connection);
109
+ // const ConnectionClass = props.Connection === 'admin' || settings.Connection = 'admin' ? AdminConnection : (props.Connection || settings.Connection || Connection);
110
+ if (!window.document.getElementById('generic-app-iobroker-component')) {
111
+ const style = window.document.createElement('style');
112
+ style.setAttribute('id', 'generic-app-iobroker-component');
113
+ style.innerHTML = cssStyle;
114
+ window.document.head.appendChild(style);
267
115
  }
268
- },
269
- onReady: function onReady( /* objects, scripts */
270
- ) {
271
- _i18n["default"].setLanguage(_this.socket.systemLang);
272
-
273
- // subscribe because of language and expert mode
274
- _this.socket.subscribeObject('system.config', _this.onSystemConfigChanged).then(function () {
275
- return _this.getSystemConfig();
276
- }).then(function (obj) {
277
- _this._secret = typeof obj !== 'undefined' && obj["native"] && obj["native"].secret || 'Zgfr56gFe87jJOM';
278
- _this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
279
- return _this.socket.getObject(_this.instanceId);
280
- }).then( /*#__PURE__*/function () {
281
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(instanceObj) {
282
- var _yield$_this$socket$g;
283
- var waitPromise, sentryPluginEnabled, sentryEnabled;
284
- return _regenerator["default"].wrap(function _callee$(_context) {
285
- while (1) switch (_context.prev = _context.next) {
286
- case 0:
287
- _context.next = 2;
288
- return _this.socket.getState("".concat(_this.instanceId, ".plugins.sentry.enabled"));
289
- case 2:
290
- _context.t1 = _yield$_this$socket$g = _context.sent;
291
- _context.t0 = _context.t1 === null;
292
- if (_context.t0) {
293
- _context.next = 6;
294
- break;
295
- }
296
- _context.t0 = _yield$_this$socket$g === void 0;
297
- case 6:
298
- if (!_context.t0) {
299
- _context.next = 10;
300
- break;
301
- }
302
- _context.t2 = void 0;
303
- _context.next = 11;
304
- break;
305
- case 10:
306
- _context.t2 = _yield$_this$socket$g.val;
307
- case 11:
308
- sentryPluginEnabled = _context.t2;
309
- sentryEnabled = sentryPluginEnabled !== false && _this._systemConfig.diag !== 'none' && (instanceObj === null || instanceObj === void 0 ? void 0 : instanceObj.common) && instanceObj.common.name && instanceObj.common.version && !instanceObj.common.disableDataReporting && window.location.host !== 'localhost:3000'; // activate sentry plugin
310
- if (!_this.sentryStarted && _this.sentryDSN && sentryEnabled) {
311
- _this.sentryStarted = true;
312
- Sentry.init({
313
- dsn: _this.sentryDSN,
314
- release: "iobroker.".concat(instanceObj.common.name, "@").concat(instanceObj.common.version),
315
- integrations: [new SentryIntegrations.Dedupe()]
116
+ // Remove `!Connection.isWeb() && window.adapterName !== 'material'` when iobroker.socket will support native ws
117
+ if (!GenericApp.isWeb() && window.io && window.location.port === '3000') {
118
+ try {
119
+ const io = new window.SocketClient();
120
+ delete window.io;
121
+ window.io = io;
122
+ }
123
+ catch (e) {
124
+ // ignore
125
+ }
126
+ }
127
+ super(props);
128
+ this.common = null;
129
+ this.sentryStarted = false;
130
+ this.sentryInited = false;
131
+ this.resizeTimer = null;
132
+ this.onSystemConfigChanged = (id, obj) => {
133
+ var _a, _b;
134
+ if (obj && id === 'system.config') {
135
+ if (this.socket.systemLang !== (obj === null || obj === void 0 ? void 0 : obj.common.language)) {
136
+ this.socket.systemLang = (obj === null || obj === void 0 ? void 0 : obj.common.language) || 'en';
137
+ i18n_1.default.setLanguage(this.socket.systemLang);
138
+ }
139
+ if (((_a = this._systemConfig) === null || _a === void 0 ? void 0 : _a.expertMode) !== !!((_b = obj === null || obj === void 0 ? void 0 : obj.common) === null || _b === void 0 ? void 0 : _b.expertMode)) {
140
+ this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
141
+ this.setState({ expertMode: this.getExpertMode() });
142
+ }
143
+ else {
144
+ this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
145
+ }
146
+ }
147
+ };
148
+ this.onReceiveMessage = (message) => {
149
+ if (message === null || message === void 0 ? void 0 : message.data) {
150
+ if (message.data === 'updateTheme') {
151
+ const newThemeName = Utils_1.default.getThemeName();
152
+ Utils_1.default.setThemeName(Utils_1.default.getThemeName());
153
+ const newTheme = this.createTheme(newThemeName);
154
+ this.setState({
155
+ theme: newTheme,
156
+ themeName: this.getThemeName(newTheme),
157
+ themeType: this.getThemeType(newTheme),
158
+ }, () => {
159
+ this.props.onThemeChange && this.props.onThemeChange(newThemeName);
160
+ this.onThemeChanged && this.onThemeChanged(newThemeName);
316
161
  });
317
- console.log('Sentry initialized');
318
- }
319
-
320
- // read UUID and init sentry with it.
321
- // for backward compatibility it will be processed separately from above logic: some adapters could still have this.sentryDSN as undefined
322
- if (!_this.sentryInited && sentryEnabled) {
323
- _this.sentryInited = true;
324
- waitPromise = _this.socket.getObject('system.meta.uuid').then(function (uuidObj) {
325
- if (uuidObj && uuidObj["native"] && uuidObj["native"].uuid) {
326
- Sentry.configureScope(function (scope) {
327
- return scope.setUser({
328
- id: uuidObj["native"].uuid
329
- });
162
+ }
163
+ else if (message.data === 'updateExpertMode') {
164
+ this.onToggleExpertMode && this.onToggleExpertMode(this.getExpertMode());
165
+ }
166
+ else if (message.data !== 'chartReady') { // if not "echart ready" message
167
+ console.debug(`Received unknown message: "${JSON.stringify(message.data)}". May be it will be processed later`);
168
+ }
169
+ }
170
+ };
171
+ /**
172
+ * @private
173
+ */
174
+ this.onResize = () => {
175
+ this.resizeTimer && clearTimeout(this.resizeTimer);
176
+ this.resizeTimer = setTimeout(() => {
177
+ this.resizeTimer = null;
178
+ this.setState({ width: GenericApp.getWidth() });
179
+ }, 200);
180
+ };
181
+ (0, Prompt_1.default)();
182
+ const query = (window.location.search || '').replace(/^\?/, '').replace(/#.*$/, '');
183
+ const args = {};
184
+ query.trim().split('&').filter(t => t.trim()).forEach(b => {
185
+ const parts = b.split('=');
186
+ args[parts[0]] = parts.length === 2 ? parts[1] : true;
187
+ if (args[parts[0]] === 'true') {
188
+ args[parts[0]] = true;
189
+ }
190
+ else if (args[parts[0]] === 'false') {
191
+ args[parts[0]] = false;
192
+ }
193
+ });
194
+ // extract instance from URL
195
+ this.instance = (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.instance) !== null && _a !== void 0 ? _a : props.instance) !== null && _b !== void 0 ? _b : (args.instance !== undefined ? parseInt(args.instance, 10) || 0 : (parseInt(window.location.search.slice(1), 10) || 0));
196
+ // extract adapter name from URL
197
+ const tmp = window.location.pathname.split('/');
198
+ this.adapterName = (settings === null || settings === void 0 ? void 0 : settings.adapterName) || props.adapterName || window.adapterName || tmp[tmp.length - 2] || 'iot';
199
+ this.instanceId = `system.adapter.${this.adapterName}.${this.instance}`;
200
+ this.newReact = args.newReact === true; // it is admin5
201
+ const location = Router_1.default.getLocation();
202
+ location.tab = location.tab || (window._localStorage || window.localStorage).getItem(`${this.adapterName}-adapter`) || '';
203
+ const themeInstance = this.createTheme();
204
+ this.state = {
205
+ selectedTab: (window._localStorage || window.localStorage).getItem(`${this.adapterName}-adapter`) || '',
206
+ selectedTabNum: -1,
207
+ native: {},
208
+ errorText: '',
209
+ changed: false,
210
+ connected: false,
211
+ loaded: false,
212
+ isConfigurationError: '',
213
+ expertMode: false,
214
+ toast: '',
215
+ theme: themeInstance,
216
+ themeName: this.getThemeName(themeInstance),
217
+ themeType: this.getThemeType(themeInstance),
218
+ bottomButtons: (settings && settings.bottomButtons) === false ? false : ((props === null || props === void 0 ? void 0 : props.bottomButtons) !== false),
219
+ width: GenericApp.getWidth(),
220
+ confirmClose: false,
221
+ _alert: false,
222
+ _alertType: 'info',
223
+ _alertMessage: '',
224
+ };
225
+ // init translations
226
+ const translations = {
227
+ en: require('./i18n/en.json'),
228
+ de: require('./i18n/de.json'),
229
+ ru: require('./i18n/ru.json'),
230
+ pt: require('./i18n/pt.json'),
231
+ nl: require('./i18n/nl.json'),
232
+ fr: require('./i18n/fr.json'),
233
+ it: require('./i18n/it.json'),
234
+ es: require('./i18n/es.json'),
235
+ pl: require('./i18n/pl.json'),
236
+ uk: require('./i18n/uk.json'),
237
+ 'zh-cn': require('./i18n/zh-cn.json'),
238
+ };
239
+ // merge together
240
+ if (settings && settings.translations) {
241
+ Object.keys(settings.translations).forEach(lang => {
242
+ if (settings.translations) {
243
+ translations[lang] = Object.assign(translations[lang], settings.translations[lang] || {});
244
+ }
245
+ });
246
+ }
247
+ else if (props.translations) {
248
+ Object.keys(props.translations).forEach(lang => {
249
+ if (props.translations) {
250
+ translations[lang] = Object.assign(translations[lang], props.translations[lang] || {});
251
+ }
252
+ });
253
+ }
254
+ i18n_1.default.setTranslations(translations);
255
+ this.savedNative = {}; // to detect if the config changed
256
+ this.encryptedFields = props.encryptedFields || (settings === null || settings === void 0 ? void 0 : settings.encryptedFields) || [];
257
+ this.sentryDSN = (settings && settings.sentryDSN) || props.sentryDSN;
258
+ if (window.socketUrl) {
259
+ if (window.socketUrl.startsWith(':')) {
260
+ window.socketUrl = `${window.location.protocol}//${window.location.hostname}${window.socketUrl}`;
261
+ }
262
+ else if (!window.socketUrl.startsWith('http://') && !window.socketUrl.startsWith('https://')) {
263
+ window.socketUrl = `${window.location.protocol}//${window.socketUrl}`;
264
+ }
265
+ }
266
+ this.alertDialogRendered = false;
267
+ window.oldAlert = window.alert;
268
+ window.alert = message => {
269
+ if (!this.alertDialogRendered) {
270
+ window.oldAlert(message);
271
+ return;
272
+ }
273
+ if (message && message.toString().toLowerCase().includes('error')) {
274
+ console.error(message);
275
+ this.showAlert(message.toString(), 'error');
276
+ }
277
+ else {
278
+ console.log(message);
279
+ this.showAlert(message.toString(), 'info');
280
+ }
281
+ };
282
+ // @ts-expect-error I don't know
283
+ this.socket = new ConnectionClass(Object.assign(Object.assign({}, ((props === null || props === void 0 ? void 0 : props.socket) || (settings === null || settings === void 0 ? void 0 : settings.socket))), { name: this.adapterName, doNotLoadAllObjects: settings === null || settings === void 0 ? void 0 : settings.doNotLoadAllObjects, onProgress: (progress) => {
284
+ if (progress === socket_client_1.PROGRESS.CONNECTING) {
285
+ this.setState({ connected: false });
286
+ }
287
+ else if (progress === socket_client_1.PROGRESS.READY) {
288
+ this.setState({ connected: true });
289
+ }
290
+ else {
291
+ this.setState({ connected: true });
292
+ }
293
+ }, onReady: ( /* objects, scripts */) => {
294
+ i18n_1.default.setLanguage(this.socket.systemLang);
295
+ // subscribe because of language and expert mode
296
+ this.socket.subscribeObject('system.config', this.onSystemConfigChanged)
297
+ .then(() => this.getSystemConfig())
298
+ .then(obj => {
299
+ this._secret = (typeof obj !== 'undefined' && obj.native && obj.native.secret) || 'Zgfr56gFe87jJOM';
300
+ this._systemConfig = (obj === null || obj === void 0 ? void 0 : obj.common) || {};
301
+ return this.socket.getObject(this.instanceId);
302
+ })
303
+ .then(async (obj) => {
304
+ var _a, _b;
305
+ let waitPromise;
306
+ const instanceObj = obj;
307
+ const sentryPluginEnabled = (_a = (await this.socket.getState(`${this.instanceId}.plugins.sentry.enabled`))) === null || _a === void 0 ? void 0 : _a.val;
308
+ const sentryEnabled = sentryPluginEnabled !== false &&
309
+ ((_b = this._systemConfig) === null || _b === void 0 ? void 0 : _b.diag) !== 'none' &&
310
+ (instanceObj === null || instanceObj === void 0 ? void 0 : instanceObj.common) &&
311
+ instanceObj.common.name &&
312
+ instanceObj.common.version &&
313
+ // @ts-expect-error will be extended in js-controller
314
+ !instanceObj.common.disableDataReporting &&
315
+ window.location.host !== 'localhost:3000';
316
+ // activate sentry plugin
317
+ if (!this.sentryStarted && this.sentryDSN && sentryEnabled) {
318
+ this.sentryStarted = true;
319
+ Sentry.init({
320
+ dsn: this.sentryDSN,
321
+ release: `iobroker.${instanceObj.common.name}@${instanceObj.common.version}`,
322
+ integrations: [
323
+ new SentryIntegrations.Dedupe(),
324
+ ],
330
325
  });
331
- }
332
- });
333
- }
334
- waitPromise = waitPromise || Promise.resolve();
335
- waitPromise.then(function () {
336
- if (instanceObj) {
337
- _this.common = instanceObj === null || instanceObj === void 0 ? void 0 : instanceObj.common;
338
- _this.onPrepareLoad(instanceObj["native"], instanceObj.encryptedNative); // decode all secrets
339
- _this.savedNative = JSON.parse(JSON.stringify(instanceObj["native"]));
340
- _this.setState({
341
- "native": instanceObj["native"],
342
- loaded: true,
343
- expertMode: _this.getExpertMode()
344
- }, function () {
345
- return _this.onConnectionReady && _this.onConnectionReady();
346
- });
347
- } else {
348
- console.warn('Cannot load instance settings');
349
- _this.setState({
350
- "native": {},
351
- loaded: true,
352
- expertMode: _this.getExpertMode()
353
- }, function () {
354
- return _this.onConnectionReady && _this.onConnectionReady();
355
- });
326
+ console.log('Sentry initialized');
356
327
  }
357
- });
358
- case 17:
359
- case "end":
360
- return _context.stop();
361
- }
362
- }, _callee);
363
- }));
364
- return function (_x) {
365
- return _ref2.apply(this, arguments);
366
- };
367
- }())["catch"](function (e) {
368
- return window.alert("Cannot settings: ".concat(e));
328
+ // read UUID and init sentry with it.
329
+ // for backward compatibility it will be processed separately from above logic: some adapters could still have this.sentryDSN as undefined
330
+ if (!this.sentryInited && sentryEnabled) {
331
+ this.sentryInited = true;
332
+ waitPromise = this.socket.getObject('system.meta.uuid')
333
+ .then(uuidObj => {
334
+ if (uuidObj && uuidObj.native && uuidObj.native.uuid) {
335
+ Sentry.configureScope(scope => scope.setUser({ id: uuidObj.native.uuid }));
336
+ }
337
+ });
338
+ }
339
+ waitPromise = waitPromise || Promise.resolve();
340
+ waitPromise
341
+ .then(() => {
342
+ if (instanceObj) {
343
+ this.common = instanceObj === null || instanceObj === void 0 ? void 0 : instanceObj.common;
344
+ this.onPrepareLoad(instanceObj.native, instanceObj.encryptedNative); // decode all secrets
345
+ this.savedNative = JSON.parse(JSON.stringify(instanceObj.native));
346
+ this.setState({ native: instanceObj.native, loaded: true, expertMode: this.getExpertMode() }, () => this.onConnectionReady && this.onConnectionReady());
347
+ }
348
+ else {
349
+ console.warn('Cannot load instance settings');
350
+ this.setState({
351
+ native: {},
352
+ loaded: true,
353
+ expertMode: this.getExpertMode(),
354
+ }, () => this.onConnectionReady && this.onConnectionReady());
355
+ }
356
+ });
357
+ })
358
+ .catch(e => window.alert(`Cannot settings: ${e}`));
359
+ }, onError: (err) => {
360
+ console.error(err);
361
+ this.showError(err);
362
+ } }));
363
+ }
364
+ /**
365
+ * Checks if this connection is running in a web adapter and not in an admin.
366
+ * @returns True if running in a web adapter or in a socketio adapter.
367
+ */
368
+ static isWeb() {
369
+ return window.socketUrl !== undefined;
370
+ }
371
+ showAlert(message, type) {
372
+ if (type !== 'error' && type !== 'warning' && type !== 'info' && type !== 'success') {
373
+ type = 'info';
374
+ }
375
+ this.setState({
376
+ _alert: true,
377
+ _alertType: type,
378
+ _alertMessage: message,
369
379
  });
370
- },
371
- onError: function onError(err) {
372
- console.error(err);
373
- _this.showError(err);
374
- }
375
- }));
376
- return _this;
377
- }
378
- (0, _createClass2["default"])(GenericApp, [{
379
- key: "showAlert",
380
- value: function showAlert(message, type) {
381
- if (type !== 'error' && type !== 'warning' && type !== 'info' && type !== 'success') {
382
- type = 'info';
383
- }
384
- this.setState({
385
- _alert: true,
386
- _alertType: type,
387
- _alertMessage: message
388
- });
389
380
  }
390
- }, {
391
- key: "renderAlertSnackbar",
392
- value: function renderAlertSnackbar() {
393
- var _this2 = this;
394
- this.alerDialogRendered = true;
395
- return /*#__PURE__*/_react["default"].createElement(_material.Snackbar, {
396
- style: this.state._alertType === 'error' ? {
397
- backgroundColor: '#f44336'
398
- } : this.state._alertType === 'success' ? {
399
- backgroundColor: '#4caf50'
400
- } : undefined,
401
- open: this.state._alert,
402
- autoHideDuration: 6000,
403
- onClose: function onClose(reason) {
404
- return reason !== 'clickaway' && _this2.setState({
405
- _alert: false
406
- });
407
- },
408
- message: this.state.alertMessage
409
- });
381
+ renderAlertSnackbar() {
382
+ this.alertDialogRendered = true;
383
+ return react_1.default.createElement(material_1.Snackbar, { style: this.state._alertType === 'error' ?
384
+ { backgroundColor: '#f44336' } :
385
+ (this.state._alertType === 'success' ? { backgroundColor: '#4caf50' } : undefined), open: this.state._alert, autoHideDuration: 6000, onClose: (_e, reason) => reason !== 'clickaway' && this.setState({ _alert: false }), message: this.state._alertMessage });
410
386
  }
411
- }, {
412
- key: "componentDidMount",
413
- value:
414
387
  /**
415
388
  * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
416
389
  */
417
- function componentDidMount() {
418
- window.addEventListener('resize', this.onResize, true);
419
- window.addEventListener('message', this.onReceiveMessage, false);
420
- (0, _get2["default"])((0, _getPrototypeOf2["default"])(GenericApp.prototype), "componentDidMount", this).call(this);
390
+ componentDidMount() {
391
+ window.addEventListener('resize', this.onResize, true);
392
+ window.addEventListener('message', this.onReceiveMessage, false);
393
+ super.componentDidMount();
421
394
  }
422
-
423
395
  /**
424
396
  * Called immediately before a component is destroyed.
425
397
  */
426
- }, {
427
- key: "componentWillUnmount",
428
- value: function componentWillUnmount() {
429
- window.removeEventListener('resize', this.onResize, true);
430
- window.removeEventListener('message', this.onReceiveMessage, false);
431
- (0, _get2["default"])((0, _getPrototypeOf2["default"])(GenericApp.prototype), "componentWillUnmount", this).call(this);
398
+ componentWillUnmount() {
399
+ window.removeEventListener('resize', this.onResize, true);
400
+ window.removeEventListener('message', this.onReceiveMessage, false);
401
+ super.componentWillUnmount();
402
+ }
403
+ /**
404
+ * Gets the width depending on the window inner width.
405
+ * @returns {import('./types').Width}
406
+ */
407
+ static getWidth() {
408
+ /**
409
+ * innerWidth |xs sm md lg xl
410
+ * |-------|-------|-------|-------|------>
411
+ * width | xs | sm | md | lg | xl
412
+ */
413
+ const SIZES = {
414
+ xs: 0,
415
+ sm: 600,
416
+ md: 960,
417
+ lg: 1280,
418
+ xl: 1920,
419
+ };
420
+ const width = window.innerWidth;
421
+ const keys = Object.keys(SIZES).reverse();
422
+ const widthComputed = keys.find(key => width >= SIZES[key]);
423
+ return widthComputed || 'xs';
432
424
  }
433
- }, {
434
- key: "createTheme",
435
- value:
436
425
  /**
437
426
  * Get a theme
438
- * @param {string} name Theme name
439
- * @returns {import('./types').Theme}
427
+ * @param name Theme name
440
428
  */
441
- function createTheme() {
442
- var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
443
- return (0, _Theme["default"])(_Utils["default"].getThemeName(name));
429
+ createTheme(name) {
430
+ return (0, Theme_1.default)(Utils_1.default.getThemeName(name));
444
431
  }
445
-
446
432
  /**
447
433
  * Get the theme name
448
- * @param {import('./types').Theme} currentTheme Theme
449
- * @returns {string} Theme name
450
434
  */
451
- }, {
452
- key: "getThemeName",
453
- value: function getThemeName(currentTheme) {
454
- return currentTheme.name;
435
+ getThemeName(currentTheme) {
436
+ return currentTheme.name;
455
437
  }
456
-
457
438
  /**
458
439
  * Get the theme type
459
- * @param {import('./types').Theme} currentTheme Theme
460
- * @returns {string} Theme type
461
440
  */
462
- }, {
463
- key: "getThemeType",
464
- value: function getThemeType(currentTheme) {
465
- return currentTheme.palette.mode;
441
+ getThemeType(currentTheme) {
442
+ return currentTheme.palette.mode;
443
+ }
444
+ onThemeChanged(newThemeName) {
445
+ }
446
+ onToggleExpertMode(expertMode) {
466
447
  }
467
-
468
448
  /**
469
449
  * Changes the current theme
470
- * @param {string} newThemeName Theme name
450
+ * @param newThemeName Theme name
471
451
  **/
472
- }, {
473
- key: "toggleTheme",
474
- value: function toggleTheme(newThemeName) {
475
- var _this3 = this;
476
- var themeName = this.state.themeName;
477
-
478
- // dark => blue => colored => light => dark
479
- newThemeName = newThemeName || (themeName === 'dark' ? 'blue' : themeName === 'blue' ? 'colored' : themeName === 'colored' ? 'light' : 'dark');
480
- if (newThemeName !== themeName) {
481
- _Utils["default"].setThemeName(newThemeName);
482
- var newTheme = this.createTheme(newThemeName);
483
- this.setState({
484
- theme: newTheme,
485
- themeName: this.getThemeName(newTheme),
486
- themeType: this.getThemeType(newTheme)
487
- }, function () {
488
- _this3.props.onThemeChange && _this3.props.onThemeChange(newThemeName);
489
- _this3.onThemeChanged && _this3.onThemeChanged(newThemeName);
490
- });
491
- }
452
+ toggleTheme(newThemeName) {
453
+ const themeName = this.state.themeName;
454
+ // dark => blue => colored => light => dark
455
+ newThemeName = newThemeName || (themeName === 'dark' ? 'blue' :
456
+ (themeName === 'blue' ? 'colored' :
457
+ (themeName === 'colored' ? 'light' : 'dark')));
458
+ if (newThemeName !== themeName) {
459
+ Utils_1.default.setThemeName(newThemeName);
460
+ const newTheme = this.createTheme(newThemeName);
461
+ this.setState({
462
+ theme: newTheme,
463
+ themeName: this.getThemeName(newTheme),
464
+ themeType: this.getThemeType(newTheme),
465
+ }, () => {
466
+ this.props.onThemeChange && this.props.onThemeChange(newThemeName || 'light');
467
+ this.onThemeChanged && this.onThemeChanged(newThemeName || 'light');
468
+ });
469
+ }
492
470
  }
493
-
494
471
  /**
495
472
  * Gets the system configuration.
496
473
  * @returns {Promise<ioBroker.OtherObject>}
497
474
  */
498
- }, {
499
- key: "getSystemConfig",
500
- value: function getSystemConfig() {
501
- return this.socket.getSystemConfig();
475
+ getSystemConfig() {
476
+ return this.socket.getSystemConfig();
502
477
  }
503
-
504
478
  /**
505
479
  * Get current expert mode
506
480
  * @returns {boolean}
507
481
  */
508
- }, {
509
- key: "getExpertMode",
510
- value: function getExpertMode() {
511
- return window.sessionStorage.getItem('App.expertMode') === 'true' || !!this._systemConfig.expertMode;
482
+ getExpertMode() {
483
+ var _a;
484
+ return window.sessionStorage.getItem('App.expertMode') === 'true' || !!((_a = this._systemConfig) === null || _a === void 0 ? void 0 : _a.expertMode);
512
485
  }
513
-
514
486
  /**
515
487
  * Gets called when the socket.io connection is ready.
516
488
  * You can overload this function to execute own commands.
517
489
  */
518
- }, {
519
- key: "onConnectionReady",
520
- value: function onConnectionReady() {}
521
-
490
+ onConnectionReady() {
491
+ }
522
492
  /**
523
493
  * Encrypts a string.
524
- * @param {string} value
525
- * @returns {string}
526
494
  */
527
- }, {
528
- key: "encrypt",
529
- value: function encrypt(value) {
530
- var result = '';
531
- for (var i = 0; i < value.length; i++) {
532
- result += String.fromCharCode(this._secret[i % this._secret.length].charCodeAt(0) ^ value.charCodeAt(i));
533
- }
534
- return result;
495
+ encrypt(value) {
496
+ let result = '';
497
+ if (this._secret) {
498
+ for (let i = 0; i < value.length; i++) {
499
+ result += String.fromCharCode(this._secret[i % this._secret.length].charCodeAt(0) ^ value.charCodeAt(i));
500
+ }
501
+ }
502
+ return result;
535
503
  }
536
-
537
504
  /**
538
505
  * Decrypts a string.
539
- * @param {string} value
540
- * @returns {string}
541
506
  */
542
- }, {
543
- key: "decrypt",
544
- value: function decrypt(value) {
545
- var result = '';
546
- for (var i = 0; i < value.length; i++) {
547
- result += String.fromCharCode(this._secret[i % this._secret.length].charCodeAt(0) ^ value.charCodeAt(i));
548
- }
549
- return result;
507
+ decrypt(value) {
508
+ let result = '';
509
+ if (this._secret) {
510
+ for (let i = 0; i < value.length; i++) {
511
+ result += String.fromCharCode(this._secret[i % this._secret.length].charCodeAt(0) ^ value.charCodeAt(i));
512
+ }
513
+ }
514
+ return result;
550
515
  }
551
-
552
516
  /**
553
517
  * Gets called when the navigation hash changes.
554
518
  * You may override this if needed.
555
519
  */
556
- }, {
557
- key: "onHashChanged",
558
- value: function onHashChanged() {
559
- var location = _Router2["default"].getLocation();
560
- if (location.tab !== this.state.selectedTab) {
561
- this.selectTab(location.tab);
562
- }
520
+ onHashChanged() {
521
+ const location = Router_1.default.getLocation();
522
+ if (location.tab !== this.state.selectedTab) {
523
+ this.selectTab(location.tab);
524
+ }
563
525
  }
564
-
565
526
  /**
566
527
  * Selects the given tab.
567
- * @param {string} tab
568
- * @param {number} [index]
569
528
  */
570
- }, {
571
- key: "selectTab",
572
- value: function selectTab(tab, index) {
573
- (window._localStorage || window.localStorage).setItem("".concat(this.adapterName, "-adapter"), tab);
574
- this.setState({
575
- selectedTab: tab,
576
- selectedTabNum: index
577
- });
529
+ selectTab(tab, index) {
530
+ (window._localStorage || window.localStorage).setItem(`${this.adapterName}-adapter`, tab);
531
+ this.setState({ selectedTab: tab, selectedTabNum: index });
578
532
  }
579
-
580
533
  /**
581
534
  * Gets called before the settings are saved.
582
535
  * You may override this if needed.
583
- * @param {Record<string, any>} settings
584
536
  */
585
- }, {
586
- key: "onPrepareSave",
587
- value: function onPrepareSave(settings) {
588
- var _this4 = this;
589
- // here you can encode values
590
- this.encryptedFields && this.encryptedFields.forEach(function (attr) {
591
- if (settings[attr]) {
592
- settings[attr] = _this4.encrypt(settings[attr]);
593
- }
594
- });
595
- return true;
537
+ onPrepareSave(settings) {
538
+ // here you can encode values
539
+ this.encryptedFields && this.encryptedFields.forEach(attr => {
540
+ if (settings[attr]) {
541
+ settings[attr] = this.encrypt(settings[attr]);
542
+ }
543
+ });
544
+ return true;
596
545
  }
597
-
598
546
  /**
599
547
  * Gets called after the settings are loaded.
600
548
  * You may override this if needed.
601
- * @param {Record<string, any>} settings
602
- * @param {string[]} encryptedNative optional list of fields to be decrypted
549
+ * @param encryptedNative optional list of fields to be decrypted
603
550
  */
604
- }, {
605
- key: "onPrepareLoad",
606
- value: function onPrepareLoad(settings, encryptedNative) {
607
- var _this5 = this;
608
- // here you can encode values
609
- this.encryptedFields && this.encryptedFields.forEach(function (attr) {
610
- if (settings[attr]) {
611
- settings[attr] = _this5.decrypt(settings[attr]);
612
- }
613
- });
614
- encryptedNative && encryptedNative.forEach(function (attr) {
615
- _this5.encryptedFields = _this5.encryptedFields || [];
616
- !_this5.encryptedFields.includes(attr) && _this5.encryptedFields.push(attr);
617
- if (settings[attr]) {
618
- settings[attr] = _this5.decrypt(settings[attr]);
619
- }
620
- });
551
+ onPrepareLoad(settings, encryptedNative) {
552
+ // here you can encode values
553
+ this.encryptedFields && this.encryptedFields.forEach(attr => {
554
+ if (settings[attr]) {
555
+ settings[attr] = this.decrypt(settings[attr]);
556
+ }
557
+ });
558
+ encryptedNative && encryptedNative.forEach(attr => {
559
+ this.encryptedFields = this.encryptedFields || [];
560
+ !this.encryptedFields.includes(attr) && this.encryptedFields.push(attr);
561
+ if (settings[attr]) {
562
+ settings[attr] = this.decrypt(settings[attr]);
563
+ }
564
+ });
621
565
  }
622
-
623
566
  /**
624
567
  * Gets the extendable instances.
625
568
  * @returns {Promise<any[]>}
626
569
  */
627
- }, {
628
- key: "getExtendableInstances",
629
- value: function getExtendableInstances() {
630
- var _this6 = this;
631
- return new Promise(function (resolve) {
632
- _this6.socket._socket.emit('getObjectView', 'system', 'instance', null, function (err, doc) {
633
- if (err) {
634
- resolve([]);
635
- } else {
636
- resolve(doc.rows.filter(function (item) {
637
- return item.value.common.webExtendable;
638
- }).map(function (item) {
639
- return item.value;
640
- }));
641
- }
642
- });
643
- });
570
+ async getExtendableInstances() {
571
+ try {
572
+ const instances = await this.socket.getObjectViewSystem('instance', 'system.adapter.', 'system.adapter.\u9999');
573
+ return Object.values(instances).filter(instance => { var _a; return !!((_a = instance === null || instance === void 0 ? void 0 : instance.common) === null || _a === void 0 ? void 0 : _a.webExtendable); });
574
+ }
575
+ catch (e) {
576
+ return [];
577
+ }
644
578
  }
645
-
646
579
  /**
647
580
  * Gets the IP addresses of the given host.
648
- * @param {string} host
649
581
  */
650
- }, {
651
- key: "getIpAddresses",
652
- value: function getIpAddresses(host) {
653
- var _this7 = this;
654
- return new Promise(function (resolve) {
655
- _this7.socket._socket.emit('getHostByIp', host || _this7.common.host, function (ip, _host) {
656
- var IPs4 = [{
657
- name: "[IPv4] 0.0.0.0 - ".concat(_i18n["default"].t('ra_Listen on all IPs')),
658
- address: '0.0.0.0',
659
- family: 'ipv4'
660
- }];
661
- var IPs6 = [{
662
- name: '[IPv6] ::',
663
- address: '::',
664
- family: 'ipv6'
665
- }];
666
- if (_host) {
667
- host = _host;
668
- if (host["native"].hardware && host["native"].hardware.networkInterfaces) {
669
- Object.keys(host["native"].hardware.networkInterfaces).forEach(function (eth) {
670
- return host["native"].hardware.networkInterfaces[eth].forEach(function (inter) {
671
- if (inter.family !== 'IPv6') {
672
- IPs4.push({
673
- name: "[".concat(inter.family, "] ").concat(inter.address, " - ").concat(eth),
674
- address: inter.address,
675
- family: 'ipv4'
676
- });
677
- } else {
678
- IPs6.push({
679
- name: "[".concat(inter.family, "] ").concat(inter.address, " - ").concat(eth),
680
- address: inter.address,
681
- family: 'ipv6'
682
- });
683
- }
684
- });
685
- });
686
- }
687
- IPs6.forEach(function (_ip) {
688
- return IPs4.push(_ip);
689
- });
690
- }
691
- resolve(IPs4);
692
- });
693
- });
582
+ async getIpAddresses(host) {
583
+ var _a;
584
+ const ips = await this.socket.getHostByIp(host || ((_a = this.common) === null || _a === void 0 ? void 0 : _a.host) || '');
585
+ // translate names
586
+ const ip4_0 = ips.find(ip => ip.address === '0.0.0.0');
587
+ if (ip4_0) {
588
+ ip4_0.name = `[IPv4] 0.0.0.0 - ${i18n_1.default.t('ra_Listen on all IPs')}`;
589
+ }
590
+ const ip6_0 = ips.find(ip => ip.address === '::');
591
+ if (ip6_0) {
592
+ ip6_0.name = `[IPv4] :: - ${i18n_1.default.t('ra_Listen on all IPs')}`;
593
+ }
594
+ return ips;
694
595
  }
695
-
696
596
  /**
697
597
  * Saves the settings to the server.
698
- * @param {boolean} isClose True if the user is closing the dialog.
598
+ * @param isClose True if the user is closing the dialog.
699
599
  */
700
- }, {
701
- key: "onSave",
702
- value: function onSave(isClose) {
703
- var _this8 = this;
704
- var oldObj;
705
- if (this.state.isConfigurationError) {
706
- this.setState({
707
- errorText: this.state.isConfigurationError
708
- });
709
- return;
710
- }
711
- this.socket.getObject(this.instanceId).then(function (_oldObj) {
712
- oldObj = _oldObj || {};
713
- for (var a in _this8.state["native"]) {
714
- if (Object.prototype.hasOwnProperty.call(_this8.state["native"], a)) {
715
- if (_this8.state["native"][a] === null) {
716
- oldObj["native"][a] = null;
717
- } else if (_this8.state["native"][a] !== undefined) {
718
- oldObj["native"][a] = JSON.parse(JSON.stringify(_this8.state["native"][a]));
719
- } else {
720
- delete oldObj["native"][a];
721
- }
722
- }
600
+ onSave(isClose) {
601
+ let oldObj;
602
+ if (this.state.isConfigurationError) {
603
+ this.setState({ errorText: this.state.isConfigurationError });
604
+ return;
723
605
  }
724
- if (_this8.state.common) {
725
- for (var b in _this8.state.common) {
726
- if (_this8.state.common[b] === null) {
727
- oldObj.common[b] = null;
728
- } else if (_this8.state.common[b] !== undefined) {
729
- oldObj.common[b] = JSON.parse(JSON.stringify(_this8.state.common[b]));
730
- } else {
731
- delete oldObj.common[b];
606
+ this.socket.getObject(this.instanceId)
607
+ .then(_oldObj => {
608
+ oldObj = (_oldObj || {});
609
+ for (const a in this.state.native) {
610
+ if (Object.prototype.hasOwnProperty.call(this.state.native, a)) {
611
+ if (this.state.native[a] === null) {
612
+ oldObj.native[a] = null;
613
+ }
614
+ else if (this.state.native[a] !== undefined) {
615
+ oldObj.native[a] = JSON.parse(JSON.stringify(this.state.native[a]));
616
+ }
617
+ else {
618
+ delete oldObj.native[a];
619
+ }
620
+ }
732
621
  }
733
- }
734
- }
735
- if (_this8.onPrepareSave(oldObj["native"]) !== false) {
736
- return _this8.socket.setObject(_this8.instanceId, oldObj);
737
- }
738
- return Promise.reject(new Error('Invalid configuration'));
739
- }).then(function () {
740
- _this8.savedNative = oldObj["native"];
741
- globalThis.changed = false;
742
- try {
743
- window.parent.postMessage('nochange', '*');
744
- } catch (e) {
745
- // ignore
746
- }
747
- _this8.setState({
748
- changed: false
749
- });
750
- isClose && GenericApp.onClose();
751
- })["catch"](function (e) {
752
- return console.error("Cannot save configuration: ".concat(e));
753
- });
622
+ if (this.state.common) {
623
+ for (const b in this.state.common) {
624
+ if (this.state.common[b] === null) {
625
+ oldObj.common[b] = null;
626
+ }
627
+ else if (this.state.common[b] !== undefined) {
628
+ oldObj.common[b] = JSON.parse(JSON.stringify(this.state.common[b]));
629
+ }
630
+ else {
631
+ delete oldObj.common[b];
632
+ }
633
+ }
634
+ }
635
+ if (this.onPrepareSave(oldObj.native) !== false) {
636
+ return this.socket.setObject(this.instanceId, oldObj);
637
+ }
638
+ return Promise.reject(new Error('Invalid configuration'));
639
+ })
640
+ .then(() => {
641
+ this.savedNative = oldObj.native;
642
+ globalThis.changed = false;
643
+ try {
644
+ window.parent.postMessage('nochange', '*');
645
+ }
646
+ catch (e) {
647
+ // ignore
648
+ }
649
+ this.setState({ changed: false });
650
+ isClose && GenericApp.onClose();
651
+ })
652
+ .catch(e => console.error(`Cannot save configuration: ${e}`));
754
653
  }
755
-
756
654
  /**
757
655
  * Renders the toast.
758
- * @returns {JSX.Element | null} The JSX element.
759
656
  */
760
- }, {
761
- key: "renderToast",
762
- value: function renderToast() {
763
- var _this9 = this;
764
- if (!this.state.toast) {
765
- return null;
766
- }
767
- return /*#__PURE__*/_react["default"].createElement(_material.Snackbar, {
768
- anchorOrigin: {
769
- vertical: 'bottom',
770
- horizontal: 'left'
771
- },
772
- open: !0,
773
- autoHideDuration: 6000,
774
- onClose: function onClose() {
775
- return _this9.setState({
776
- toast: ''
777
- });
778
- },
779
- ContentProps: {
780
- 'aria-describedby': 'message-id'
781
- },
782
- message: /*#__PURE__*/_react["default"].createElement("span", {
783
- id: "message-id"
784
- }, this.state.toast),
785
- action: [/*#__PURE__*/_react["default"].createElement(_material.IconButton, {
786
- key: "close",
787
- "aria-label": "Close",
788
- color: "inherit",
789
- className: this.props.classes.close,
790
- onClick: function onClick() {
791
- return _this9.setState({
792
- toast: ''
793
- });
794
- },
795
- size: "large"
796
- }, /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Close, null))]
797
- });
657
+ renderToast() {
658
+ var _a;
659
+ if (!this.state.toast) {
660
+ return null;
661
+ }
662
+ return react_1.default.createElement(material_1.Snackbar, { anchorOrigin: {
663
+ vertical: 'bottom',
664
+ horizontal: 'left',
665
+ }, open: !0, autoHideDuration: 6000, onClose: () => this.setState({ toast: '' }), ContentProps: { 'aria-describedby': 'message-id' }, message: react_1.default.createElement("span", { id: "message-id" }, this.state.toast), action: [
666
+ react_1.default.createElement(material_1.IconButton, { key: "close", "aria-label": "Close", color: "inherit", className: (_a = this.props.classes) === null || _a === void 0 ? void 0 : _a.close, onClick: () => this.setState({ toast: '' }), size: "large" },
667
+ react_1.default.createElement(icons_material_1.Close, null)),
668
+ ] });
798
669
  }
799
-
800
670
  /**
801
671
  * Closes the dialog.
802
672
  * @private
803
673
  */
804
- }, {
805
- key: "renderError",
806
- value:
674
+ static onClose() {
675
+ if (typeof window.parent !== 'undefined' && window.parent) {
676
+ try {
677
+ // @ts-expect-error No idea how to solve it
678
+ if (window.parent.$iframeDialog && typeof window.parent.$iframeDialog.close === 'function') {
679
+ // @ts-expect-error No idea how to solve it
680
+ window.parent.$iframeDialog.close();
681
+ }
682
+ else {
683
+ window.parent.postMessage('close', '*');
684
+ }
685
+ }
686
+ catch (e) {
687
+ window.parent.postMessage('close', '*');
688
+ }
689
+ }
690
+ }
807
691
  /**
808
692
  * Renders the error dialog.
809
693
  * @returns {JSX.Element | null} The JSX element.
810
694
  */
811
- function renderError() {
812
- var _this10 = this;
813
- if (!this.state.errorText) {
814
- return null;
815
- }
816
- return /*#__PURE__*/_react["default"].createElement(_Error["default"], {
817
- text: this.state.errorText,
818
- onClose: function onClose() {
819
- return _this10.setState({
820
- errorText: ''
821
- });
695
+ renderError() {
696
+ if (!this.state.errorText) {
697
+ return null;
822
698
  }
823
- });
699
+ return react_1.default.createElement(Error_1.default, { text: this.state.errorText, onClose: () => this.setState({ errorText: '' }) });
824
700
  }
825
-
826
701
  /**
827
702
  * Checks if the configuration has changed.
828
703
  * @param {Record<string, any>} [native] the new state
829
704
  */
830
- }, {
831
- key: "getIsChanged",
832
- value: function getIsChanged(_native) {
833
- _native = _native || this.state["native"];
834
- var isChanged = JSON.stringify(_native) !== JSON.stringify(this.savedNative);
835
- globalThis.changed = isChanged;
836
- return isChanged;
705
+ getIsChanged(native) {
706
+ native = native || this.state.native;
707
+ const isChanged = JSON.stringify(native) !== JSON.stringify(this.savedNative);
708
+ globalThis.changed = isChanged;
709
+ return isChanged;
837
710
  }
838
-
839
711
  /**
840
712
  * Gets called when loading the configuration.
841
- * @param {Record<string, any>} newNative The new configuration object.
713
+ * @param newNative The new configuration object.
842
714
  */
843
- }, {
844
- key: "onLoadConfig",
845
- value: function onLoadConfig(newNative) {
846
- if (JSON.stringify(newNative) !== JSON.stringify(this.state["native"])) {
847
- this.setState({
848
- "native": newNative,
849
- changed: this.getIsChanged(newNative)
850
- });
851
- }
715
+ onLoadConfig(newNative) {
716
+ if (JSON.stringify(newNative) !== JSON.stringify(this.state.native)) {
717
+ this.setState({ native: newNative, changed: this.getIsChanged(newNative) });
718
+ }
852
719
  }
853
-
854
720
  /**
855
721
  * Sets the configuration error.
856
- * @param {string} errorText
857
722
  */
858
- }, {
859
- key: "setConfigurationError",
860
- value: function setConfigurationError(errorText) {
861
- if (this.state.isConfigurationError !== errorText) {
862
- this.setState({
863
- isConfigurationError: errorText
864
- });
865
- }
723
+ setConfigurationError(errorText) {
724
+ if (this.state.isConfigurationError !== errorText) {
725
+ this.setState({ isConfigurationError: errorText });
726
+ }
866
727
  }
867
-
868
728
  /**
869
729
  * Renders the save and close buttons.
870
730
  * @returns {JSX.Element | undefined} The JSX element.
871
731
  */
872
- }, {
873
- key: "renderSaveCloseButtons",
874
- value: function renderSaveCloseButtons() {
875
- var _this11 = this;
876
- if (!this.state.confirmClose && !this.state.bottomButtons) {
877
- return null;
878
- }
879
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.state.bottomButtons ? /*#__PURE__*/_react["default"].createElement(_SaveCloseButtons["default"], {
880
- theme: this.state.theme,
881
- newReact: this.newReact,
882
- noTextOnButtons: this.state.width === 'xs' || this.state.width === 'sm' || this.state.width === 'md',
883
- changed: this.state.changed,
884
- onSave: function onSave(isClose) {
885
- return _this11.onSave(isClose);
886
- },
887
- onClose: function onClose() {
888
- if (_this11.state.changed) {
889
- _this11.setState({
890
- confirmClose: true
891
- });
892
- } else {
893
- GenericApp.onClose();
894
- }
732
+ renderSaveCloseButtons() {
733
+ if (!this.state.confirmClose && !this.state.bottomButtons) {
734
+ return null;
895
735
  }
896
- }) : null, this.state.confirmClose ? /*#__PURE__*/_react["default"].createElement(_Confirm["default"], {
897
- title: _i18n["default"].t('ra_Please confirm'),
898
- text: _i18n["default"].t('ra_Some data are not stored. Discard?'),
899
- ok: _i18n["default"].t('ra_Discard'),
900
- cancel: _i18n["default"].t('ra_Cancel'),
901
- onClose: function onClose(isYes) {
902
- return _this11.setState({
903
- confirmClose: false
904
- }, function () {
905
- return isYes && GenericApp.onClose();
906
- });
907
- }
908
- }) : null);
736
+ return react_1.default.createElement(react_1.default.Fragment, null,
737
+ this.state.bottomButtons ? react_1.default.createElement(SaveCloseButtons_1.default, { theme: this.state.theme, newReact: this.newReact, noTextOnButtons: this.state.width === 'xs' || this.state.width === 'sm' || this.state.width === 'md', changed: this.state.changed, onSave: isClose => this.onSave(isClose), onClose: () => {
738
+ if (this.state.changed) {
739
+ this.setState({ confirmClose: true });
740
+ }
741
+ else {
742
+ GenericApp.onClose();
743
+ }
744
+ } }) : null,
745
+ this.state.confirmClose ? react_1.default.createElement(Confirm_1.default, { title: i18n_1.default.t('ra_Please confirm'), text: i18n_1.default.t('ra_Some data are not stored. Discard?'), ok: i18n_1.default.t('ra_Discard'), cancel: i18n_1.default.t('ra_Cancel'), onClose: isYes => this.setState({ confirmClose: false }, () => isYes && GenericApp.onClose()) }) : null);
909
746
  }
910
-
911
747
  /**
912
748
  * @private
913
- * @param {Record<string, any>} obj
914
- * @param {any} attrs
915
- * @param {any} value
916
- * @returns {boolean | undefined}
917
749
  */
918
- }, {
919
- key: "_updateNativeValue",
920
- value: function _updateNativeValue(obj, attrs, value) {
921
- if ((0, _typeof2["default"])(attrs) !== 'object') {
922
- attrs = attrs.split('.');
923
- }
924
- var attr = attrs.shift();
925
- if (!attrs.length) {
926
- if (value && (0, _typeof2["default"])(value) === 'object') {
927
- if (JSON.stringify(obj[attr]) !== JSON.stringify(value)) {
928
- obj[attr] = value;
929
- return true;
930
- }
931
- return false;
750
+ _updateNativeValue(obj, attrs, value) {
751
+ if (typeof attrs !== 'object') {
752
+ attrs = attrs.split('.');
932
753
  }
933
- if (obj[attr] !== value) {
934
- obj[attr] = value;
935
- return true;
754
+ const attr = attrs.shift() || '';
755
+ if (!attrs.length) {
756
+ if (value && typeof value === 'object') {
757
+ if (JSON.stringify(obj[attr]) !== JSON.stringify(value)) {
758
+ obj[attr] = value;
759
+ return true;
760
+ }
761
+ return false;
762
+ }
763
+ if (obj[attr] !== value) {
764
+ obj[attr] = value;
765
+ return true;
766
+ }
767
+ return false;
768
+ }
769
+ obj[attr] = obj[attr] || {};
770
+ if (typeof obj[attr] !== 'object') {
771
+ throw new Error(`attribute ${attr} is no object, but ${typeof obj[attr]}`);
936
772
  }
937
- return false;
938
- }
939
- obj[attr] = obj[attr] || {};
940
- if ((0, _typeof2["default"])(obj[attr]) !== 'object') {
941
- throw new Error("attribute ".concat(attr, " is no object, but ").concat((0, _typeof2["default"])(obj[attr])));
942
- }
943
- return this._updateNativeValue(obj[attr], attrs, value);
773
+ return this._updateNativeValue(obj[attr], attrs, value);
944
774
  }
945
-
946
775
  /**
947
776
  * Update the native value
948
- * @param {string} attr The attribute name with dots as delimiter.
949
- * @param {any} value The new value.
950
- * @param {(() => void)} [cb] Callback which will be called upon completion.
951
- */
952
- }, {
953
- key: "updateNativeValue",
954
- value: function updateNativeValue(attr, value, cb) {
955
- var _native2 = JSON.parse(JSON.stringify(this.state["native"]));
956
- if (this._updateNativeValue(_native2, attr, value)) {
957
- var changed = this.getIsChanged(_native2);
958
- if (changed !== this.state.changed) {
959
- try {
960
- window.parent.postMessage(changed ? 'change' : 'nochange', '*');
961
- } catch (e) {
962
- // ignore
963
- }
777
+ * @param attr The attribute name with dots as delimiter.
778
+ * @param value The new value.
779
+ * @param cb Callback which will be called upon completion.
780
+ */
781
+ updateNativeValue(attr, value, cb) {
782
+ const native = JSON.parse(JSON.stringify(this.state.native));
783
+ if (this._updateNativeValue(native, attr, value)) {
784
+ const changed = this.getIsChanged(native);
785
+ if (changed !== this.state.changed) {
786
+ try {
787
+ window.parent.postMessage(changed ? 'change' : 'nochange', '*');
788
+ }
789
+ catch (e) {
790
+ // ignore
791
+ }
792
+ }
793
+ this.setState({ native, changed }, cb);
964
794
  }
965
- this.setState({
966
- "native": _native2,
967
- changed: changed
968
- }, cb);
969
- }
970
795
  }
971
-
972
796
  /**
973
797
  * Set the error text to be shown.
974
- * @param {string | JSX.Element} text
975
798
  */
976
- }, {
977
- key: "showError",
978
- value: function showError(text) {
979
- this.setState({
980
- errorText: text
981
- });
799
+ showError(text) {
800
+ this.setState({ errorText: text });
982
801
  }
983
-
984
802
  /**
985
803
  * Sets the toast to be shown.
986
804
  * @param {string} toast
987
805
  */
988
- }, {
989
- key: "showToast",
990
- value: function showToast(toast) {
991
- this.setState({
992
- toast: toast
993
- });
806
+ showToast(toast) {
807
+ this.setState({ toast });
994
808
  }
995
-
996
809
  /**
997
810
  * Renders helper dialogs
998
811
  * @returns {JSX.Element} The JSX element.
999
812
  */
1000
- }, {
1001
- key: "renderHelperDialogs",
1002
- value: function renderHelperDialogs() {
1003
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderError(), this.renderToast(), this.renderSaveCloseButtons(), this.renderAlertSnackbar());
813
+ renderHelperDialogs() {
814
+ return react_1.default.createElement(react_1.default.Fragment, null,
815
+ this.renderError(),
816
+ this.renderToast(),
817
+ this.renderSaveCloseButtons(),
818
+ this.renderAlertSnackbar());
1004
819
  }
1005
-
1006
820
  /**
1007
821
  * Renders this component.
1008
822
  * @returns {JSX.Element} The JSX element.
1009
823
  */
1010
- }, {
1011
- key: "render",
1012
- value: function render() {
1013
- if (!this.state.loaded) {
1014
- return /*#__PURE__*/_react["default"].createElement(_Loader["default"], {
1015
- theme: this.state.themeType
1016
- });
1017
- }
1018
- return /*#__PURE__*/_react["default"].createElement("div", {
1019
- className: "App"
1020
- }, this.renderError(), this.renderToast(), this.renderSaveCloseButtons(), this.renderAlertSnackbar());
1021
- }
1022
- }], [{
1023
- key: "getWidth",
1024
- value:
1025
- /**
1026
- * Gets the width depending on the window inner width.
1027
- * @returns {import('./types').Width}
1028
- */
1029
- function getWidth() {
1030
- /**
1031
- * innerWidth |xs sm md lg xl
1032
- * |-------|-------|-------|-------|------>
1033
- * width | xs | sm | md | lg | xl
1034
- */
1035
-
1036
- var SIZES = {
1037
- xs: 0,
1038
- sm: 600,
1039
- md: 960,
1040
- lg: 1280,
1041
- xl: 1920
1042
- };
1043
- var width = window.innerWidth;
1044
- var keys = Object.keys(SIZES).reverse();
1045
- var widthComputed = keys.find(function (key) {
1046
- return width >= SIZES[key];
1047
- });
1048
- return widthComputed || 'xs';
1049
- }
1050
- }, {
1051
- key: "onClose",
1052
- value: function onClose() {
1053
- if (typeof window.parent !== 'undefined' && window.parent) {
1054
- try {
1055
- if (window.parent.$iframeDialog && typeof window.parent.$iframeDialog.close === 'function') {
1056
- window.parent.$iframeDialog.close();
1057
- } else {
1058
- window.parent.postMessage('close', '*');
1059
- }
1060
- } catch (e) {
1061
- window.parent.postMessage('close', '*');
824
+ render() {
825
+ if (!this.state.loaded) {
826
+ return react_1.default.createElement(Loader_1.default, { themeType: this.state.themeType });
1062
827
  }
1063
- }
828
+ return react_1.default.createElement("div", { className: "App" },
829
+ this.renderError(),
830
+ this.renderToast(),
831
+ this.renderSaveCloseButtons(),
832
+ this.renderAlertSnackbar());
1064
833
  }
1065
- }]);
1066
- return GenericApp;
1067
- }(_Router2["default"]);
1068
- GenericApp.propTypes = {
1069
- adapterName: _propTypes["default"].string,
1070
- // (optional) name of adapter
1071
- onThemeChange: _propTypes["default"].func,
1072
- // (optional) called by theme change
1073
- socket: _propTypes["default"].object,
1074
- // (optional) socket information (host, port)
1075
- encryptedFields: _propTypes["default"].array,
1076
- // (optional) list of native attributes that must be encrypted
1077
- bottomButtons: _propTypes["default"].bool,
1078
- // If the bottom buttons (Save/Close) must be shown
1079
- Connection: _propTypes["default"].object // If the bottom buttons (Save/Close) must be shown
1080
- };
1081
- var _default = exports["default"] = GenericApp;
1082
- //# sourceMappingURL=GenericApp.js.map
834
+ }
835
+ exports.default = GenericApp;