@iobroker/adapter-react-v5 7.1.0 → 7.1.3

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,57 +1,57 @@
1
- import React from 'react';
2
-
3
- import { Grid, Paper } from '@mui/material';
4
-
5
- const styles: Record<string, React.CSSProperties> = {
6
- root: {
7
- width: '100%',
8
- height: '100%',
9
- },
10
- overflowHidden: {
11
- overflow: 'hidden',
12
- },
13
- container: {
14
- height: '100%',
15
- },
16
- };
17
-
18
- interface TabContainerProps {
19
- /* The elevation of the tab container. */
20
- elevation?: number;
21
- /* Set to 'visible' show the overflow. */
22
- overflow?: string;
23
- styles?: {
24
- root?: React.CSSProperties;
25
- container?: React.CSSProperties;
26
- };
27
- onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
28
- tabIndex?: number;
29
- /** The content of the component. */
30
- children: React.ReactNode;
31
- }
32
-
33
- function TabContainer(props: TabContainerProps): React.JSX.Element {
34
- return (
35
- <Paper
36
- elevation={!Number.isNaN(props.elevation) ? props.elevation : 1}
37
- style={{
38
- ...styles.root,
39
- ...(props.styles?.root || undefined),
40
- ...(props.overflow !== 'visible' ? styles.overflowHidden : undefined),
41
- }}
42
- onKeyDown={props.onKeyDown}
43
- tabIndex={props.tabIndex}
44
- >
45
- <Grid
46
- container
47
- direction="column"
48
- wrap="nowrap"
49
- sx={styles.container}
50
- >
51
- {props.children}
52
- </Grid>
53
- </Paper>
54
- );
55
- }
56
-
57
- export default TabContainer;
1
+ import React from 'react';
2
+
3
+ import { Grid2, Paper } from '@mui/material';
4
+
5
+ const styles: Record<string, React.CSSProperties> = {
6
+ root: {
7
+ width: '100%',
8
+ height: '100%',
9
+ },
10
+ overflowHidden: {
11
+ overflow: 'hidden',
12
+ },
13
+ container: {
14
+ height: '100%',
15
+ },
16
+ };
17
+
18
+ interface TabContainerProps {
19
+ /* The elevation of the tab container. */
20
+ elevation?: number;
21
+ /* Set to 'visible' show the overflow. */
22
+ overflow?: string;
23
+ styles?: {
24
+ root?: React.CSSProperties;
25
+ container?: React.CSSProperties;
26
+ };
27
+ onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
28
+ tabIndex?: number;
29
+ /** The content of the component. */
30
+ children: React.ReactNode;
31
+ }
32
+
33
+ function TabContainer(props: TabContainerProps): React.JSX.Element {
34
+ return (
35
+ <Paper
36
+ elevation={!Number.isNaN(props.elevation) ? props.elevation : 1}
37
+ style={{
38
+ ...styles.root,
39
+ ...(props.styles?.root || undefined),
40
+ ...(props.overflow !== 'visible' ? styles.overflowHidden : undefined),
41
+ }}
42
+ onKeyDown={props.onKeyDown}
43
+ tabIndex={props.tabIndex}
44
+ >
45
+ <Grid2
46
+ container
47
+ direction="column"
48
+ wrap="nowrap"
49
+ sx={styles.container}
50
+ >
51
+ {props.children}
52
+ </Grid2>
53
+ </Paper>
54
+ );
55
+ }
56
+
57
+ export default TabContainer;
@@ -1,123 +1,163 @@
1
- import React, { type JSX } from 'react';
2
-
3
- import { Button, DialogTitle, DialogContent, DialogActions, Dialog } from '@mui/material';
4
-
5
- import { Check as IconOk, Cancel as IconCancel, Delete as IconClear } from '@mui/icons-material';
6
-
7
- import ComplexCron from '../Components/ComplexCron';
8
-
9
- import I18n from '../i18n';
10
-
11
- // Generate cron expression
12
- const styles: Record<string, React.CSSProperties> = {
13
- headerID: {
14
- fontWeight: 'bold',
15
- fontStyle: 'italic',
16
- },
17
- radio: {
18
- display: 'inline-block',
19
- },
20
- dialogPaper: {
21
- height: 'calc(100% - 96px)',
22
- },
23
- };
24
-
25
- interface DialogCronProps {
26
- onClose: () => void;
27
- onOk: (cron: string | false) => void;
28
- title?: string;
29
- cron?: string;
30
- cancel?: string;
31
- ok?: string;
32
- clear?: string;
33
- clearButton?: boolean;
34
- }
35
-
36
- interface DialogCronState {
37
- cron: string;
38
- }
39
-
40
- class DialogComplexCron extends React.Component<DialogCronProps, DialogCronState> {
41
- constructor(props: DialogCronProps) {
42
- super(props);
43
- let cron;
44
- if (this.props.cron && typeof this.props.cron === 'string' && this.props.cron.replace(/^["']/, '')[0] !== '{') {
45
- cron = this.props.cron.replace(/['"]/g, '').trim();
46
- } else {
47
- cron = this.props.cron || '{}';
48
- if (typeof cron === 'string') {
49
- cron = cron.replace(/^["']/, '').replace(/["']\n?$/, '');
50
- }
51
- }
52
-
53
- this.state = {
54
- cron,
55
- };
56
- }
57
-
58
- handleCancel(): void {
59
- this.props.onClose();
60
- }
61
-
62
- handleOk(): void {
63
- this.props.onOk(this.state.cron);
64
- this.props.onClose();
65
- }
66
-
67
- handleClear(): void {
68
- this.props.onOk(false);
69
- this.props.onClose();
70
- }
71
-
72
- render(): JSX.Element {
73
- return (
74
- <Dialog
75
- onClose={() => {}}
76
- maxWidth="md"
77
- fullWidth
78
- sx={{ '& .MuiDialog-paper': styles.dialogPaper }}
79
- open={!0}
80
- aria-labelledby="cron-dialog-title"
81
- >
82
- <DialogTitle id="cron-dialog-title">{this.props.title || I18n.t('ra_Define schedule...')}</DialogTitle>
83
- <DialogContent style={{ height: '100%', overflow: 'hidden' }}>
84
- <ComplexCron
85
- cronExpression={this.state.cron}
86
- onChange={cron => this.setState({ cron })}
87
- language={I18n.getLanguage()}
88
- />
89
- </DialogContent>
90
- <DialogActions>
91
- {!!this.props.clearButton && (
92
- <Button
93
- color="grey"
94
- variant="contained"
95
- onClick={() => this.handleClear()}
96
- startIcon={<IconClear />}
97
- >
98
- {this.props.clear || I18n.t('ra_Clear')}
99
- </Button>
100
- )}
101
- <Button
102
- variant="contained"
103
- onClick={() => this.handleOk()}
104
- color="primary"
105
- startIcon={<IconOk />}
106
- >
107
- {this.props.ok || I18n.t('ra_Ok')}
108
- </Button>
109
- <Button
110
- color="grey"
111
- variant="contained"
112
- onClick={() => this.handleCancel()}
113
- startIcon={<IconCancel />}
114
- >
115
- {this.props.cancel || I18n.t('ra_Cancel')}
116
- </Button>
117
- </DialogActions>
118
- </Dialog>
119
- );
120
- }
121
- }
122
-
123
- export default DialogComplexCron;
1
+ import React, { type JSX } from 'react';
2
+
3
+ import { Button, DialogTitle, DialogContent, DialogActions, Dialog } from '@mui/material';
4
+
5
+ import { Check as IconOk, Cancel as IconCancel, Delete as IconClear } from '@mui/icons-material';
6
+
7
+ import ComplexCron from '../Components/ComplexCron';
8
+ import ConfirmDialog from '../Dialogs/Confirm';
9
+
10
+ import I18n from '../i18n';
11
+
12
+ // Generate cron expression
13
+ const styles: Record<string, React.CSSProperties> = {
14
+ headerID: {
15
+ fontWeight: 'bold',
16
+ fontStyle: 'italic',
17
+ },
18
+ radio: {
19
+ display: 'inline-block',
20
+ },
21
+ dialogPaper: {
22
+ height: 'calc(100% - 96px)',
23
+ },
24
+ };
25
+
26
+ interface DialogCronProps {
27
+ onClose: () => void;
28
+ onOk: (cron: string | false) => void;
29
+ title?: string;
30
+ cron?: string;
31
+ cancel?: string;
32
+ ok?: string;
33
+ clear?: string;
34
+ clearButton?: boolean;
35
+ }
36
+
37
+ interface DialogCronState {
38
+ cron: string;
39
+ showWarning: '' | 'everySecond' | 'everyMinute';
40
+ }
41
+
42
+ class DialogComplexCron extends React.Component<DialogCronProps, DialogCronState> {
43
+ constructor(props: DialogCronProps) {
44
+ super(props);
45
+ let cron;
46
+ if (this.props.cron && typeof this.props.cron === 'string' && this.props.cron.replace(/^["']/, '')[0] !== '{') {
47
+ cron = this.props.cron.replace(/['"]/g, '').trim();
48
+ } else {
49
+ cron = this.props.cron || '{}';
50
+ if (typeof cron === 'string') {
51
+ cron = cron.replace(/^["']/, '').replace(/["']\n?$/, '');
52
+ }
53
+ }
54
+
55
+ this.state = {
56
+ showWarning: '',
57
+ cron,
58
+ };
59
+ }
60
+
61
+ handleCancel(): void {
62
+ this.props.onClose();
63
+ }
64
+
65
+ handleOk(ignoreCheck?: boolean): void {
66
+ if (!ignoreCheck) {
67
+ // Check if the CRON will be executed every second or every minute and warn about it
68
+ const cron = ComplexCron.cron2state(this.state.cron);
69
+ if (cron.seconds === '*' || cron.seconds === '*/1') {
70
+ this.setState({ showWarning: 'everySecond' });
71
+ return;
72
+ }
73
+ if (cron.minutes === '*' || cron.minutes === '*/1') {
74
+ this.setState({ showWarning: 'everyMinute' });
75
+ return;
76
+ }
77
+ }
78
+
79
+ this.props.onOk(this.state.cron);
80
+ this.props.onClose();
81
+ }
82
+
83
+ renderWarningDialog(): JSX.Element | null {
84
+ if (!this.state.showWarning) {
85
+ return null;
86
+ }
87
+ return (
88
+ <ConfirmDialog
89
+ title={I18n.t('ra_Please confirm')}
90
+ text={I18n.t(
91
+ this.state.showWarning === 'everySecond'
92
+ ? 'ra_The schedule will be executed every second. Are you sure?'
93
+ : 'ra_The schedule will be executed every minute. Are you sure?',
94
+ )}
95
+ onClose={(ok: boolean) =>
96
+ this.setState({ showWarning: '' }, () => {
97
+ if (ok) {
98
+ this.handleOk(true);
99
+ }
100
+ })
101
+ }
102
+ />
103
+ );
104
+ }
105
+
106
+ handleClear(): void {
107
+ this.props.onOk(false);
108
+ this.props.onClose();
109
+ }
110
+
111
+ render(): JSX.Element {
112
+ return (
113
+ <Dialog
114
+ onClose={() => {}}
115
+ maxWidth="md"
116
+ fullWidth
117
+ sx={{ '& .MuiDialog-paper': styles.dialogPaper }}
118
+ open={!0}
119
+ aria-labelledby="cron-dialog-title"
120
+ >
121
+ {this.renderWarningDialog()}
122
+ <DialogTitle id="cron-dialog-title">{this.props.title || I18n.t('ra_Define schedule...')}</DialogTitle>
123
+ <DialogContent style={{ height: '100%', overflow: 'hidden' }}>
124
+ <ComplexCron
125
+ cronExpression={this.state.cron}
126
+ onChange={cron => this.setState({ cron })}
127
+ language={I18n.getLanguage()}
128
+ />
129
+ </DialogContent>
130
+ <DialogActions>
131
+ {!!this.props.clearButton && (
132
+ <Button
133
+ color="grey"
134
+ variant="contained"
135
+ onClick={() => this.handleClear()}
136
+ startIcon={<IconClear />}
137
+ >
138
+ {this.props.clear || I18n.t('ra_Clear')}
139
+ </Button>
140
+ )}
141
+ <Button
142
+ variant="contained"
143
+ onClick={() => this.handleOk()}
144
+ color="primary"
145
+ startIcon={<IconOk />}
146
+ >
147
+ {this.props.ok || I18n.t('ra_Ok')}
148
+ </Button>
149
+ <Button
150
+ color="grey"
151
+ variant="contained"
152
+ onClick={() => this.handleCancel()}
153
+ startIcon={<IconCancel />}
154
+ >
155
+ {this.props.cancel || I18n.t('ra_Cancel')}
156
+ </Button>
157
+ </DialogActions>
158
+ </Dialog>
159
+ );
160
+ }
161
+ }
162
+
163
+ export default DialogComplexCron;
package/tasks.js CHANGED
@@ -1,91 +1,91 @@
1
- /**
2
- * Copyright 2024 bluefox <dogafox@gmail.com>
3
- *
4
- * MIT License
5
- *
6
- **/
7
- 'use strict';
8
-
9
- const fs = require('node:fs');
10
- const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
11
-
12
- const SRC = 'src';
13
-
14
- function copyAllFiles() {
15
- deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
16
-
17
- copyFiles(
18
- [
19
- `${SRC}/build/*`,
20
- `!${SRC}/build/index.html`,
21
- `!${SRC}/build/static/js/main.*.chunk.js`,
22
- `!${SRC}/build/static/media/*.svg`,
23
- `!${SRC}/build/static/media/*.txt`,
24
- `!${SRC}/build/i18n/*`,
25
- `!${SRC}/build/i18n`,
26
- ],
27
- 'admin',
28
- );
29
-
30
- copyFiles(`${SRC}/build/index.html`, 'admin');
31
-
32
- copyFiles(`${SRC}/build/static/js/main.*.chunk.js`, 'admin/static/js');
33
- }
34
-
35
- function clean() {
36
- deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
37
- deleteFoldersRecursive(`${SRC}/build`);
38
- }
39
-
40
- function installNpmLocal() {
41
- if (fs.existsSync(`${SRC}/node_modules`)) {
42
- return Promise.resolve();
43
- }
44
- return npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`);
45
- }
46
-
47
- function patchFiles() {
48
- if (fs.existsSync(`${__dirname}/admin/index.html`)) {
49
- let code = fs.readFileSync(`${__dirname}/admin/index.html`).toString('utf8');
50
- code = code.replace(
51
- /<script>var script=document\.createElement\("script"\).+?<\/script>/,
52
- `<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
53
- );
54
-
55
- fs.writeFileSync(`${__dirname}/admin/index.html`, code);
56
- }
57
- if (fs.existsSync(`${__dirname}/${SRC}/build/index.html`)) {
58
- let code = fs.readFileSync(`${__dirname}/${SRC}/build/index.html`).toString('utf8');
59
- code = code.replace(
60
- /<script>var script=document\.createElement\("script"\).+?<\/script>/,
61
- `<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
62
- );
63
-
64
- fs.writeFileSync(`${SRC}/build/index.html`, code);
65
- }
66
- }
67
-
68
- if (process.argv.find(arg => arg === '--0-clean')) {
69
- clean();
70
- } else if (process.argv.find(arg => arg === '--1-npm')) {
71
- npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`).catch(e => {
72
- console.error(`Cannot install: ${e}`);
73
- process.exit(1);
74
- });
75
- } else if (process.argv.find(arg => arg === '--2-build')) {
76
- buildReact(SRC, { rootDir: __dirname }).catch(e => {
77
- console.error(`Cannot build: ${e}`);
78
- process.exit(1);
79
- });
80
- } else if (process.argv.find(arg => arg === '--3-copy')) {
81
- copyAllFiles();
82
- } else if (process.argv.find(arg => arg === '--4-patch')) {
83
- patchFiles();
84
- } else {
85
- clean();
86
-
87
- installNpmLocal()
88
- .then(() => buildReact(SRC, { rootDir: __dirname }))
89
- .then(() => copyAllFiles())
90
- .then(() => patchFiles());
91
- }
1
+ /**
2
+ * Copyright 2024 bluefox <dogafox@gmail.com>
3
+ *
4
+ * MIT License
5
+ *
6
+ */
7
+ 'use strict';
8
+
9
+ const fs = require('node:fs');
10
+ const { deleteFoldersRecursive, npmInstall, buildReact, copyFiles } = require('@iobroker/build-tools');
11
+
12
+ const SRC = 'src';
13
+
14
+ function copyAllFiles() {
15
+ deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
16
+
17
+ copyFiles(
18
+ [
19
+ `${SRC}/build/*`,
20
+ `!${SRC}/build/index.html`,
21
+ `!${SRC}/build/static/js/main.*.chunk.js`,
22
+ `!${SRC}/build/static/media/*.svg`,
23
+ `!${SRC}/build/static/media/*.txt`,
24
+ `!${SRC}/build/i18n/*`,
25
+ `!${SRC}/build/i18n`,
26
+ ],
27
+ 'admin',
28
+ );
29
+
30
+ copyFiles(`${SRC}/build/index.html`, 'admin');
31
+
32
+ copyFiles(`${SRC}/build/static/js/main.*.chunk.js`, 'admin/static/js');
33
+ }
34
+
35
+ function clean() {
36
+ deleteFoldersRecursive('admin', ['.png', '.json', 'i18n']);
37
+ deleteFoldersRecursive(`${SRC}/build`);
38
+ }
39
+
40
+ function installNpmLocal() {
41
+ if (fs.existsSync(`${SRC}/node_modules`)) {
42
+ return Promise.resolve();
43
+ }
44
+ return npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`);
45
+ }
46
+
47
+ function patchFiles() {
48
+ if (fs.existsSync(`${__dirname}/admin/index.html`)) {
49
+ let code = fs.readFileSync(`${__dirname}/admin/index.html`).toString('utf8');
50
+ code = code.replace(
51
+ /<script>var script=document\.createElement\("script"\).+?<\/script>/,
52
+ `<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
53
+ );
54
+
55
+ fs.writeFileSync(`${__dirname}/admin/index.html`, code);
56
+ }
57
+ if (fs.existsSync(`${__dirname}/${SRC}/build/index.html`)) {
58
+ let code = fs.readFileSync(`${__dirname}/${SRC}/build/index.html`).toString('utf8');
59
+ code = code.replace(
60
+ /<script>var script=document\.createElement\("script"\).+?<\/script>/,
61
+ `<script type="text/javascript" src="./../../lib/js/socket.io.js"></script>`,
62
+ );
63
+
64
+ fs.writeFileSync(`${SRC}/build/index.html`, code);
65
+ }
66
+ }
67
+
68
+ if (process.argv.find(arg => arg === '--0-clean')) {
69
+ clean();
70
+ } else if (process.argv.find(arg => arg === '--1-npm')) {
71
+ npmInstall(`${__dirname.replace(/\\/g, '/')}/${SRC}/`).catch(e => {
72
+ console.error(`Cannot install: ${e}`);
73
+ process.exit(1);
74
+ });
75
+ } else if (process.argv.find(arg => arg === '--2-build')) {
76
+ buildReact(SRC, { rootDir: __dirname }).catch(e => {
77
+ console.error(`Cannot build: ${e}`);
78
+ process.exit(1);
79
+ });
80
+ } else if (process.argv.find(arg => arg === '--3-copy')) {
81
+ copyAllFiles();
82
+ } else if (process.argv.find(arg => arg === '--4-patch')) {
83
+ patchFiles();
84
+ } else {
85
+ clean();
86
+
87
+ installNpmLocal()
88
+ .then(() => buildReact(SRC, { rootDir: __dirname }))
89
+ .then(() => copyAllFiles())
90
+ .then(() => patchFiles());
91
+ }