@iobroker/adapter-react-v5 7.4.19 → 7.4.21

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,5 +1,4 @@
1
- import { type JSX } from 'react';
2
- import { Component } from 'react';
1
+ import { type JSX, Component } from 'react';
3
2
  interface ImageProps {
4
3
  color?: string;
5
4
  src?: string;
@@ -1,5 +1,4 @@
1
- import React from 'react';
2
- import { Component } from 'react';
1
+ import React, { Component } from 'react';
3
2
  import { IconNoIcon } from '../icons/IconNoIcon';
4
3
  function getElementFromSource(src) {
5
4
  const svgContainer = document.createElement('div');
@@ -1 +1 @@
1
- {"version":3,"file":"Image.js","sourceRoot":"./src/","sources":["Components/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,SAAS,oBAAoB,CAAC,GAAW;IACrC,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnD,YAAY,CAAC,SAAS,GAAG,GAAG,CAAC;IAC7B,MAAM,GAAG,GAAgB,YAAY,CAAC,iBAAgC,CAAC;IACvE,IAAI,GAAG,EAAE,MAAM,EAAE,CAAC;QACd,GAAG,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;SAAM,IAAI,GAAG,EAAE,CAAC;QACb,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,YAAY,CAAC,MAAM,EAAE,CAAC;IACtB,OAAO,GAAG,CAAC;AACf,CAAC;AAED,SAAS,cAAc,CAAC,GAAkB;IACtC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,GAAG,CAAC;IACf,CAAC;IACD,KAAK,IAAI,IAAI,EAAE,CAAC,GAAG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E,GAAG,EAAE,CACV,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAE3F,CACL,CAAC;YACN,CAAC;YAED,OAAO,CACH,6BACI,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EACpD,GAAG,EAAC,EAAE,EACN,OAAO,EAAE,GAAG,EAAE,CACV,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAE3F,CACL,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\nimport { Component } from 'react';\n\nimport { IconNoIcon } from '../icons/IconNoIcon';\n\nfunction getElementFromSource(src: string): HTMLElement | null {\n const svgContainer = document.createElement('div');\n svgContainer.innerHTML = src;\n const svg: HTMLElement = svgContainer.firstElementChild as HTMLElement;\n if (svg?.remove) {\n svg.remove();\n } else if (svg) {\n svgContainer.removeChild(svg);\n }\n\n svgContainer.remove();\n return svg;\n}\n\nfunction serializeAttrs(map?: NamedNodeMap): Record<string, string> {\n const ret: Record<string, string> = {};\n if (!map) {\n return ret;\n }\n for (let prop, i = 0; i < map.length; i++) {\n const key = map[i].name;\n if (key === 'class') {\n prop = 'className';\n } else if (!key.startsWith('data-')) {\n prop = key.replace(/[-|:]([a-z])/g, g => g[1].toUpperCase());\n } else {\n prop = key;\n }\n\n ret[prop] = map[i].value;\n }\n return ret;\n}\n\ninterface ImageProps {\n /* The color */\n color?: string;\n /* The source of the image */\n src?: string;\n /* The image prefix (default: './files/') */\n imagePrefix?: string;\n /* The CSS class name */\n className?: string;\n /* Show image errors (or just show no image)? */\n showError?: boolean;\n}\n\ninterface ImageState {\n svg?: boolean;\n created?: boolean;\n color?: string;\n src?: string;\n imgError?: boolean;\n showError?: boolean;\n}\n\n/**\n * A component for displaying an image.\n */\nexport class Image extends Component<ImageProps, ImageState> {\n private svg: JSX.Element | null;\n\n static REMOTE_SERVER: boolean = window.location.hostname.includes('iobroker.in');\n\n static REMOTE_PREFIX: string = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);\n\n constructor(props: ImageProps) {\n super(props);\n this.state = {\n svg: !!this.props.src?.startsWith('data:'),\n created: true,\n color: this.props.color || '',\n src: this.props.src || '',\n imgError: false,\n showError: !!this.props.showError,\n };\n\n this.svg = this.state.svg && this.state.src ? this.getSvgFromData(this.state.src) : null;\n }\n\n static getDerivedStateFromProps(props: ImageProps, state: ImageState): Partial<ImageState> | null {\n const newState: ImageState = {};\n let changed = false;\n\n if (props && state && props.src !== state.src) {\n newState.src = props.src;\n newState.svg = props.src?.startsWith('data:');\n newState.created = false;\n changed = true;\n }\n\n if (props && state && props.color !== state.color) {\n newState.color = props.color;\n newState.created = false;\n changed = true;\n }\n\n if (props && state && props.showError !== state.showError) {\n newState.showError = props.showError;\n changed = true;\n }\n\n return changed ? newState : null;\n }\n\n getSvgFromData(src: string): JSX.Element | null {\n const len = 'data:image/svg+xml;base64,';\n if (!src.startsWith(len)) {\n return null;\n }\n src = src.substring(len.length);\n try {\n src = atob(src);\n const svg: HTMLElement = getElementFromSource(src);\n const inner = svg.innerHTML;\n const svgProps = serializeAttrs(svg.attributes);\n\n svg.remove();\n\n return (\n <svg\n className={this.props.className}\n style={this.state.color ? { color: this.state.color } : {}}\n {...svgProps}\n dangerouslySetInnerHTML={{ __html: inner }}\n />\n );\n } catch {\n // ignore\n }\n return null;\n }\n\n render(): JSX.Element | null {\n if (this.state.svg) {\n if (!this.state.created) {\n setTimeout(() => {\n this.svg = this.state.src ? this.getSvgFromData(this.state.src) : null;\n this.setState({ created: true });\n }, 50);\n }\n\n return this.svg;\n }\n if (this.state.src) {\n if (this.state.imgError || !this.state.src) {\n return <IconNoIcon className={this.props.className} />;\n }\n if (\n Image.REMOTE_SERVER &&\n !this.state.src.startsWith('http://') &&\n !this.state.src.startsWith('https://')\n ) {\n let src = (this.props.imagePrefix || '') + this.state.src;\n if (src.startsWith('./')) {\n src = Image.REMOTE_PREFIX + src.substring(2);\n } else if (!src.startsWith('/')) {\n src = Image.REMOTE_PREFIX + src;\n }\n return (\n <img\n className={this.props.className}\n src={`https://remote-files.iobroker.in${src}`}\n alt=\"\"\n onError={() =>\n this.props.showError ? this.setState({ imgError: true }) : this.setState({ src: '' })\n }\n />\n );\n }\n\n return (\n <img\n className={this.props.className}\n src={(this.props.imagePrefix || '') + this.state.src}\n alt=\"\"\n onError={() =>\n this.props.showError ? this.setState({ imgError: true }) : this.setState({ src: '' })\n }\n />\n );\n }\n\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"Image.js","sourceRoot":"./src/","sources":["Components/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAY,SAAS,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,SAAS,oBAAoB,CAAC,GAAW;IACrC,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnD,YAAY,CAAC,SAAS,GAAG,GAAG,CAAC;IAC7B,MAAM,GAAG,GAAgB,YAAY,CAAC,iBAAgC,CAAC;IACvE,IAAI,GAAG,EAAE,MAAM,EAAE,CAAC;QACd,GAAG,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;SAAM,IAAI,GAAG,EAAE,CAAC;QACb,YAAY,CA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ACjD,CAAC;qBAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC9B,GAAG,GAAG,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC;gBACpC,CAAC;gBACD,OAAO,CACH,6BACI,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,GAAG,EAAE,mCAAmC,GAAG,EAAE,EAC7C,GAAG,EAAC,EAAE,EACN,OAAO,EAAE,GAAG,EAAE,CACV,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAE3F,CACL,CAAC;YACN,CAAC;YAED,OAAO,CACH,6BACI,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EACpD,GAAG,EAAC,EAAE,EACN,OAAO,EAAE,GAAG,EAAE,CACV,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAE3F,CACL,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC","sourcesContent":["import React, { type JSX, Component } from 'react';\n\nimport { IconNoIcon } from '../icons/IconNoIcon';\n\nfunction getElementFromSource(src: string): HTMLElement | null {\n const svgContainer = document.createElement('div');\n svgContainer.innerHTML = src;\n const svg: HTMLElement = svgContainer.firstElementChild as HTMLElement;\n if (svg?.remove) {\n svg.remove();\n } else if (svg) {\n svgContainer.removeChild(svg);\n }\n\n svgContainer.remove();\n return svg;\n}\n\nfunction serializeAttrs(map?: NamedNodeMap): Record<string, string> {\n const ret: Record<string, string> = {};\n if (!map) {\n return ret;\n }\n for (let prop, i = 0; i < map.length; i++) {\n const key = map[i].name;\n if (key === 'class') {\n prop = 'className';\n } else if (!key.startsWith('data-')) {\n prop = key.replace(/[-|:]([a-z])/g, g => g[1].toUpperCase());\n } else {\n prop = key;\n }\n\n ret[prop] = map[i].value;\n }\n return ret;\n}\n\ninterface ImageProps {\n /* The color */\n color?: string;\n /* The source of the image */\n src?: string;\n /* The image prefix (default: './files/') */\n imagePrefix?: string;\n /* The CSS class name */\n className?: string;\n /* Show image errors (or just show no image)? */\n showError?: boolean;\n}\n\ninterface ImageState {\n svg?: boolean;\n created?: boolean;\n color?: string;\n src?: string;\n imgError?: boolean;\n showError?: boolean;\n}\n\n/**\n * A component for displaying an image.\n */\nexport class Image extends Component<ImageProps, ImageState> {\n private svg: JSX.Element | null;\n\n static REMOTE_SERVER: boolean = window.location.hostname.includes('iobroker.in');\n\n static REMOTE_PREFIX: string = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);\n\n constructor(props: ImageProps) {\n super(props);\n this.state = {\n svg: !!this.props.src?.startsWith('data:'),\n created: true,\n color: this.props.color || '',\n src: this.props.src || '',\n imgError: false,\n showError: !!this.props.showError,\n };\n\n this.svg = this.state.svg && this.state.src ? this.getSvgFromData(this.state.src) : null;\n }\n\n static getDerivedStateFromProps(props: ImageProps, state: ImageState): Partial<ImageState> | null {\n const newState: ImageState = {};\n let changed = false;\n\n if (props && state && props.src !== state.src) {\n newState.src = props.src;\n newState.svg = props.src?.startsWith('data:');\n newState.created = false;\n changed = true;\n }\n\n if (props && state && props.color !== state.color) {\n newState.color = props.color;\n newState.created = false;\n changed = true;\n }\n\n if (props && state && props.showError !== state.showError) {\n newState.showError = props.showError;\n changed = true;\n }\n\n return changed ? newState : null;\n }\n\n getSvgFromData(src: string): JSX.Element | null {\n const len = 'data:image/svg+xml;base64,';\n if (!src.startsWith(len)) {\n return null;\n }\n src = src.substring(len.length);\n try {\n src = atob(src);\n const svg: HTMLElement = getElementFromSource(src);\n const inner = svg.innerHTML;\n const svgProps = serializeAttrs(svg.attributes);\n\n svg.remove();\n\n return (\n <svg\n className={this.props.className}\n style={this.state.color ? { color: this.state.color } : {}}\n {...svgProps}\n dangerouslySetInnerHTML={{ __html: inner }}\n />\n );\n } catch {\n // ignore\n }\n return null;\n }\n\n render(): JSX.Element | null {\n if (this.state.svg) {\n if (!this.state.created) {\n setTimeout(() => {\n this.svg = this.state.src ? this.getSvgFromData(this.state.src) : null;\n this.setState({ created: true });\n }, 50);\n }\n\n return this.svg;\n }\n if (this.state.src) {\n if (this.state.imgError || !this.state.src) {\n return <IconNoIcon className={this.props.className} />;\n }\n if (\n Image.REMOTE_SERVER &&\n !this.state.src.startsWith('http://') &&\n !this.state.src.startsWith('https://')\n ) {\n let src = (this.props.imagePrefix || '') + this.state.src;\n if (src.startsWith('./')) {\n src = Image.REMOTE_PREFIX + src.substring(2);\n } else if (!src.startsWith('/')) {\n src = Image.REMOTE_PREFIX + src;\n }\n return (\n <img\n className={this.props.className}\n src={`https://remote-files.iobroker.in${src}`}\n alt=\"\"\n onError={() =>\n this.props.showError ? this.setState({ imgError: true }) : this.setState({ src: '' })\n }\n />\n );\n }\n\n return (\n <img\n className={this.props.className}\n src={(this.props.imagePrefix || '') + this.state.src}\n alt=\"\"\n onError={() =>\n this.props.showError ? this.setState({ imgError: true }) : this.setState({ src: '' })\n }\n />\n );\n }\n\n return null;\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ interface InfoBoxProps {
3
+ /** Text to display in the info box */
4
+ children: string | (string | React.JSX.Element | null)[] | React.JSX.Element;
5
+ /** The type determines the color and symbol */
6
+ type: 'warning' | 'info' | 'error' | 'ok';
7
+ /** If the Box is closeable */
8
+ closeable?: boolean;
9
+ /** Use together with `closeable: true`. You can specify in which variable in local storage the state of this info box could be stored */
10
+ storeId?: string;
11
+ /** Use together with `closeable: true`, listener called if close button clicked */
12
+ onClose?: (desiredState: boolean) => void;
13
+ /** Custom style */
14
+ style?: React.CSSProperties;
15
+ /** Icon position */
16
+ iconPosition?: 'top' | 'middle';
17
+ /** Use together with `closeable: true`. If the box is closed or not. In this case, it will be controlled from outside */
18
+ closed?: boolean;
19
+ }
20
+ interface InfoBoxState {
21
+ closed: boolean;
22
+ }
23
+ /**
24
+ * This component can be used to show important information or warnings to the user
25
+ */
26
+ export default class InfoBox extends React.Component<InfoBoxProps, InfoBoxState> {
27
+ private readonly refTypo;
28
+ private height;
29
+ private width;
30
+ constructor(props: InfoBoxProps);
31
+ componentDidMount(): void;
32
+ onClick(): void;
33
+ detectHeight(): void;
34
+ componentDidUpdate(): void;
35
+ render(): React.ReactNode;
36
+ }
37
+ export {};
@@ -0,0 +1,115 @@
1
+ import React from 'react';
2
+ import { Box, Typography } from '@mui/material';
3
+ import { Info, Warning, Close, Visibility, Check } from '@mui/icons-material';
4
+ /**
5
+ * This component can be used to show important information or warnings to the user
6
+ */
7
+ export default class InfoBox extends React.Component {
8
+ refTypo;
9
+ height;
10
+ width;
11
+ constructor(props) {
12
+ super(props);
13
+ this.state = {
14
+ closed: this.props.storeId ? window.localStorage.getItem(this.props.storeId) === 'true' : false,
15
+ };
16
+ this.height = 0;
17
+ this.width = 0;
18
+ this.refTypo = React.createRef();
19
+ }
20
+ componentDidMount() {
21
+ this.detectHeight();
22
+ }
23
+ onClick() {
24
+ if (this.props.storeId && this.props.closed === undefined) {
25
+ if (this.state.closed) {
26
+ window.localStorage.removeItem(this.props.storeId);
27
+ }
28
+ else {
29
+ window.localStorage.setItem(this.props.storeId, 'true');
30
+ }
31
+ }
32
+ if (this.props.closed === undefined) {
33
+ this.setState({ closed: !this.state.closed }, () => {
34
+ // Inform about state change
35
+ if (this.props.onClose) {
36
+ this.props.onClose(this.state.closed);
37
+ }
38
+ });
39
+ }
40
+ else if (this.props.onClose) {
41
+ this.props.onClose(!this.props.closed);
42
+ }
43
+ }
44
+ detectHeight() {
45
+ const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;
46
+ // We must get the height of the element when it is open to make transition
47
+ if (this.props.closeable && !closed && this.refTypo.current) {
48
+ window.requestAnimationFrame(() => {
49
+ const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;
50
+ if (closed) {
51
+ return;
52
+ }
53
+ if (this.refTypo.current && (!this.height || this.width !== this.refTypo.current.clientWidth)) {
54
+ this.height = this.refTypo.current.clientHeight;
55
+ this.width = this.refTypo.current.clientWidth;
56
+ this.forceUpdate();
57
+ }
58
+ });
59
+ }
60
+ }
61
+ componentDidUpdate() {
62
+ this.detectHeight();
63
+ }
64
+ render() {
65
+ const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;
66
+ const Icon = closed ? Visibility : Close;
67
+ return (React.createElement(Box, { className: "iom-info-box", style: {
68
+ whiteSpace: 'preserve',
69
+ display: 'flex',
70
+ gap: 8,
71
+ alignItems: closed || this.props.iconPosition === 'top' ? 'flex-start' : 'center',
72
+ borderWidth: 1,
73
+ borderStyle: 'solid',
74
+ padding: 4,
75
+ borderRadius: 5,
76
+ marginBottom: 8,
77
+ maxWidth: '100%',
78
+ transition: 'height 0.5s',
79
+ height: this.props.closeable ? (closed ? 30 : this.height || undefined) : undefined,
80
+ overflow: this.props.closeable ? 'hidden' : undefined,
81
+ position: 'relative',
82
+ ...this.props.style,
83
+ }, sx: {
84
+ borderColor: theme => this.props.type === 'ok' ? theme.palette.info.main : theme.palette[this.props.type].main,
85
+ } },
86
+ this.props.type === 'ok' ? (React.createElement(Check, { style: { color: '#0F0' } })) : this.props.type === 'info' ? (React.createElement(Info, { color: "primary" })) : (React.createElement(Warning, { color: this.props.type })),
87
+ React.createElement(Typography, { ref: this.refTypo }, this.props.children),
88
+ this.props.closeable ? (React.createElement(Icon, { sx: {
89
+ color: theme => (theme.palette.mode === 'dark' ? 'lightgray' : 'gray'),
90
+ // alignSelf: 'flex-start',
91
+ cursor: 'pointer',
92
+ position: 'absolute',
93
+ top: 4,
94
+ right: 4,
95
+ }, onClick: () => this.onClick() })) : null,
96
+ this.props.closeable ? React.createElement("div", { style: { width: 22 } }) : null,
97
+ closed ? (React.createElement(Box
98
+ // This is a shadow box at the bottom of the InfoBox when it closed
99
+ , {
100
+ // This is a shadow box at the bottom of the InfoBox when it closed
101
+ component: "div", sx: theme => {
102
+ const color = theme.palette[this.props.type === 'ok' ? 'info' : this.props.type].main;
103
+ return {
104
+ background: `linear-gradient(${color}00 0%, ${color}10 60%, ${color}90 100%)`,
105
+ };
106
+ }, style: {
107
+ bottom: 0,
108
+ position: 'absolute',
109
+ left: 0,
110
+ right: 0,
111
+ height: 10,
112
+ } })) : null));
113
+ }
114
+ }
115
+ //# sourceMappingURL=InfoBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InfoBox.js","sourceRoot":"./src/","sources":["Components/InfoBox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAyB,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAwBrG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAAqC;IAC3D,OAAO,CAAkC;IAClD,MAAM,CAAS;IACf,KAAK,CAAS;IAEtB,YAAY,KAAmB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG;YACT,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK;SAClG,CAAC;QAC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AC;oBACtF,OAAO;wBACH,UAAU,EAAE,mBAAmB,KAAK,UAAU,KAAK,WAAW,KAAK,UAAU;qBAChF,CAAC;gBACN,CAAC,EACD,KAAK,EAAE;oBACH,MAAM,EAAE,CAAC;oBACT,QAAQ,EAAE,UAAU;oBACpB,IAAI,EAAE,CAAC;oBACP,KAAK,EAAE,CAAC;oBACR,MAAM,EAAE,EAAE;iBACb,GACH,CACL,CAAC,CAAC,CAAC,IAAI,CACN,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { Info, Warning, Close, Visibility, type SvgIconComponent, Check } from '@mui/icons-material';\n\ninterface InfoBoxProps {\n /** Text to display in the info box */\n children: string | (string | React.JSX.Element | null)[] | React.JSX.Element;\n /** The type determines the color and symbol */\n type: 'warning' | 'info' | 'error' | 'ok';\n /** If the Box is closeable */\n closeable?: boolean;\n /** Use together with `closeable: true`. You can specify in which variable in local storage the state of this info box could be stored */\n storeId?: string;\n /** Use together with `closeable: true`, listener called if close button clicked */\n onClose?: (desiredState: boolean) => void;\n /** Custom style */\n style?: React.CSSProperties;\n /** Icon position */\n iconPosition?: 'top' | 'middle';\n /** Use together with `closeable: true`. If the box is closed or not. In this case, it will be controlled from outside */\n closed?: boolean;\n}\n\ninterface InfoBoxState {\n closed: boolean;\n}\n/**\n * This component can be used to show important information or warnings to the user\n */\nexport default class InfoBox extends React.Component<InfoBoxProps, InfoBoxState> {\n private readonly refTypo: React.RefObject<HTMLDivElement>;\n private height: number;\n private width: number;\n\n constructor(props: InfoBoxProps) {\n super(props);\n this.state = {\n closed: this.props.storeId ? window.localStorage.getItem(this.props.storeId) === 'true' : false,\n };\n this.height = 0;\n this.width = 0;\n\n this.refTypo = React.createRef();\n }\n\n componentDidMount(): void {\n this.detectHeight();\n }\n\n onClick(): void {\n if (this.props.storeId && this.props.closed === undefined) {\n if (this.state.closed) {\n window.localStorage.removeItem(this.props.storeId);\n } else {\n window.localStorage.setItem(this.props.storeId, 'true');\n }\n }\n if (this.props.closed === undefined) {\n this.setState({ closed: !this.state.closed }, () => {\n // Inform about state change\n if (this.props.onClose) {\n this.props.onClose(this.state.closed);\n }\n });\n } else if (this.props.onClose) {\n this.props.onClose(!this.props.closed);\n }\n }\n\n detectHeight(): void {\n const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;\n // We must get the height of the element when it is open to make transition\n if (this.props.closeable && !closed && this.refTypo.current) {\n window.requestAnimationFrame(() => {\n const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;\n if (closed) {\n return;\n }\n if (this.refTypo.current && (!this.height || this.width !== this.refTypo.current.clientWidth)) {\n this.height = this.refTypo.current.clientHeight;\n this.width = this.refTypo.current.clientWidth;\n this.forceUpdate();\n }\n });\n }\n }\n\n componentDidUpdate(): void {\n this.detectHeight();\n }\n\n render(): React.ReactNode {\n const closed = this.props.closed !== undefined ? this.props.closed : this.state.closed;\n\n const Icon: SvgIconComponent = closed ? Visibility : Close;\n\n return (\n <Box\n className=\"iom-info-box\"\n style={{\n whiteSpace: 'preserve',\n display: 'flex',\n gap: 8,\n alignItems: closed || this.props.iconPosition === 'top' ? 'flex-start' : 'center',\n borderWidth: 1,\n borderStyle: 'solid',\n padding: 4,\n borderRadius: 5,\n marginBottom: 8,\n maxWidth: '100%',\n transition: 'height 0.5s',\n height: this.props.closeable ? (closed ? 30 : this.height || undefined) : undefined,\n overflow: this.props.closeable ? 'hidden' : undefined,\n position: 'relative',\n ...this.props.style,\n }}\n sx={{\n borderColor: theme =>\n this.props.type === 'ok' ? theme.palette.info.main : theme.palette[this.props.type].main,\n }}\n >\n {this.props.type === 'ok' ? (\n <Check style={{ color: '#0F0' }} />\n ) : this.props.type === 'info' ? (\n <Info color=\"primary\" />\n ) : (\n <Warning color={this.props.type} />\n )}\n <Typography ref={this.refTypo}>{this.props.children}</Typography>\n {this.props.closeable ? (\n <Icon\n sx={{\n color: theme => (theme.palette.mode === 'dark' ? 'lightgray' : 'gray'),\n // alignSelf: 'flex-start',\n cursor: 'pointer',\n position: 'absolute',\n top: 4,\n right: 4,\n }}\n onClick={() => this.onClick()}\n />\n ) : null}\n {/* Reserve place for button so it will not overlap the text */}\n {this.props.closeable ? <div style={{ width: 22 }} /> : null}\n {closed ? (\n <Box\n // This is a shadow box at the bottom of the InfoBox when it closed\n component=\"div\"\n sx={theme => {\n const color = theme.palette[this.props.type === 'ok' ? 'info' : this.props.type].main;\n return {\n background: `linear-gradient(${color}00 0%, ${color}10 60%, ${color}90 100%)`,\n };\n }}\n style={{\n bottom: 0,\n position: 'absolute',\n left: 0,\n right: 0,\n height: 10,\n }}\n />\n ) : null}\n </Box>\n );\n }\n}\n"]}
@@ -24,6 +24,7 @@ export class Logo extends React.Component {
24
24
  if (f) {
25
25
  const reader = new window.FileReader();
26
26
  reader.onload = () => {
27
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
27
28
  const contents = reader.result?.toString() || '';
28
29
  try {
29
30
  const json = JSON.parse(contents);
@@ -1 +1 @@
1
- {"version":3,"file":"Logo.js","sourceRoot":"./src/","sources":["Components/Logo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EACH,IAAI,IAAI,QAAQ,EAChB,gBAAgB,IAAI,UAAU,EAC9B,mBAAmB,IAAI,YAAY,GACtC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAiB9B,MAAM,OAAO,IAAK,SAAQ,KAAK,CAAC,SAAoB;IAChD,MAAM,CAAC,YAAY,CAAC,QAAgB,EAAE,GAAQ;QAC1C,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC9C,EAAE,CAAC,YAAY,CACX,MAAM,EACN,uCA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CAAC,CAAC,CACxB,oBAAC,GAAG,IACA,IAAI,EAAC,OAAO,EACZ,KAAK,EAAC,SAAS,gBACJ,MAAM,EACjB,KAAK,EAAE;oBACH,WAAW,EAAE,CAAC;oBACd,SAAS,EAAE,CAAC;oBACZ,KAAK,EAAE,OAAO;iBACjB,EACD,OAAO,EAAE,GAAG,EAAE;oBACV,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAC5D,GAAG,EAAE,KAAK,EAAE,CAAC;gBACjB,CAAC;gBAED,oBAAC,QAAQ,OAAG,CACV,CACT,CAAC,CAAC,CAAC,IAAI;YACR,oBAAC,GAAG,IACA,IAAI,EAAC,OAAO,EACZ,KAAK,EAAC,SAAS,gBACJ,aAAa,EACxB,KAAK,EAAE;oBACH,WAAW,EAAE,CAAC;oBACd,SAAS,EAAE,CAAC;oBACZ,KAAK,EAAE,OAAO;iBACjB,EACD,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,iCAAiC,CAAC,EAChD,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;gBAE5B,oBAAC,UAAU,OAAG,CACZ;YACN,oBAAC,GAAG,IACA,IAAI,EAAC,OAAO,EACZ,KAAK,EAAC,SAAS,gBACJ,aAAa,EACxB,KAAK,EAAE;oBACH,WAAW,EAAE,CAAC;oBACd,SAAS,EAAE,CAAC;oBACZ,KAAK,EAAE,OAAO;iBACjB,EACD,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,+BAA+B,CAAC,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAE9B,oBAAC,YAAY,OAAG,CACd,CACJ,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { Fab } from '@mui/material';\n\nimport {\n Help as IconHelp,\n VerticalAlignTop as IconUpload,\n VerticalAlignBottom as IconDownload,\n} from '@mui/icons-material';\n\nimport { I18n } from '../i18n';\nimport { Icon } from './Icon';\n\ninterface LogoProps {\n /* Adapter common configuration from io-package.json */\n common: any;\n /* Adapter native data from io-package.json */\n native: any;\n /* Adapter instance number. */\n instance: number;\n /* on Load handler */\n onLoad?: (contents: any) => void;\n /* on Error handler */\n onError?: (error: string) => void;\n className?: string;\n style?: Record<string, any>;\n}\n\nexport class Logo extends React.Component<LogoProps> {\n static generateFile(fileName: string, obj: any): void {\n const el = window.document.createElement('a');\n el.setAttribute(\n 'href',\n `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(obj, null, 2))}`,\n );\n el.setAttribute('download', fileName);\n\n el.style.display = 'none';\n window.document.body.appendChild(el);\n\n el.click();\n\n window.document.body.removeChild(el);\n }\n\n handleFileSelect = (evt: Event): void => {\n const target = evt.target as HTMLInputElement;\n const files = target?.files;\n if (!files || !files.length) {\n console.error('No files found. Please report to developers');\n return;\n }\n const f = files[0];\n\n if (f) {\n const reader = new window.FileReader();\n reader.onload = () => {\n const contents: string = reader.result?.toString() || '';\n try {\n const json = JSON.parse(contents);\n if (json.native && json.common) {\n if (json.common.name !== this.props.common.name) {\n this.props.onError && this.props.onError(I18n.t('ra_otherConfig', json.common.name));\n } else {\n this.props.onLoad && this.props.onLoad(json.native);\n }\n } else {\n this.props.onError && this.props.onError(I18n.t('ra_invalidConfig'));\n }\n } catch (err: any) {\n this.props.onError && this.props.onError(err?.toString());\n }\n };\n reader.readAsText(f);\n } else {\n alert('Failed to open JSON File');\n }\n };\n\n download(): void {\n const result = {\n _id: `system.adapter.${this.props.common.name}.${this.props.instance}`,\n common: JSON.parse(JSON.stringify(this.props.common)),\n native: this.props.native,\n };\n // remove unimportant information\n if (result.common.news) {\n delete result.common.news;\n }\n if (result.common.titleLang) {\n delete result.common.titleLang;\n }\n if (result.common.desc) {\n delete result.common.desc;\n }\n\n // window.open('data:application/iobroker; content-disposition=attachment; filename=' + result._id + '.json,' + JSON.stringify(result, null, 2));\n Logo.generateFile(`${result._id}.json`, result);\n }\n\n upload(): void {\n const input = window.document.createElement('input');\n input.setAttribute('type', 'file');\n input.setAttribute('id', 'files');\n input.setAttribute('opacity', '0');\n input.addEventListener('change', this.handleFileSelect, false);\n input.click();\n }\n\n render(): React.JSX.Element {\n return (\n <div\n className={this.props.className}\n style={this.props.style}\n >\n {this.props.common.icon ? (\n <Icon\n src={this.props.common.icon}\n style={{\n padding: 8,\n width: 64,\n }}\n alt=\"logo\"\n />\n ) : null}\n {this.props.common.readme ? (\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Help\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n onClick={() => {\n const win = window.open(this.props.common.readme, '_blank');\n win?.focus();\n }}\n >\n <IconHelp />\n </Fab>\n ) : null}\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Load config\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n title={I18n.t('ra_Load configuration from file')}\n onClick={() => this.upload()}\n >\n <IconUpload />\n </Fab>\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Save config\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n title={I18n.t('ra_Save configuration to file')}\n onClick={() => this.download()}\n >\n <IconDownload />\n </Fab>\n </div>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"Logo.js","sourceRoot":"./src/","sources":["Components/Logo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EACH,IAAI,IAAI,QAAQ,EAChB,gBAAgB,IAAI,UAAU,EAC9B,mBAAmB,IAAI,YAAY,GACtC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAiB9B,MAA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AAC,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAE9B,oBAAC,YAAY,OAAG,CACd,CACJ,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { Fab } from '@mui/material';\n\nimport {\n Help as IconHelp,\n VerticalAlignTop as IconUpload,\n VerticalAlignBottom as IconDownload,\n} from '@mui/icons-material';\n\nimport { I18n } from '../i18n';\nimport { Icon } from './Icon';\n\ninterface LogoProps {\n /* Adapter common configuration from io-package.json */\n common: any;\n /* Adapter native data from io-package.json */\n native: any;\n /* Adapter instance number. */\n instance: number;\n /* on Load handler */\n onLoad?: (contents: any) => void;\n /* on Error handler */\n onError?: (error: string) => void;\n className?: string;\n style?: Record<string, any>;\n}\n\nexport class Logo extends React.Component<LogoProps> {\n static generateFile(fileName: string, obj: any): void {\n const el = window.document.createElement('a');\n el.setAttribute(\n 'href',\n `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(obj, null, 2))}`,\n );\n el.setAttribute('download', fileName);\n\n el.style.display = 'none';\n window.document.body.appendChild(el);\n\n el.click();\n\n window.document.body.removeChild(el);\n }\n\n handleFileSelect = (evt: Event): void => {\n const target = evt.target as HTMLInputElement;\n const files = target?.files;\n if (!files || !files.length) {\n console.error('No files found. Please report to developers');\n return;\n }\n const f = files[0];\n\n if (f) {\n const reader = new window.FileReader();\n reader.onload = () => {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n const contents: string = reader.result?.toString() || '';\n try {\n const json = JSON.parse(contents);\n if (json.native && json.common) {\n if (json.common.name !== this.props.common.name) {\n this.props.onError && this.props.onError(I18n.t('ra_otherConfig', json.common.name));\n } else {\n this.props.onLoad && this.props.onLoad(json.native);\n }\n } else {\n this.props.onError && this.props.onError(I18n.t('ra_invalidConfig'));\n }\n } catch (err: any) {\n this.props.onError && this.props.onError(err?.toString());\n }\n };\n reader.readAsText(f);\n } else {\n alert('Failed to open JSON File');\n }\n };\n\n download(): void {\n const result = {\n _id: `system.adapter.${this.props.common.name}.${this.props.instance}`,\n common: JSON.parse(JSON.stringify(this.props.common)),\n native: this.props.native,\n };\n // remove unimportant information\n if (result.common.news) {\n delete result.common.news;\n }\n if (result.common.titleLang) {\n delete result.common.titleLang;\n }\n if (result.common.desc) {\n delete result.common.desc;\n }\n\n // window.open('data:application/iobroker; content-disposition=attachment; filename=' + result._id + '.json,' + JSON.stringify(result, null, 2));\n Logo.generateFile(`${result._id}.json`, result);\n }\n\n upload(): void {\n const input = window.document.createElement('input');\n input.setAttribute('type', 'file');\n input.setAttribute('id', 'files');\n input.setAttribute('opacity', '0');\n input.addEventListener('change', this.handleFileSelect, false);\n input.click();\n }\n\n render(): React.JSX.Element {\n return (\n <div\n className={this.props.className}\n style={this.props.style}\n >\n {this.props.common.icon ? (\n <Icon\n src={this.props.common.icon}\n style={{\n padding: 8,\n width: 64,\n }}\n alt=\"logo\"\n />\n ) : null}\n {this.props.common.readme ? (\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Help\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n onClick={() => {\n const win = window.open(this.props.common.readme, '_blank');\n win?.focus();\n }}\n >\n <IconHelp />\n </Fab>\n ) : null}\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Load config\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n title={I18n.t('ra_Load configuration from file')}\n onClick={() => this.upload()}\n >\n <IconUpload />\n </Fab>\n <Fab\n size=\"small\"\n color=\"primary\"\n aria-label=\"Save config\"\n style={{\n marginRight: 5,\n marginTop: 5,\n float: 'right',\n }}\n title={I18n.t('ra_Save configuration to file')}\n onClick={() => this.download()}\n >\n <IconDownload />\n </Fab>\n </div>\n );\n }\n}\n"]}
@@ -1525,6 +1525,7 @@ export class Utils {
1525
1525
  const blob = await response.blob();
1526
1526
  return new Promise(resolve => {
1527
1527
  const reader = new FileReader();
1528
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
1528
1529
  reader.onload = () => resolve(reader.result?.toString() || '');
1529
1530
  reader.readAsDataURL(blob);
1530
1531
  });