@iobroker/adapter-react-v5 4.10.4 → 4.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/GenericApp.d.ts CHANGED
@@ -1,98 +1,147 @@
1
- export default GenericApp;
2
1
  /**
3
- * @extends {Router<import('./types').GenericAppProps, import('./types').GenericAppState>}
4
- */
5
- declare class GenericApp extends Router<import("./types").GenericAppProps, import("./types").GenericAppState> {
2
+ * Copyright 2018-2023 Denis Haev (bluefox) <dogafox@gmail.com>
3
+ *
4
+ * MIT License
5
+ *
6
+ **/
7
+ import React from 'react';
8
+ import { Connection, AdminConnection } from '@iobroker/socket-client';
9
+ import { type Theme } from '@mui/material';
10
+ import Router from './Components/Router';
11
+ import LegacyConnection from './LegacyConnection';
12
+ import { ConnectionProps, ThemeName, ThemeType, Width } from './types';
13
+ declare global {
14
+ interface Window {
15
+ io: any;
16
+ SocketClient: any;
17
+ adapterName: string;
18
+ socketUrl: string;
19
+ oldAlert: any;
20
+ changed: boolean;
21
+ }
22
+ }
23
+ interface GenericAppProps {
24
+ /** Adapter instance number if known, else will be determined from url */
25
+ instance?: number;
26
+ /** The name of the adapter. */
27
+ adapterName?: string;
28
+ /** Should the bottom buttons be shown (default: true). */
29
+ bottomButtons?: boolean;
30
+ /** Additional translations. */
31
+ translations?: {
32
+ [lang in ioBroker.Languages]?: Record<string, string>;
33
+ };
34
+ /** Fields that should be encrypted/decrypted. */
35
+ encryptedFields?: string[];
36
+ /** Socket.io configuration. */
37
+ socket?: ConnectionProps;
38
+ /** Desired connection object */
39
+ Connection?: LegacyConnection | Connection | AdminConnection;
40
+ /** sentry DNS */
41
+ sentryDSN?: string;
42
+ onThemeChange?: (newThemeName: ThemeName) => void;
43
+ classes?: Record<string, string>;
44
+ }
45
+ interface GenericAppSettings extends GenericAppProps {
46
+ /** Don't load all objects on start-up. */
47
+ doNotLoadAllObjects?: boolean;
48
+ }
49
+ interface GenericAppState {
50
+ loaded: boolean;
51
+ themeType: ThemeType;
52
+ themeName: ThemeName;
53
+ theme: Theme;
54
+ expertMode: boolean;
55
+ selectedTab: string;
56
+ selectedTabNum: number | undefined;
57
+ native: Record<string, any>;
58
+ errorText: string | React.JSX.Element;
59
+ changed: boolean;
60
+ connected: boolean;
61
+ isConfigurationError: string;
62
+ toast: string | React.JSX.Element;
63
+ bottomButtons: boolean;
64
+ width: Width;
65
+ confirmClose: boolean;
66
+ _alert: boolean;
67
+ _alertType: 'info' | 'warning' | 'error' | 'success';
68
+ _alertMessage: string | React.JSX.Element;
69
+ common?: Record<string, any>;
70
+ }
71
+ declare class GenericApp extends Router<GenericAppProps, GenericAppState> {
72
+ protected socket: AdminConnection;
73
+ protected readonly instance: number;
74
+ protected readonly adapterName: string;
75
+ protected readonly instanceId: string;
76
+ protected readonly newReact: boolean;
77
+ protected encryptedFields: string[];
78
+ protected readonly sentryDSN: string | undefined;
79
+ private alertDialogRendered;
80
+ private _secret;
81
+ protected _systemConfig: Record<string, any> | undefined;
82
+ private savedNative;
83
+ private common;
84
+ private sentryStarted;
85
+ private sentryInited;
86
+ private resizeTimer;
6
87
  /**
7
- * Gets the width depending on the window inner width.
8
- * @returns {import('./types').Width}
88
+ * @param {import('./types').GenericAppProps} props
89
+ * @param {import('./types').GenericAppSettings | undefined} settings
9
90
  */
10
- static getWidth(): import('./types').Width;
91
+ constructor(props: GenericAppProps, settings?: GenericAppSettings);
11
92
  /**
12
- * Closes the dialog.
13
- * @private
93
+ * Checks if this connection is running in a web adapter and not in an admin.
94
+ * @returns True if running in a web adapter or in a socketio adapter.
14
95
  */
15
- private static onClose;
96
+ static isWeb(): boolean;
97
+ showAlert(message: string, type?: 'info' | 'warning' | 'error' | 'success'): void;
98
+ renderAlertSnackbar(): React.JSX.Element;
99
+ onSystemConfigChanged: (id: string, obj: ioBroker.Object | null | undefined) => void;
16
100
  /**
17
- * @param {import('./types').GenericAppProps} props
18
- * @param {import('./types').GenericAppSettings | undefined} settings
101
+ * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
19
102
  */
20
- constructor(props: import('./types').GenericAppProps, settings: import('./types').GenericAppSettings | undefined);
103
+ componentDidMount(): void;
21
104
  /**
22
- * @type {import('@iobroker/socket-client').Connection | import('@iobroker/socket-client').AdminConnection}
105
+ * Called immediately before a component is destroyed.
23
106
  */
24
- socket: import('@iobroker/socket-client').Connection | import('@iobroker/socket-client').AdminConnection;
25
- instance: number;
26
- adapterName: any;
27
- instanceId: string;
28
- newReact: boolean;
29
- state: {
30
- selectedTab: any;
31
- selectedTabNum: number;
32
- native: {};
33
- errorText: string;
34
- changed: boolean;
35
- connected: boolean;
36
- loaded: boolean;
37
- isConfigurationError: string;
38
- expertMode: boolean;
39
- toast: string;
40
- theme: import("./types").Theme;
41
- themeName: string;
42
- themeType: string;
43
- bottomButtons: boolean;
44
- width: import("./types").Width;
45
- confirmClose: boolean;
46
- _alert: boolean;
47
- _alertType: string;
48
- _alertMessage: string;
49
- };
50
- savedNative: {};
51
- encryptedFields: string[];
52
- sentryDSN: any;
53
- alerDialogRendered: boolean;
54
- _secret: any;
55
- _systemConfig: {};
56
- sentryStarted: boolean;
57
- sentryInited: boolean;
58
- common: (ioBroker.StateCommon & Record<string, any>) | (ioBroker.ChannelCommon & Record<string, any>) | (ioBroker.DeviceCommon & Record<string, any>) | (ioBroker.OtherCommon & Record<string, any>) | (ioBroker.EnumCommon & Record<string, any>) | (ioBroker.MetaCommon & Record<string, any>) | (ioBroker.HostCommon & Record<string, any>) | (ioBroker.AdapterCommon & Record<string, any>) | (ioBroker.InstanceCommon & Record<string, any>) | (ioBroker.UserCommon & Record<string, any>) | (ioBroker.GroupCommon & Record<string, any>) | (ioBroker.ScriptCommon & Record<string, any>) | (ioBroker.ChartCommon & Record<string, any>) | (ioBroker.ScheduleCommon & Record<string, any>);
59
- showAlert(message: any, type: any): void;
60
- renderAlertSnackbar(): React.JSX.Element;
61
- onSystemConfigChanged: (id: any, obj: any) => void;
62
- onReceiveMessage: (message: any) => void;
107
+ componentWillUnmount(): void;
108
+ onReceiveMessage: (message: {
109
+ data: string;
110
+ } | null) => void;
63
111
  /**
64
112
  * @private
65
113
  */
66
- private onResize;
67
- resizeTimer: any;
114
+ onResize: () => void;
115
+ /**
116
+ * Gets the width depending on the window inner width.
117
+ * @returns {import('./types').Width}
118
+ */
119
+ static getWidth(): Width;
68
120
  /**
69
121
  * Get a theme
70
- * @param {string} name Theme name
71
- * @returns {import('./types').Theme}
122
+ * @param name Theme name
72
123
  */
73
- createTheme(name?: string): import('./types').Theme;
124
+ createTheme(name?: ThemeName | null | undefined): Theme;
74
125
  /**
75
126
  * Get the theme name
76
- * @param {import('./types').Theme} currentTheme Theme
77
- * @returns {string} Theme name
78
127
  */
79
- getThemeName(currentTheme: import('./types').Theme): string;
128
+ getThemeName(currentTheme: Theme): ThemeName;
80
129
  /**
81
130
  * Get the theme type
82
- * @param {import('./types').Theme} currentTheme Theme
83
- * @returns {string} Theme type
84
131
  */
85
- getThemeType(currentTheme: import('./types').Theme): string;
132
+ getThemeType(currentTheme: Theme): ThemeType;
133
+ onThemeChanged(newThemeName: string): void;
134
+ onToggleExpertMode(expertMode: boolean): void;
86
135
  /**
87
136
  * Changes the current theme
88
- * @param {string} newThemeName Theme name
137
+ * @param newThemeName Theme name
89
138
  **/
90
- toggleTheme(newThemeName: string): void;
139
+ toggleTheme(newThemeName?: ThemeName): void;
91
140
  /**
92
141
  * Gets the system configuration.
93
142
  * @returns {Promise<ioBroker.OtherObject>}
94
143
  */
95
- getSystemConfig(): Promise<ioBroker.OtherObject>;
144
+ getSystemConfig(): Promise<import("@iobroker/socket-client").SystemConfig>;
96
145
  /**
97
146
  * Get current expert mode
98
147
  * @returns {boolean}
@@ -105,126 +154,112 @@ declare class GenericApp extends Router<import("./types").GenericAppProps, impor
105
154
  onConnectionReady(): void;
106
155
  /**
107
156
  * Encrypts a string.
108
- * @param {string} value
109
- * @returns {string}
110
157
  */
111
158
  encrypt(value: string): string;
112
159
  /**
113
160
  * Decrypts a string.
114
- * @param {string} value
115
- * @returns {string}
116
161
  */
117
162
  decrypt(value: string): string;
163
+ /**
164
+ * Gets called when the navigation hash changes.
165
+ * You may override this if needed.
166
+ */
167
+ onHashChanged(): void;
118
168
  /**
119
169
  * Selects the given tab.
120
- * @param {string} tab
121
- * @param {number} [index]
122
170
  */
123
171
  selectTab(tab: string, index?: number): void;
124
172
  /**
125
173
  * Gets called before the settings are saved.
126
174
  * You may override this if needed.
127
- * @param {Record<string, any>} settings
128
175
  */
129
176
  onPrepareSave(settings: Record<string, any>): boolean;
130
177
  /**
131
178
  * Gets called after the settings are loaded.
132
179
  * You may override this if needed.
133
- * @param {Record<string, any>} settings
134
- * @param {string[]} encryptedNative optional list of fields to be decrypted
180
+ * @param encryptedNative optional list of fields to be decrypted
135
181
  */
136
- onPrepareLoad(settings: Record<string, any>, encryptedNative: string[]): void;
182
+ onPrepareLoad(settings: Record<string, any>, encryptedNative?: string[]): void;
137
183
  /**
138
184
  * Gets the extendable instances.
139
185
  * @returns {Promise<any[]>}
140
186
  */
141
- getExtendableInstances(): Promise<any[]>;
187
+ getExtendableInstances(): Promise<ioBroker.InstanceObject[]>;
142
188
  /**
143
189
  * Gets the IP addresses of the given host.
144
- * @param {string} host
145
190
  */
146
- getIpAddresses(host: string): Promise<any>;
191
+ getIpAddresses(host: string): Promise<{
192
+ name: string;
193
+ address: string;
194
+ family: 'ipv4' | 'ipv6';
195
+ }[]>;
147
196
  /**
148
197
  * Saves the settings to the server.
149
- * @param {boolean} isClose True if the user is closing the dialog.
198
+ * @param isClose True if the user is closing the dialog.
150
199
  */
151
- onSave(isClose: boolean): void;
200
+ onSave(isClose?: boolean): void;
152
201
  /**
153
202
  * Renders the toast.
154
- * @returns {JSX.Element | null} The JSX element.
155
203
  */
156
- renderToast(): JSX.Element | null;
204
+ renderToast(): React.JSX.Element;
205
+ /**
206
+ * Closes the dialog.
207
+ * @private
208
+ */
209
+ static onClose(): void;
157
210
  /**
158
211
  * Renders the error dialog.
159
212
  * @returns {JSX.Element | null} The JSX element.
160
213
  */
161
- renderError(): JSX.Element | null;
214
+ renderError(): React.JSX.Element;
162
215
  /**
163
216
  * Checks if the configuration has changed.
164
217
  * @param {Record<string, any>} [native] the new state
165
218
  */
166
- getIsChanged(native?: Record<string, any>): boolean;
219
+ getIsChanged(native: Record<string, any>): boolean;
167
220
  /**
168
221
  * Gets called when loading the configuration.
169
- * @param {Record<string, any>} newNative The new configuration object.
222
+ * @param newNative The new configuration object.
170
223
  */
171
224
  onLoadConfig(newNative: Record<string, any>): void;
172
225
  /**
173
226
  * Sets the configuration error.
174
- * @param {string} errorText
175
227
  */
176
228
  setConfigurationError(errorText: string): void;
177
229
  /**
178
230
  * Renders the save and close buttons.
179
231
  * @returns {JSX.Element | undefined} The JSX element.
180
232
  */
181
- renderSaveCloseButtons(): JSX.Element | undefined;
233
+ renderSaveCloseButtons(): React.JSX.Element;
182
234
  /**
183
235
  * @private
184
- * @param {Record<string, any>} obj
185
- * @param {any} attrs
186
- * @param {any} value
187
- * @returns {boolean | undefined}
188
236
  */
189
- private _updateNativeValue;
237
+ _updateNativeValue(obj: Record<string, any>, attrs: string | string[], value: any): boolean;
190
238
  /**
191
239
  * Update the native value
192
- * @param {string} attr The attribute name with dots as delimiter.
193
- * @param {any} value The new value.
194
- * @param {(() => void)} [cb] Callback which will be called upon completion.
240
+ * @param attr The attribute name with dots as delimiter.
241
+ * @param value The new value.
242
+ * @param cb Callback which will be called upon completion.
195
243
  */
196
- updateNativeValue(attr: string, value: any, cb?: (() => void)): void;
244
+ updateNativeValue(attr: string, value: any, cb: () => void): void;
197
245
  /**
198
246
  * Set the error text to be shown.
199
- * @param {string | JSX.Element} text
200
247
  */
201
- showError(text: string | JSX.Element): void;
248
+ showError(text: string | React.JSX.Element): void;
202
249
  /**
203
250
  * Sets the toast to be shown.
204
251
  * @param {string} toast
205
252
  */
206
- showToast(toast: string): void;
253
+ showToast(toast: string | React.JSX.Element): void;
207
254
  /**
208
255
  * Renders helper dialogs
209
256
  * @returns {JSX.Element} The JSX element.
210
257
  */
211
- renderHelperDialogs(): JSX.Element;
258
+ renderHelperDialogs(): React.JSX.Element;
212
259
  /**
213
260
  * Renders this component.
214
261
  * @returns {JSX.Element} The JSX element.
215
262
  */
216
- render(): JSX.Element;
263
+ render(): React.JSX.Element;
217
264
  }
218
- declare namespace GenericApp {
219
- namespace propTypes {
220
- let adapterName: PropTypes.Requireable<string>;
221
- let onThemeChange: PropTypes.Requireable<(...args: any[]) => any>;
222
- let socket: PropTypes.Requireable<object>;
223
- let encryptedFields: PropTypes.Requireable<any[]>;
224
- let bottomButtons: PropTypes.Requireable<boolean>;
225
- let Connection: PropTypes.Requireable<object>;
226
- }
227
- }
228
- import Router from './Components/Router';
229
- import React from 'react';
230
- import PropTypes from 'prop-types';
265
+ export default GenericApp;