@iobroker/adapter-react-v5 4.9.1 → 4.9.2

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.
@@ -1,4 +1,25 @@
1
- export default Utils;
1
+ /**
2
+ * Copyright 2018-2023 Denis Haev <dogafox@gmail.com>
3
+ *
4
+ * MIT License
5
+ *
6
+ **/
7
+ import React from 'react';
8
+ interface GetObjectNameOptions {
9
+ name?: ioBroker.StringOrTranslated;
10
+ language?: ioBroker.Languages;
11
+ }
12
+ type SmartName = null | (ioBroker.StringOrTranslated & {
13
+ /** Which kind of device it is */
14
+ smartType?: string | null;
15
+ /** Which value to set when the ON command is issued */
16
+ byOn?: string | null;
17
+ });
18
+ declare namespace clsx {
19
+ type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
20
+ type ClassDictionary = Record<string, any>;
21
+ type ClassArray = ClassValue[];
22
+ }
2
23
  declare class Utils {
3
24
  static namespace: string;
4
25
  static INSTANCES: string;
@@ -6,280 +27,202 @@ declare class Utils {
6
27
  static FORBIDDEN_CHARS: RegExp;
7
28
  /**
8
29
  * Capitalize words.
9
- * @param {string | undefined} name
10
- * @returns {string}
11
30
  */
12
- static CapitalWords(name: string | undefined): string;
13
- static formatSeconds(seconds: any): string;
31
+ static CapitalWords(name: string): string;
32
+ static formatSeconds(seconds: number): string;
14
33
  /**
15
34
  * Get the name of the object by id from the name or description.
16
- * @param {Record<string, ioBroker.Object>} objects
17
- * @param {string} id
18
- * @param {{ name: any; } | ioBroker.Languages | null} settings
19
- * @param {{ language?: ioBroker.Languages; }} options
20
- * @param {boolean} [isDesc] Set to true to get the description.
21
- * @returns {string}
35
+ * @param objects
36
+ * @param id
37
+ * @param settings
38
+ * @param options
39
+ * @param isDesc Set to true to get the description.
22
40
  */
23
- static getObjectName(objects: Record<string, ioBroker.Object>, id: string, settings: {
24
- name: any;
25
- } | ioBroker.Languages | null, options: {
26
- language?: ioBroker.Languages;
27
- }, isDesc?: boolean): string;
41
+ static getObjectName(objects: Record<string, ioBroker.Object>, id: string, settings?: GetObjectNameOptions | ioBroker.Languages | null, options?: GetObjectNameOptions, isDesc?: boolean): string;
28
42
  /**
29
43
  * Get the name of the object from the name or description.
30
- * @param {ioBroker.PartialObject} obj
31
- * @param {{ name: any; } | ioBroker.Languages | null } settings or language
32
- * @param {{ language?: ioBroker.Languages; } } options
33
- * @param {boolean} [isDesc] Set to true to get the description.
34
- * @param {boolean} [noTrim] Allow to use spaces in name (by edit)
35
- * @returns {string}
44
+ * @param obj
45
+ * @param settings or language
46
+ * @param options
47
+ * @param isDesc Set to true to get the description.
48
+ * @param noTrim Allow to use spaces in name (by edit)
36
49
  */
37
- static getObjectNameFromObj(obj: ioBroker.PartialObject, settings: {
38
- name: any;
39
- } | ioBroker.Languages | null, options: {
40
- language?: ioBroker.Languages;
41
- }, isDesc?: boolean, noTrim?: boolean): string;
50
+ static getObjectNameFromObj(obj: ioBroker.Object, settings?: GetObjectNameOptions | ioBroker.Languages | null, options?: GetObjectNameOptions, isDesc?: boolean, noTrim?: boolean): string;
42
51
  /**
43
- * @param {ioBroker.PartialObject | ioBroker.ObjectCommon} obj
44
- * @param {string} forEnumId
45
- * @param {{ user: string; }} options
46
- * @returns {string | null}
52
+ * Extracts from the object material settings, depends on username
47
53
  */
48
- static getSettingsOrder(obj: ioBroker.PartialObject | ioBroker.ObjectCommon, forEnumId: string, options: {
54
+ static getSettingsOrder(obj: ioBroker.StateObject | ioBroker.StateCommon, forEnumId: string, options: {
49
55
  user: string;
50
56
  }): string | null;
51
57
  /**
52
- * @param {ioBroker.PartialObject | ioBroker.ObjectCommon} obj
53
- * @param {string} forEnumId
54
- * @param {{ user: string; }} options
58
+ Used in material
55
59
  */
56
- static getSettingsCustomURLs(obj: ioBroker.PartialObject | ioBroker.ObjectCommon, forEnumId: string, options: {
60
+ static getSettingsCustomURLs(obj: ioBroker.StateObject | ioBroker.StateCommon, forEnumId: string, options: {
57
61
  user: string;
58
- }): any;
62
+ }): string | null;
59
63
  /**
60
64
  * Reorder the array items in list between source and dest.
61
- * @param {Iterable<any> | ArrayLike<any>} list
62
- * @param {number} source
63
- * @param {number} dest
64
- */
65
- static reorder(list: Iterable<any> | ArrayLike<any>, source: number, dest: number): any[];
66
- /**
67
- * @param {any} obj
68
- * @param {{ id: any; user: any; name: any; icon: any; color: any; language: ioBroker.Languages; }} options
69
- * @param {boolean} [defaultEnabling]
70
- */
71
- static getSettings(obj: any, options: {
72
- id: any;
73
- user: any;
74
- name: any;
75
- icon: any;
76
- color: any;
77
- language: ioBroker.Languages;
65
+ */
66
+ static reorder(list: Iterable<any> | ArrayLike<any>, source: number, dest: number): Iterable<any> | ArrayLike<any>;
67
+ /**
68
+ Get smart name settings for the given object.
69
+ */
70
+ static getSettings(obj: ioBroker.StateObject | ioBroker.StateCommon, options: {
71
+ id?: string;
72
+ user?: string;
73
+ name?: ioBroker.StringOrTranslated;
74
+ icon?: string;
75
+ color?: string;
76
+ language?: ioBroker.Languages;
78
77
  }, defaultEnabling?: boolean): any;
79
78
  /**
80
- * @param {any} obj
81
- * @param {any} settings
82
- * @param {{ user: any; language: ioBroker.Languages; }} options
79
+ Sets smartName settings for the given object.
83
80
  */
84
- static setSettings(obj: any, settings: any, options: {
85
- user: any;
86
- language: ioBroker.Languages;
81
+ static setSettings(obj: ioBroker.StateObject, settings: any, options: {
82
+ user?: string;
83
+ language?: ioBroker.Languages;
87
84
  }): boolean;
88
85
  /**
89
86
  * Get the icon for the given settings.
90
- * @param {{ icon: string | undefined; name: string | undefined; prefix: string | undefined}} settings
91
- * @param {any} style
92
- * @returns {JSX.Element | null}
93
87
  */
94
88
  static getIcon(settings: {
95
- icon: string | undefined;
96
- name: string | undefined;
97
- prefix: string | undefined;
98
- }, style: any): JSX.Element | null;
89
+ icon?: string;
90
+ name?: string;
91
+ prefix?: string;
92
+ }, style?: React.CSSProperties): React.JSX.Element | null;
99
93
  /**
100
94
  * Get the icon for the given object.
101
- * @param {string} id
102
- * @param {{ common: { icon: any; }; }} obj
103
- * @returns {string | null}
104
- */
105
- static getObjectIcon(id: string, obj: {
106
- common: {
107
- icon: any;
108
- };
109
- }): string | null;
95
+ */
96
+ static getObjectIcon(id: string | ioBroker.PartialObject, obj?: ioBroker.PartialObject): string | null;
110
97
  /**
111
98
  * Splits CamelCase into words.
112
- * @param {string | undefined} text
113
- * @returns {string}
114
99
  */
115
100
  static splitCamelCase(text: string | undefined): string;
116
101
  /**
117
102
  * Check if the given color is bright.
118
103
  * https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
119
- * @param {string | null | undefined} color
120
- * @param {boolean} [defaultValue]
121
- * @returns {boolean}
122
104
  */
123
105
  static isUseBright(color: string | null | undefined, defaultValue?: boolean): boolean;
124
106
  /**
125
107
  * Get the time string in the format 00:00.
126
- * @param {string | number} seconds
127
108
  */
128
109
  static getTimeString(seconds: string | number): string;
129
110
  /**
130
111
  * Gets the wind direction with the given angle (degrees).
131
- * @param {number} angle in degrees.
132
- * @returns {string | undefined}
112
+ * @param angle in degrees.
133
113
  */
134
- static getWindDirection(angle: number): string | undefined;
114
+ static getWindDirection(angle: number): string;
135
115
  /**
136
- * Pad the given number with a zero if it's not 2 digits long.
137
- * @param {string | number} num
116
+ * Pad the given number with a zero if it's not two digits long.
138
117
  */
139
- static padding(num: string | number): string | number;
118
+ static padding(num: string | number): string;
140
119
  /**
141
120
  * Sets the date format.
142
- * @param {string} format
143
121
  */
144
122
  static setDataFormat(format: string): void;
145
123
  /**
146
124
  * Converts the date to a string.
147
- * @param {string | number | Date} now
148
- * @returns {string}
149
125
  */
150
126
  static date2string(now: string | number | Date): string;
151
127
  /**
152
128
  * Render a text as a link.
153
- * @param {string} text
154
- * @returns {string | JSX.Element[]}
155
129
  */
156
- static renderTextWithA(text: string): string | JSX.Element[];
130
+ static renderTextWithA(text: string): React.JSX.Element[] | string;
157
131
  /**
158
132
  * Get the smart name of the given state.
159
- * @param {Record<string, ioBroker.StateObject> | ioBroker.StateObject} states
160
- * @param {string} id
161
- * @param {string} instanceId
162
- * @param {boolean} [noCommon]
163
133
  */
164
- static getSmartName(states: Record<string, ioBroker.StateObject> | ioBroker.StateObject, id: string, instanceId: string, noCommon?: boolean): any;
134
+ static getSmartName(states: Record<string, ioBroker.StateObject> | ioBroker.StateObject | ioBroker.StateCommon, id: string, instanceId: string, noCommon?: boolean): SmartName | undefined;
165
135
  /**
166
136
  * Get the smart name from a state.
167
- * @param {ioBroker.StateObject} obj
168
- * @param {string} instanceId
169
- * @param {boolean} [noCommon]
170
137
  */
171
- static getSmartNameFromObj(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): any;
138
+ static getSmartNameFromObj(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): SmartName | undefined;
172
139
  /**
173
140
  * Enable smart name for a state.
174
- * @param {ioBroker.StateObject} obj
175
- * @param {string} instanceId
176
- * @param {boolean} [noCommon]
177
141
  */
178
142
  static enableSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void;
179
143
  /**
180
144
  * Completely remove smart name from a state.
181
- * @param {ioBroker.StateObject} obj
182
- * @param {string | number} instanceId
183
- * @param {boolean} [noCommon]
184
145
  */
185
- static removeSmartName(obj: ioBroker.StateObject, instanceId: string | number, noCommon?: boolean): void;
146
+ static removeSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void;
186
147
  /**
187
148
  * Update the smartname of a state.
188
- * @param {ioBroker.StateObject} obj
189
- * @param {string} newSmartName
190
- * @param {string | undefined} byON
191
- * @param {string | undefined} smartType
192
- * @param {string} instanceId
193
- * @param {boolean} [noCommon]
194
149
  */
195
- static updateSmartName(obj: ioBroker.StateObject, newSmartName: string, byON: string | undefined, smartType: string | undefined, instanceId: string, noCommon?: boolean): void;
150
+ static updateSmartName(obj: ioBroker.StateObject, newSmartName: ioBroker.StringOrTranslated, byON: string | null, smartType: string | null, instanceId: string, noCommon?: boolean): void;
196
151
  /**
197
152
  * Disable the smart name of a state.
198
- * @param {ioBroker.StateObject} obj
199
- * @param {string} instanceId
200
- * @param {boolean} [noCommon]
201
153
  */
202
154
  static disableSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void;
203
155
  /**
204
156
  * Copy text to the clipboard.
205
- * @param {string} text
206
- * @param {Event} [e]
207
157
  */
208
- static copyToClipboard(text: string, e?: Event): boolean;
158
+ static copyToClipboard(text: string, e: Event): boolean;
209
159
  /**
210
160
  * Gets the extension of a file name.
211
- * @param {string | null} [fileName] the file name.
212
- * @returns {string | null} The extension in lower case.
161
+ * @param fileName the file name.
162
+ * @returns The extension in lower case.
213
163
  */
214
- static getFileExtension(fileName?: string | null): string | null;
164
+ static getFileExtension(fileName: string): string | null;
215
165
  /**
216
166
  * Format number of bytes as a string with B, KB, MB or GB.
217
167
  * The base for all calculations is 1024.
218
- * @param {number} bytes The number of bytes.
219
- * @returns {string} The formatted string (e.g. '723.5 KB')
168
+ * @param bytes The number of bytes.
169
+ * @returns The formatted string (e.g. '723.5 KB')
220
170
  */
221
171
  static formatBytes(bytes: number): string;
222
172
  /**
223
173
  * Invert the given color according to a theme type to get the inverted text color for background
224
- * @param {string} color Color in the format '#rrggbb' or '#rgb' (or without a hash)
225
- * @param {string} themeType theme type
226
- * @param {string} invert dark theme has light color in control or light theme has light color in control
227
- * @returns {string | undefined}
174
+ * @param color Color in the format '#rrggbb' or '#rgb' (or without a hash)
175
+ * @param themeType theme type
176
+ * @param invert dark theme has light color in control or light theme has light color in control
228
177
  */
229
- static getInvertedColor(color: string, themeType: string, invert: string): string | undefined;
178
+ static getInvertedColor(color: string, themeType?: string, invert?: boolean): string | undefined;
230
179
  /**
231
180
  * Invert the given color
232
- * @param {string} hex Color in the format '#rrggbb' or '#rgb' (or without hash)
233
- * @param {boolean} bw Set to black or white.
234
- * @returns {string}
181
+ * @param hex Color in the format '#rrggbb' or '#rgb' (or without hash)
182
+ * @param bw Set to black or white.
235
183
  */
236
- static invertColor(hex: string, bw: boolean): string;
184
+ static invertColor(hex: string, bw?: boolean): string;
237
185
  /**
238
186
  * Convert RGB to array [r, g, b]
239
- * @param {string} hex Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
240
- * @returns {Array<number>} Array with 3 elements [r, g, b]
187
+ * @param hex Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
188
+ * @returns Array with 3 elements [r, g, b]
241
189
  */
242
- static color2rgb(hex: string): Array<number>;
190
+ static color2rgb(hex: string): false | [number, number, number] | '';
243
191
  /**
244
192
  * Convert RGB to LAB
245
193
  * @param {Array<number>} rgb color in format [r,g,b]
246
194
  * @returns {Array<number>} lab color in format [l,a,b]
247
195
  */
248
- static rgb2lab(rgb: Array<number>): Array<number>;
196
+ static rgb2lab(rgb: [number, number, number]): [number, number, number];
249
197
  /**
250
198
  * Calculate the distance between two colors in LAB color space in the range 0-100^2
251
199
  * If distance is less than 1000, the colors are similar
252
- * @param {string} color1 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
253
- * @param {string} color2 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
254
- * @returns {number} distance in the range 0-100^2
200
+ * @param color1 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
201
+ * @param color2 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
202
+ * @returns distance in the range 0-100^2
255
203
  */
256
204
  static colorDistance(color1: string, color2: string): number;
257
205
  /**
258
206
  * @private
259
- * @param {any} mix
260
- * @returns {string}
261
207
  */
262
- private static _toVal;
208
+ static _toVal(mix: clsx.ClassValue): string;
263
209
  /**
264
210
  * Convert any object to a string with its values.
265
211
  * @returns {string}
266
212
  */
267
- static clsx(...args: any[]): string;
213
+ static clsx(...inputs: clsx.ClassValue[]): string;
268
214
  /**
269
215
  * Get the current theme name (either from local storage or the browser settings).
270
216
  * @param {string} [themeName]
271
217
  * @returns {string}
272
218
  */
273
- static getThemeName(themeName?: string): string;
219
+ static getThemeName(themeName?: string): any;
274
220
  /**
275
221
  * Get the type of theme.
276
- * @param {string} [themeName]
277
- * @returns {'dark' | 'light'}
278
222
  */
279
223
  static getThemeType(themeName?: string): 'dark' | 'light';
280
224
  /**
281
225
  * Set the theme name and theme type.
282
- * @param {string} themeName
283
226
  */
284
227
  static setThemeName(themeName: string): void;
285
228
  /**
@@ -290,80 +233,72 @@ declare class Utils {
290
233
  static toggleTheme(themeName: string | null): string;
291
234
  /**
292
235
  * Get the list of themes
293
- * @returns {array<string>} list of possible themes
236
+ * @returns list of possible themes
294
237
  */
295
- static getThemeNames(): array<string>;
238
+ static getThemeNames(): string[];
296
239
  /**
297
240
  * Parse a query string into its parts.
298
- * @param {string} query
299
- * @returns {Record<string, string | boolean | number>}
300
241
  */
301
242
  static parseQuery(query: string): Record<string, string | boolean | number>;
302
243
  /**
303
244
  * Returns parent ID.
304
- * @param {string} id
305
- * @returns {string | null} parent ID or null if no parent
245
+ * @returns parent ID or null if no parent
306
246
  */
307
247
  static getParentId(id: string): string | null;
308
- static formatDate(dateObj: any, dateFormat: any): string;
309
- static formatTime(seconds: any): string;
310
- static MDtext2link(text: any): any;
311
- static openLink(url: any, target: any): void;
312
- static MDgetTitle(text: any): any;
313
- static MDextractHeader(text: any): {
314
- header: {};
315
- body: any;
248
+ static formatDate(dateObj: Date, dateFormat: string): string;
249
+ static formatTime(seconds: number): string;
250
+ static MDtext2link(text: string): string;
251
+ static openLink(url: string, target?: string): void;
252
+ static MDgetTitle(text: string): string;
253
+ static MDextractHeader(text: string): {
254
+ header: Record<string, string | boolean | number>;
255
+ body: string;
316
256
  };
317
- static MDremoveDocsify(text: any): any;
257
+ static MDremoveDocsify(text: string): string;
318
258
  /**
319
259
  * Generate the json file on the file for download.
320
- * @param {string} filename file name
321
- * @param {string} json file data
260
+ * @param fileName file name
261
+ * @param json file data
322
262
  * @returns {object} json structure (not stringified)
323
263
  */
324
- static generateFile(filename: string, json: string): object;
264
+ static generateFile(fileName: string, json: string): void;
325
265
  /**
326
266
  * Convert quality code into text
327
267
  * @param {number} quality code
328
268
  * @returns {array<string>} lines that decode quality
329
269
  */
330
- static quality2text(quality: number): array<string>;
270
+ static quality2text(quality: number): string[];
331
271
  /**
332
272
  * Deep copy object
333
- * @param {object} object
334
- * @returns {object}
335
273
  */
336
- static clone(object: object): object;
274
+ static clone(object: any): any;
337
275
  /**
338
276
  * Get states of object
339
- * @param {object} obj
340
- * @returns {object} states as an object in form {"value1": "label1", "value2": "label2"} or null
277
+ * @returns states as an object in form {"value1": "label1", "value2": "label2"} or null
341
278
  */
342
- static getStates(obj: object): object;
279
+ static getStates(obj: ioBroker.StateObject | null | undefined): Record<string, string> | null;
343
280
  /**
344
281
  * Get svg file as text
345
- * @param {string} url URL of SVG file
346
- * @returns {object} Promise with "data:image..."
282
+ * @param url URL of SVG file
283
+ * @returns Promise with "data:image..."
347
284
  */
348
- static getSvg(url: string): object;
285
+ static getSvg(url: string): Promise<string>;
349
286
  /**
350
287
  * Detect file extension by its content
351
288
  * @param {string} base64 Base64 encoded binary file
352
289
  * @returns {string} Detected extension, like 'jpg'
353
290
  */
354
- static detectMimeType(base64: string): string;
291
+ static detectMimeType(base64: string): string | null;
355
292
  /**
356
293
  * Check if configured repository is the stable repository
357
294
  *
358
- * @param {string | string[]} activeRepo current configured repository or multi repository
359
- * @return {boolean}
295
+ * @param activeRepo current configured repository or multi repository
360
296
  */
361
297
  static isStableRepository(activeRepo: string | string[]): boolean;
362
298
  /**
363
- * Check if given string is an integer
299
+ * Check if a given string is an integer
364
300
  *
365
- * @param {string} str string to check
366
- * @return {boolean}
301
+ * @param str string to check
367
302
  */
368
303
  static isStringInteger(str: string): boolean;
369
304
  /**
@@ -372,5 +307,6 @@ declare class Utils {
372
307
  * @param {Date} date
373
308
  * @return {boolean}
374
309
  */
375
- static isValidDate(date: Date): boolean;
310
+ static isValidDate(date: any): boolean;
376
311
  }
312
+ export default Utils;