@iobroker/adapter-react-v5
Version:
React components to develop ioBroker interfaces with react.
210 lines (209 loc) • 6.26 kB
TypeScript
/**
* Copyright 2018-2024 Denis Haev (bluefox) <dogafox@gmail.com>
*
* MIT License
*
*/
import React, { type JSX } from 'react';
import { type AdminConnection } from '@iobroker/socket-client';
import { Router } from './Components/Router';
import type { GenericAppProps, GenericAppState, GenericAppSettings, ThemeName, ThemeType, IobTheme, Width } from './types';
declare global {
/** If config has been changed */
var changed: boolean;
interface Window {
io: any;
SocketClient: any;
adapterName: undefined | string;
socketUrl: undefined | string;
iobOldAlert: any;
changed: boolean;
$iframeDialog: {
close?: () => void;
};
}
}
export declare class GenericApp<TProps extends GenericAppProps = GenericAppProps, TState extends GenericAppState = GenericAppState> extends Router<TProps, TState> {
protected socket: AdminConnection;
protected isIFrame: boolean;
protected readonly instance: number;
protected readonly adapterName: string;
protected readonly instanceId: string;
protected readonly newReact: boolean;
protected encryptedFields: string[];
protected readonly sentryDSN: string | undefined;
private alertDialogRendered;
private _secret;
protected _systemConfig: ioBroker.SystemConfigCommon | undefined;
private savedNative;
protected common: ioBroker.InstanceCommon | null;
private sentryStarted;
private sentryInited;
private resizeTimer;
constructor(props: TProps, settings?: GenericAppSettings);
/**
* Checks if this connection is running in a web adapter and not in an admin.
*
* @returns True if running in a web adapter or in a socketio adapter.
*/
static isWeb(): boolean;
showAlert(message: string, type?: 'info' | 'warning' | 'error' | 'success'): void;
renderAlertSnackbar(): JSX.Element;
onSystemConfigChanged: (id: string, obj: ioBroker.AnyObject | null | undefined) => void;
/**
* Called immediately after a component is mounted. Setting state here will trigger re-rendering.
*/
componentDidMount(): void;
/**
* Called immediately before a component is destroyed.
*/
componentWillUnmount(): void;
onReceiveMessage: (message: {
data: string;
} | null) => void;
private onResize;
/**
* Gets the width depending on the window inner width.
*/
static getWidth(): Width;
/**
* Get a theme
*
* @param name Theme name
*/
createTheme(name?: ThemeName | null): IobTheme;
/**
* Get the theme name
*/
getThemeName(currentTheme: IobTheme): ThemeName;
/**
* Get the theme type
*/
getThemeType(currentTheme: IobTheme): ThemeType;
onThemeChanged(_newThemeName: string): void;
onToggleExpertMode(_expertMode: boolean): void;
/**
* Changes the current theme
*/
toggleTheme(newThemeName?: ThemeName): void;
/**
* Gets the system configuration.
*/
getSystemConfig(): Promise<ioBroker.SystemConfigObject>;
/**
* Get current expert mode
*/
getExpertMode(): boolean;
/**
* Gets called when the socket.io connection is ready.
* You can overload this function to execute own commands.
*/
onConnectionReady(): void;
/**
* Encrypts a string.
*/
encrypt(value: string): string;
/**
* Decrypts a string.
*/
decrypt(value: string): string;
/**
* Gets called when the navigation hash changes.
* You may override this if needed.
*/
onHashChanged(): void;
/**
* Selects the given tab.
*/
selectTab(tab: string, index?: number): void;
/**
* Gets called before the settings are saved.
* You may override this if needed.
*/
onPrepareSave(settings: Record<string, any>): boolean;
/**
* Gets called after the settings are loaded.
* You may override this if needed.
*
* @param settings instance settings from native part
* @param encryptedNative optional list of fields to be decrypted
*/
onPrepareLoad(settings: Record<string, any>, encryptedNative?: string[]): void;
/**
* Gets the extendable instances.
*/
getExtendableInstances(): Promise<ioBroker.InstanceObject[]>;
/**
* Gets the IP addresses of the given host.
*/
getIpAddresses(host: string): Promise<{
name: string;
address: string;
family: 'ipv4' | 'ipv6';
}[]>;
/**
* Saves the settings to the server.
*
* @param isClose True if the user is closing the dialog.
*/
onSave(isClose?: boolean): void;
/**
* Renders the toast.
*/
renderToast(): JSX.Element | null;
/**
* Closes the dialog.
*/
static onClose(): void;
/**
* Renders the error dialog.
*/
renderError(): React.JSX.Element | null;
/**
* Checks if the configuration has changed.
*
* @param native the new state
*/
getIsChanged(native: Record<string, any>): boolean;
/**
* Gets called when loading the configuration.
*
* @param newNative The new configuration object.
*/
onLoadConfig(newNative: Record<string, any>): void;
/**
* Sets the configuration error.
*/
setConfigurationError(errorText: string): void;
/**
* Renders the save and close buttons.
*/
renderSaveCloseButtons(): React.JSX.Element | null;
private _updateNativeValue;
/**
* Update the native value
*
* @param attr The attribute name with dots as delimiter.
* @param value The new value.
* @param cb Callback which will be called upon completion.
*/
updateNativeValue(attr: string, value: any, cb?: () => void): void;
/**
* Set the error text to be shown.
*/
showError(text: string | React.JSX.Element): void;
/**
* Sets the toast to be shown.
*
* @param toast Text to be shown.
*/
showToast(toast: string | React.JSX.Element): void;
/**
* Renders helper dialogs
*/
renderHelperDialogs(): React.JSX.Element;
/**
* Renders this component.
*/
render(): React.JSX.Element;
}