@iobroker/json-config 7.6.17 → 7.6.19

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,5 @@
1
1
  import React from 'react';
2
- import { InputLabel, FormHelperText, FormControl, Select, MenuItem, ListSubheader, Box, Chip, ListItemText, Checkbox, } from '@mui/material';
2
+ import { InputLabel, FormHelperText, FormControl, Select, MenuItem, ListSubheader, Chip, ListItemText, Checkbox, } from '@mui/material';
3
3
  import { I18n } from '@iobroker/adapter-react-v5';
4
4
  import ConfigGeneric from './ConfigGeneric';
5
5
  const styles = {
@@ -34,11 +34,13 @@ class ConfigSelect extends ConfigGeneric {
34
34
  label: this.getText(item.label, this.props.schema.noTranslation),
35
35
  value: item.value,
36
36
  group: true,
37
+ color: item.color,
37
38
  });
38
39
  groupItem.items.forEach(it => selectOptions.push({
39
40
  label: this.getText(it.label, this.props.schema.noTranslation),
40
41
  value: it.value,
41
42
  hidden: it.hidden,
43
+ color: item.color,
42
44
  }));
43
45
  }
44
46
  else {
@@ -46,6 +48,7 @@ class ConfigSelect extends ConfigGeneric {
46
48
  label: this.getText(item.label, this.props.schema.noTranslation),
47
49
  value: item.value,
48
50
  hidden: item.hidden,
51
+ color: item.color,
49
52
  });
50
53
  }
51
54
  });
@@ -94,14 +97,14 @@ class ConfigSelect extends ConfigGeneric {
94
97
  const item = this.props.schema.multiple ? null : selectOptions.find(it => it.value == value); // let "==" be and not ===
95
98
  return (React.createElement(FormControl, { variant: "standard", fullWidth: true, sx: this.props.table !== undefined && styles.noMargin, id: `jsonSelect_${this.props.attr}_${this.props.index || this.props.index === 0 ? this.props.index : ''}` },
96
99
  this.props.schema.label ? React.createElement(InputLabel, null, this.getText(this.props.schema.label)) : null,
97
- React.createElement(Select, { variant: "standard", error: !!error, multiple: this.props.schema.multiple, disabled: !!disabled, value: value || '_', renderValue: (val) => this.props.schema.multiple ? (React.createElement(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, val.map((v) => {
100
+ React.createElement(Select, { variant: "standard", error: !!error, multiple: this.props.schema.multiple, disabled: !!disabled, value: value || '_', renderValue: (val) => this.props.schema.multiple ? (React.createElement("div", { style: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, val.map((v) => {
98
101
  const it = selectOptions.find(_item => _item.value === v);
99
102
  if (it || this.props.schema.showAllValues !== false) {
100
103
  const label = it?.label || v;
101
104
  return (React.createElement(Chip, { key: v, label: label }));
102
105
  }
103
106
  return null;
104
- }))) : ((item?.label === undefined ? val : item.label)), onChange: e => {
107
+ }))) : item?.color ? (React.createElement("div", { style: { color: item.color } }, item?.label === undefined ? val : item.label)) : item?.label === undefined ? (val) : (item.label), onChange: e => {
105
108
  this.setState({ value: e.target.value === '_' ? '' : e.target.value }, () => {
106
109
  let mayBePromise;
107
110
  if (this.state.value === ConfigGeneric.DIFFERENT_VALUE) {
@@ -116,7 +119,7 @@ class ConfigSelect extends ConfigGeneric {
116
119
  });
117
120
  } }, selectOptions.map((it, i) => {
118
121
  if (it.group) {
119
- return (React.createElement(ListSubheader, { key: i }, it.label));
122
+ return (React.createElement(ListSubheader, { key: i, style: { color: it.color } }, it.label));
120
123
  }
121
124
  return (React.createElement(MenuItem, { key: i, value: it.value, style: it.value === ConfigGeneric.DIFFERENT_VALUE ? { opacity: 0.5 } : {} },
122
125
  this.props.schema.multiple ? (React.createElement(Checkbox, { checked: value.includes(it.value), onClick: () => {
@@ -131,7 +134,7 @@ class ConfigSelect extends ConfigGeneric {
131
134
  }
132
135
  this.setState({ value: _value }, () => this.onChange(this.props.attr, _value));
133
136
  } })) : null,
134
- React.createElement(ListItemText, { primary: it.label })));
137
+ React.createElement(ListItemText, { primary: it.label, style: { color: it.color } })));
135
138
  })),
136
139
  this.props.schema.help ? (React.createElement(FormHelperText, null, this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation))) : null));
137
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Config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CACjB,CAAC;IACN,CAAC;CACJ;AAED,eAAe,YAAY,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport {\n InputLabel,\n FormHelperText,\n FormControl,\n Select,\n MenuItem,\n ListSubheader,\n Box,\n Chip,\n ListItemText, Checkbox,\n} from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemSelect, ConfigItemSelectOption } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, any> = {\n fullWidth: {\n width: '100%',\n },\n noMargin: {\n '&>div': {\n marginTop: 0,\n },\n },\n};\n\ninterface ConfigInstanceSelectProps extends ConfigGenericProps {\n schema: ConfigItemSelect;\n}\n\ninterface ConfigInstanceSelectState extends ConfigGenericState {\n selectOptions?: { label: string; value: number | string; group?: boolean; hidden?: string | boolean }[];\n}\n\nclass ConfigSelect extends ConfigGeneric<ConfigInstanceSelectProps, ConfigInstanceSelectState> {\n private initialValue: string | string[] = '';\n\n componentDidMount(): void {\n super.componentDidMount();\n let value: string | string[] = ConfigGeneric.getValue(this.props.data, this.props.attr);\n\n if (this.props.schema.multiple) {\n if (typeof value === 'string') {\n value = [value];\n } else if (value === null || value === undefined) {\n value = [];\n }\n }\n\n const selectOptions: {\n label: string;\n value: number | string;\n group?: boolean;\n hidden?: string | boolean;\n }[] = [];\n\n (this.props.schema.options || []).forEach(item => {\n // if optgroup\n const groupItem: {\n items: ConfigItemSelectOption[];\n label: ioBroker.StringOrTranslated;\n value?: number | string;\n hidden?: string | boolean;\n } = item as {\n items: ConfigItemSelectOption[];\n label: ioBroker.StringOrTranslated;\n value?: number | string;\n hidden?: string | boolean;\n };\n if (Array.isArray(groupItem.items)) {\n selectOptions.push({\n label: this.getText(item.label, this.props.schema.noTranslation),\n value: item.value,\n group: true,\n });\n groupItem.items.forEach(it =>\n selectOptions.push({\n label: this.getText(it.label, this.props.schema.noTranslation),\n value: it.value,\n hidden: it.hidden,\n }),\n );\n } else {\n selectOptions.push({\n label: this.getText(item.label, this.props.schema.noTranslation),\n value: item.value,\n hidden: item.hidden,\n });\n }\n });\n\n // if __different\n if (Array.isArray(value) && !this.props.schema.multiple) {\n this.initialValue = [...value];\n selectOptions.unshift({\n label: I18n.t(ConfigGeneric.DIFFERENT_LABEL),\n value: ConfigGeneric.DIFFERENT_VALUE,\n });\n this.setState({ value: ConfigGeneric.DIFFERENT_VALUE, selectOptions });\n } else {\n this.setState({ value, selectOptions });\n }\n }\n\n _getValue(): string | string[] {\n let value =\n this.state.value === null || this.state.value === undefined\n ? ConfigGeneric.getValue(this.props.data, this.props.attr)\n : this.state.value;\n\n if (this.props.schema.multiple) {\n if (typeof value === 'string') {\n value = [value];\n } else if (value === null || value === undefined) {\n value = [];\n }\n }\n\n return value;\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n if (!this.state.selectOptions) {\n return null;\n }\n\n const selectOptions = (this.state.selectOptions || []).filter(item => {\n // if optgroup or no hidden function\n if (!item.hidden) {\n return true;\n }\n\n if (this.props.custom) {\n return !this.executeCustom(\n item.hidden,\n this.props.data,\n this.props.customObj,\n this.props.oContext.instanceObj,\n this.props.arrayIndex,\n this.props.globalData,\n );\n }\n return !this.execute(\n item.hidden,\n this.props.schema.default,\n this.props.data,\n this.props.arrayIndex,\n this.props.globalData,\n );\n });\n\n const value = this._getValue();\n\n const item = this.props.schema.multiple ? null : selectOptions.find(it => it.value == value); // let \"==\" be and not ===\n\n return (\n <FormControl\n variant=\"standard\"\n fullWidth\n sx={this.props.table !== undefined && styles.noMargin}\n id={`jsonSelect_${this.props.attr}_${this.props.index || this.props.index === 0 ? this.props.index : ''}`}\n >\n {this.props.schema.label ? <InputLabel>{this.getText(this.props.schema.label)}</InputLabel> : null}\n <Select\n variant=\"standard\"\n error={!!error}\n multiple={this.props.schema.multiple}\n disabled={!!disabled}\n value={value || '_'}\n renderValue={(val: string | string[]) =>\n this.props.schema.multiple ? (\n <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>\n {(val as string[]).map((v: string) => {\n const it = selectOptions.find(_item => _item.value === v);\n if (it || this.props.schema.showAllValues !== false) {\n const label = it?.label || v;\n return (\n <Chip\n key={v}\n label={label}\n />\n );\n }\n return null;\n })}\n </Box>\n ) : (\n (item?.label === undefined ? val : item.label)\n )\n }\n onChange={e => {\n this.setState({ value: e.target.value === '_' ? '' : e.target.value }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.state.value === ConfigGeneric.DIFFERENT_VALUE) {\n mayBePromise = this.onChange(this.props.attr, this.initialValue);\n } else {\n mayBePromise = this.onChange(this.props.attr, this.state.value);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n >\n {selectOptions.map((it, i) => {\n if (it.group) {\n return (\n <ListSubheader key={i}>\n {it.label}\n </ListSubheader>\n );\n }\n return (\n <MenuItem\n key={i}\n value={it.value}\n style={it.value === ConfigGeneric.DIFFERENT_VALUE ? { opacity: 0.5 } : {}}\n >\n {this.props.schema.multiple ? (\n <Checkbox\n checked={value.includes(it.value as string)}\n onClick={() => {\n const _value = JSON.parse(JSON.stringify(this._getValue()));\n const pos = value.indexOf(it.value as string);\n if (pos !== -1) {\n _value.splice(pos, 1);\n } else {\n _value.push(it.value);\n _value.sort();\n }\n this.setState({ value: _value }, () =>\n this.onChange(this.props.attr, _value),\n );\n }}\n />\n ) : null}\n <ListItemText primary={it.label} />\n </MenuItem>\n );\n })}\n </Select>\n {this.props.schema.help ? (\n <FormHelperText>\n {this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n </FormHelperText>\n ) : null}\n </FormControl>\n );\n }\n}\n\nexport default ConfigSelect;\n"]}
1
+ {"version":3,"file":"ConfigSelect.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAEx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CAAC;YACN,CAAC,CAAC,CACG;YACR,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CACtB,oBAAC,cAAc,QACV,IAAI,CAAC,UAAU,CACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,CACY,CACpB,CAAC,CAAC,CAAC,IAAI,CACE,CACjB,CAAC;IACN,CAAC;CACJ;AAED,eAAe,YAAY,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport {\n InputLabel,\n FormHelperText,\n FormControl,\n Select,\n MenuItem,\n ListSubheader,\n Box,\n Chip,\n ListItemText,\n Checkbox,\n} from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemSelect, ConfigItemSelectOption } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, any> = {\n fullWidth: {\n width: '100%',\n },\n noMargin: {\n '&>div': {\n marginTop: 0,\n },\n },\n};\n\ninterface ConfigInstanceSelectProps extends ConfigGenericProps {\n schema: ConfigItemSelect;\n}\n\ninterface ConfigInstanceSelectState extends ConfigGenericState {\n selectOptions?: {\n label: string;\n value: number | string;\n group?: boolean;\n hidden?: string | boolean;\n color?: string;\n }[];\n}\n\nclass ConfigSelect extends ConfigGeneric<ConfigInstanceSelectProps, ConfigInstanceSelectState> {\n private initialValue: string | string[] = '';\n\n componentDidMount(): void {\n super.componentDidMount();\n let value: string | string[] = ConfigGeneric.getValue(this.props.data, this.props.attr);\n\n if (this.props.schema.multiple) {\n if (typeof value === 'string') {\n value = [value];\n } else if (value === null || value === undefined) {\n value = [];\n }\n }\n\n const selectOptions: {\n label: string;\n value: number | string;\n group?: boolean;\n hidden?: string | boolean;\n color?: string;\n }[] = [];\n\n (this.props.schema.options || []).forEach(item => {\n // if optgroup\n const groupItem: {\n items: ConfigItemSelectOption[];\n label: ioBroker.StringOrTranslated;\n value?: number | string;\n hidden?: string | boolean;\n } = item as {\n items: ConfigItemSelectOption[];\n label: ioBroker.StringOrTranslated;\n value?: number | string;\n hidden?: string | boolean;\n };\n if (Array.isArray(groupItem.items)) {\n selectOptions.push({\n label: this.getText(item.label, this.props.schema.noTranslation),\n value: item.value,\n group: true,\n color: item.color,\n });\n groupItem.items.forEach(it =>\n selectOptions.push({\n label: this.getText(it.label, this.props.schema.noTranslation),\n value: it.value,\n hidden: it.hidden,\n color: item.color,\n }),\n );\n } else {\n selectOptions.push({\n label: this.getText(item.label, this.props.schema.noTranslation),\n value: item.value,\n hidden: item.hidden,\n color: item.color,\n });\n }\n });\n\n // if __different\n if (Array.isArray(value) && !this.props.schema.multiple) {\n this.initialValue = [...value];\n selectOptions.unshift({\n label: I18n.t(ConfigGeneric.DIFFERENT_LABEL),\n value: ConfigGeneric.DIFFERENT_VALUE,\n });\n this.setState({ value: ConfigGeneric.DIFFERENT_VALUE, selectOptions });\n } else {\n this.setState({ value, selectOptions });\n }\n }\n\n _getValue(): string | string[] {\n let value =\n this.state.value === null || this.state.value === undefined\n ? ConfigGeneric.getValue(this.props.data, this.props.attr)\n : this.state.value;\n\n if (this.props.schema.multiple) {\n if (typeof value === 'string') {\n value = [value];\n } else if (value === null || value === undefined) {\n value = [];\n }\n }\n\n return value;\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n if (!this.state.selectOptions) {\n return null;\n }\n\n const selectOptions = (this.state.selectOptions || []).filter(item => {\n // if optgroup or no hidden function\n if (!item.hidden) {\n return true;\n }\n\n if (this.props.custom) {\n return !this.executeCustom(\n item.hidden,\n this.props.data,\n this.props.customObj,\n this.props.oContext.instanceObj,\n this.props.arrayIndex,\n this.props.globalData,\n );\n }\n return !this.execute(\n item.hidden,\n this.props.schema.default,\n this.props.data,\n this.props.arrayIndex,\n this.props.globalData,\n );\n });\n\n const value = this._getValue();\n\n const item = this.props.schema.multiple ? null : selectOptions.find(it => it.value == value); // let \"==\" be and not ===\n\n return (\n <FormControl\n variant=\"standard\"\n fullWidth\n sx={this.props.table !== undefined && styles.noMargin}\n id={`jsonSelect_${this.props.attr}_${this.props.index || this.props.index === 0 ? this.props.index : ''}`}\n >\n {this.props.schema.label ? <InputLabel>{this.getText(this.props.schema.label)}</InputLabel> : null}\n <Select\n variant=\"standard\"\n error={!!error}\n multiple={this.props.schema.multiple}\n disabled={!!disabled}\n value={value || '_'}\n renderValue={(val: string | string[]) =>\n this.props.schema.multiple ? (\n <div style={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>\n {(val as string[]).map((v: string) => {\n const it = selectOptions.find(_item => _item.value === v);\n if (it || this.props.schema.showAllValues !== false) {\n const label = it?.label || v;\n return (\n <Chip\n key={v}\n label={label}\n />\n );\n }\n return null;\n })}\n </div>\n ) : item?.color ? (\n <div style={{ color: item.color }}>{item?.label === undefined ? val : item.label}</div>\n ) : item?.label === undefined ? (\n val\n ) : (\n item.label\n )\n }\n onChange={e => {\n this.setState({ value: e.target.value === '_' ? '' : e.target.value }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.state.value === ConfigGeneric.DIFFERENT_VALUE) {\n mayBePromise = this.onChange(this.props.attr, this.initialValue);\n } else {\n mayBePromise = this.onChange(this.props.attr, this.state.value);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n >\n {selectOptions.map((it, i) => {\n if (it.group) {\n return (\n <ListSubheader\n key={i}\n style={{ color: it.color }}\n >\n {it.label}\n </ListSubheader>\n );\n }\n return (\n <MenuItem\n key={i}\n value={it.value}\n style={it.value === ConfigGeneric.DIFFERENT_VALUE ? { opacity: 0.5 } : {}}\n >\n {this.props.schema.multiple ? (\n <Checkbox\n checked={value.includes(it.value as string)}\n onClick={() => {\n const _value = JSON.parse(JSON.stringify(this._getValue()));\n const pos = value.indexOf(it.value as string);\n if (pos !== -1) {\n _value.splice(pos, 1);\n } else {\n _value.push(it.value);\n _value.sort();\n }\n this.setState({ value: _value }, () =>\n this.onChange(this.props.attr, _value),\n );\n }}\n />\n ) : null}\n <ListItemText\n primary={it.label}\n style={{ color: it.color }}\n />\n </MenuItem>\n );\n })}\n </Select>\n {this.props.schema.help ? (\n <FormHelperText>\n {this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n </FormHelperText>\n ) : null}\n </FormControl>\n );\n }\n}\n\nexport default ConfigSelect;\n"]}
@@ -1,17 +1,12 @@
1
1
  import React from 'react';
2
2
  import { Button } from '@mui/material';
3
3
  import { Warning as IconWarning, Error as IconError, Info as IconInfo } from '@mui/icons-material';
4
- import { DialogConfirm, Icon, I18n } from '@iobroker/adapter-react-v5';
4
+ import { DialogConfirm, I18n } from '@iobroker/adapter-react-v5';
5
5
  import ConfigGeneric from './ConfigGeneric';
6
6
  const styles = {
7
7
  fullWidth: {
8
8
  width: '100%',
9
9
  },
10
- icon: {
11
- width: 24,
12
- height: 24,
13
- marginRight: 4,
14
- },
15
10
  };
16
11
  class ConfigSetState extends ConfigGeneric {
17
12
  async _onClick() {
@@ -61,6 +56,7 @@ class ConfigSetState extends ConfigGeneric {
61
56
  return (React.createElement(DialogConfirm, { title: this.getText(confirm.title) || I18n.t('ra_Please confirm'), text: this.getText(confirm.text), ok: this.getText(confirm.ok) || I18n.t('ra_Ok'), cancel: this.getText(confirm.cancel) || I18n.t('ra_Cancel'), icon: icon, onClose: isOk => this.setState({ confirmDialog: false }, () => isOk && this._onClick()) }));
62
57
  }
63
58
  renderItem(_error, disabled /* , defaultValue */) {
59
+ const icon = this.getIcon();
64
60
  return (React.createElement(Button, { variant: this.props.schema.variant || undefined, color: this.props.schema.color || 'grey', style: styles.fullWidth, disabled: disabled, onClick: async () => {
65
61
  if (this.props.schema.confirm) {
66
62
  this.setState({ confirmDialog: true });
@@ -68,9 +64,7 @@ class ConfigSetState extends ConfigGeneric {
68
64
  else {
69
65
  await this._onClick();
70
66
  }
71
- } },
72
- this.props.schema.icon ? (React.createElement(Icon, { src: this.props.schema.icon, style: styles.icon })) : null,
73
- this.getText(this.props.schema.label, this.props.schema.noTranslation)));
67
+ }, startIcon: icon || undefined }, this.getText(this.props.schema.label, this.props.schema.noTranslation)));
74
68
  }
75
69
  }
76
70
  export default ConfigSetState;
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigSetState.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigSetState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,IAAI,SAAS,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,SAAS,EAAE;QACP,KAAK,EAAE,MAAM;KAChB;IACD,IAAI,EAAE;QACF,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,CAAC;KACjB;CACJ,CAAC;AAMF,MAAM,cAAe,SAAQ,aAA4D;IACrF,KAAK,CAAC,QAAQ;QACV,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAChC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YACvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,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,CAAC,aAAa,CAAC,CAClE,CACZ,CAAC;IACN,CAAC;CACJ;AAED,eAAe,cAAc,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Button } from '@mui/material';\n\nimport { Warning as IconWarning, Error as IconError, Info as IconInfo } from '@mui/icons-material';\n\nimport { DialogConfirm, Icon, I18n } from '@iobroker/adapter-react-v5';\nimport type { ConfigItemSetState } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n icon: {\n width: 24,\n height: 24,\n marginRight: 4,\n },\n};\n\ninterface ConfigInstanceSelectProps extends ConfigGenericProps {\n schema: ConfigItemSetState;\n}\n\nclass ConfigSetState extends ConfigGeneric<ConfigInstanceSelectProps, ConfigGenericState> {\n async _onClick(): Promise<void> {\n let val = this.props.schema.val;\n if (typeof val === 'string' && val.includes('${')) {\n val = this.getPattern(val, null, true);\n const obj = await this.props.oContext.socket.getObject(this.props.schema.id);\n if (obj?.common?.type === 'number') {\n val = parseFloat(val);\n } else if (obj?.common?.type === 'boolean') {\n // @ts-expect-error val could be anything\n val = val === 'true' || val === true || val === '1' || val === 1;\n }\n }\n\n const id = (this.props.schema.id || '').replace(/%INSTANCE%/g, (this.props.oContext.instance || 0).toString());\n\n try {\n await this.props.oContext.socket.setState(id, { val, ack: !!this.props.schema.ack });\n if (this.props.schema.okText) {\n window.alert(this.getText(this.props.schema.okText));\n }\n } catch (e) {\n if (this.props.schema.error && this.props.schema.error[e.toString()]) {\n window.alert(this.getText(this.props.schema.error[e.toString()]));\n } else {\n window.alert(I18n.t(e.toString()) || I18n.t('ra_Error'));\n }\n }\n }\n\n renderDialogConfirm(): JSX.Element | null {\n if (!this.state.confirmDialog) {\n return null;\n }\n const confirm = this.state.confirmData || this.props.schema.confirm;\n let icon = null;\n if (confirm.type === 'warning') {\n icon = <IconWarning />;\n } else if (confirm.type === 'error') {\n icon = <IconError />;\n } else if (confirm.type === 'info') {\n icon = <IconInfo />;\n }\n\n return (\n <DialogConfirm\n title={this.getText(confirm.title) || I18n.t('ra_Please confirm')}\n text={this.getText(confirm.text)}\n ok={this.getText(confirm.ok) || I18n.t('ra_Ok')}\n cancel={this.getText(confirm.cancel) || I18n.t('ra_Cancel')}\n icon={icon}\n onClose={isOk => this.setState({ confirmDialog: false }, () => isOk && this._onClick())}\n />\n );\n }\n\n renderItem(_error: string, disabled: boolean /* , defaultValue */): JSX.Element | null {\n return (\n <Button\n variant={this.props.schema.variant || undefined}\n color={this.props.schema.color || 'grey'}\n style={styles.fullWidth}\n disabled={disabled}\n onClick={async () => {\n if (this.props.schema.confirm) {\n this.setState({ confirmDialog: true });\n } else {\n await this._onClick();\n }\n }}\n >\n {this.props.schema.icon ? (\n <Icon\n src={this.props.schema.icon}\n style={styles.icon}\n />\n ) : null}\n {this.getText(this.props.schema.label, this.props.schema.noTranslation)}\n </Button>\n );\n }\n}\n\nexport default ConfigSetState;\n"]}
1
+ {"version":3,"file":"ConfigSetState.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigSetState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,IAAI,SAAS,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAE,aAAa,EAAQ,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,SAAS,EAAE;QACP,KAAK,EAAE,MAAM;KAChB;CACJ,CAAC;AAMF,MAAM,cAAe,SAAQ,aAA4D;IACrF,KAAK,CAAC,QAAQ;QACV,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;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EAAE,IAAI,IAAI,SAAS,IAE3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAClE,CACZ,CAAC;IACN,CAAC;CACJ;AAED,eAAe,cAAc,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Button } from '@mui/material';\n\nimport { Warning as IconWarning, Error as IconError, Info as IconInfo } from '@mui/icons-material';\n\nimport { DialogConfirm, Icon, I18n } from '@iobroker/adapter-react-v5';\nimport type { ConfigItemSetState } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n};\n\ninterface ConfigInstanceSelectProps extends ConfigGenericProps {\n schema: ConfigItemSetState;\n}\n\nclass ConfigSetState extends ConfigGeneric<ConfigInstanceSelectProps, ConfigGenericState> {\n async _onClick(): Promise<void> {\n let val = this.props.schema.val;\n if (typeof val === 'string' && val.includes('${')) {\n val = this.getPattern(val, null, true);\n const obj = await this.props.oContext.socket.getObject(this.props.schema.id);\n if (obj?.common?.type === 'number') {\n val = parseFloat(val);\n } else if (obj?.common?.type === 'boolean') {\n // @ts-expect-error val could be anything\n val = val === 'true' || val === true || val === '1' || val === 1;\n }\n }\n\n const id = (this.props.schema.id || '').replace(/%INSTANCE%/g, (this.props.oContext.instance || 0).toString());\n\n try {\n await this.props.oContext.socket.setState(id, { val, ack: !!this.props.schema.ack });\n if (this.props.schema.okText) {\n window.alert(this.getText(this.props.schema.okText));\n }\n } catch (e) {\n if (this.props.schema.error && this.props.schema.error[e.toString()]) {\n window.alert(this.getText(this.props.schema.error[e.toString()]));\n } else {\n window.alert(I18n.t(e.toString()) || I18n.t('ra_Error'));\n }\n }\n }\n\n renderDialogConfirm(): JSX.Element | null {\n if (!this.state.confirmDialog) {\n return null;\n }\n const confirm = this.state.confirmData || this.props.schema.confirm;\n let icon = null;\n if (confirm.type === 'warning') {\n icon = <IconWarning />;\n } else if (confirm.type === 'error') {\n icon = <IconError />;\n } else if (confirm.type === 'info') {\n icon = <IconInfo />;\n }\n\n return (\n <DialogConfirm\n title={this.getText(confirm.title) || I18n.t('ra_Please confirm')}\n text={this.getText(confirm.text)}\n ok={this.getText(confirm.ok) || I18n.t('ra_Ok')}\n cancel={this.getText(confirm.cancel) || I18n.t('ra_Cancel')}\n icon={icon}\n onClose={isOk => this.setState({ confirmDialog: false }, () => isOk && this._onClick())}\n />\n );\n }\n\n renderItem(_error: string, disabled: boolean /* , defaultValue */): JSX.Element | null {\n const icon = this.getIcon();\n return (\n <Button\n variant={this.props.schema.variant || undefined}\n color={this.props.schema.color || 'grey'}\n style={styles.fullWidth}\n disabled={disabled}\n onClick={async () => {\n if (this.props.schema.confirm) {\n this.setState({ confirmDialog: true });\n } else {\n await this._onClick();\n }\n }}\n startIcon={icon || undefined}\n >\n {this.getText(this.props.schema.label, this.props.schema.noTranslation)}\n </Button>\n );\n }\n}\n\nexport default ConfigSetState;\n"]}
@@ -19,7 +19,13 @@ declare class ConfigState extends ConfigGeneric<ConfigStateProps, ConfigStateSta
19
19
  componentDidMount(): Promise<void>;
20
20
  componentWillUnmount(): void;
21
21
  onStateChanged: (_id: string, state: ioBroker.State | null | undefined) => void;
22
- detectType(obj: ioBroker.StateObject): 'button' | 'switch' | 'slider' | 'input' | 'text';
22
+ detectType(obj: ioBroker.StateObject): 'button' | 'switch' | 'slider' | 'input' | 'text' | 'select';
23
+ getNormalizedStates(): {
24
+ label: string;
25
+ value: number | string;
26
+ hidden?: string | boolean;
27
+ color?: string;
28
+ }[];
23
29
  renderItem(_error: string, disabled: boolean): JSX.Element;
24
30
  }
25
31
  export default ConfigState;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { TextField, IconButton, Button, Switch, Slider, Box } from '@mui/material';
2
+ import { TextField, IconButton, Button, Switch, Slider, Box, FormControl, InputLabel, Select, MenuItem, } from '@mui/material';
3
3
  import { I18n, Icon } from '@iobroker/adapter-react-v5';
4
4
  import getIconByName from './Icons';
5
5
  import ConfigGeneric from './ConfigGeneric';
@@ -51,6 +51,20 @@ class ConfigState extends ConfigGeneric {
51
51
  async componentDidMount() {
52
52
  super.componentDidMount();
53
53
  const obj = (await this.props.oContext.socket.getObject(this.getObjectID()));
54
+ if (obj?.common?.states && !this.props.schema.options) {
55
+ // Normalize states to object
56
+ if (Array.isArray(obj?.common?.states)) {
57
+ // convert array to object
58
+ const states = {};
59
+ obj.common.states.forEach((state, index) => {
60
+ states[index.toString()] = state;
61
+ });
62
+ obj.common.states = states;
63
+ }
64
+ if (!Object.keys(obj.common.states).length) {
65
+ obj.common.states = undefined; // remove empty states
66
+ }
67
+ }
54
68
  const controlType = this.props.schema.control || this.detectType(obj);
55
69
  try {
56
70
  const state = await this.props.oContext.socket.getState(this.getObjectID());
@@ -109,8 +123,8 @@ class ConfigState extends ConfigGeneric {
109
123
  }
110
124
  };
111
125
  detectType(obj) {
112
- obj = obj || {};
113
- obj.common = obj.common || {};
126
+ obj ||= {};
127
+ obj.common ||= {};
114
128
  // read an object
115
129
  if (obj.common.type === 'boolean') {
116
130
  if (this.props.schema.controlled !== false) {
@@ -125,6 +139,9 @@ class ConfigState extends ConfigGeneric {
125
139
  }
126
140
  if (obj.common.type === 'number' && this.props.schema.controlled !== false) {
127
141
  if (obj.common.write || this.props.schema.controlled === true) {
142
+ if (obj.common.states || this.props.schema.options) {
143
+ return 'select';
144
+ }
128
145
  if (obj.common.max !== undefined) {
129
146
  return 'slider';
130
147
  }
@@ -133,16 +150,70 @@ class ConfigState extends ConfigGeneric {
133
150
  return 'text';
134
151
  }
135
152
  if (obj.common.write && this.props.schema.controlled !== false) {
153
+ if (obj.common.states || this.props.schema.options) {
154
+ return 'select';
155
+ }
136
156
  return 'input';
137
157
  }
138
158
  return 'text';
139
159
  }
160
+ getNormalizedStates() {
161
+ let states;
162
+ if (this.props.schema.options) {
163
+ states = this.props.schema.options.map(state => {
164
+ if (typeof state === 'string') {
165
+ return { value: state, label: this.getText(state, this.props.schema.noTranslation) };
166
+ }
167
+ return {
168
+ value: state.value,
169
+ label: this.getText(state.label, this.props.schema.noTranslation),
170
+ color: state.color,
171
+ };
172
+ });
173
+ }
174
+ else if (this.state.obj.common.states) {
175
+ states = [];
176
+ Object.keys(this.state.obj.common.states).forEach(key => {
177
+ states.push({
178
+ value: key,
179
+ label: this.getText(this.state.obj.common.states[key], this.props.schema.noTranslation),
180
+ });
181
+ });
182
+ }
183
+ else {
184
+ states = [];
185
+ }
186
+ return states;
187
+ }
140
188
  renderItem(_error, disabled /*, defaultValue */) {
141
189
  if (!this.state.obj) {
142
190
  return null;
143
191
  }
144
192
  let content;
145
- if (this.state.controlType === 'button' ||
193
+ if (this.state.controlType === 'select' ||
194
+ (!this.state.controlType &&
195
+ (this.state.obj.common.type === 'number' || this.state.obj.common.type === 'string') &&
196
+ this.state.obj.common.write !== false &&
197
+ (this.props.schema.options || this.state.obj.common.states))) {
198
+ const states = this.getNormalizedStates();
199
+ const item = states.find(it => it.value === this.state.stateValue);
200
+ content = (React.createElement(FormControl, { fullWidth: true },
201
+ React.createElement(InputLabel, null,
202
+ "$",
203
+ this.getText(this.props.schema.label)),
204
+ React.createElement(Select, { value: this.state.stateValue, disabled: !!this.props.schema.readOnly || disabled, onChange: e => {
205
+ this.setState({ stateValue: e.target.value }, () => {
206
+ let value = this.state.stateValue;
207
+ if (this.state.obj.common.type === 'number') {
208
+ value = parseFloat(value.toString().replace(',', '.'));
209
+ }
210
+ void this.props.oContext.socket.setState(this.getObjectID(), value, false);
211
+ });
212
+ }, renderValue: (val) => item?.color ? React.createElement("div", { style: { color: item.color } }, item.label) : val }, states.map(item => (React.createElement(MenuItem, { key: (item.value ?? '').toString(), value: item.value, style: { color: item.color } },
213
+ "$",
214
+ item.label))))));
215
+ }
216
+ else if (this.state.controlType === 'button' ||
146
217
  (!this.state.controlType &&
147
218
  this.state.obj.common.type === 'boolean' &&
148
219
  ((this.state.obj.common.write && this.state.obj.common.read === false) ||
@@ -194,7 +265,7 @@ class ConfigState extends ConfigGeneric {
194
265
  else if (this.state.controlType === 'input' ||
195
266
  (!this.state.controlType && this.state.obj.common.write && this.state.obj.common.type === 'string')) {
196
267
  content = (React.createElement("div", { style: { width: '100%', display: 'flex', flexDirection: 'row', gap: 8, alignItems: 'baseline' } },
197
- React.createElement(TextField, { style: { flex: 1 }, value: this.state.stateValue, variant: "standard", slotProps: {
268
+ React.createElement(TextField, { style: { flex: 1 }, value: this.state.stateValue, variant: "standard", disabled: !!this.props.schema.readOnly || disabled, slotProps: {
198
269
  input: {
199
270
  endAdornment: this.getText(this.props.schema.unit, this.props.schema.noTranslation) ||
200
271
  this.state.obj.common.unit ||
@@ -217,11 +288,15 @@ class ConfigState extends ConfigGeneric {
217
288
  }
218
289
  this.controlTimeout = setTimeout(async () => {
219
290
  this.controlTimeout = null;
220
- await this.props.oContext.socket.setState(this.getObjectID(), this.state.stateValue, false);
291
+ let value = this.state.stateValue;
292
+ if (this.state.obj.common.type === 'number') {
293
+ value = parseFloat(value.toString().replace(',', '.'));
294
+ }
295
+ await this.props.oContext.socket.setState(this.getObjectID(), value, false);
221
296
  }, this.props.schema.controlDelay || 0);
222
297
  });
223
298
  }, label: this.getText(this.props.schema.label), helperText: this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation) }),
224
- this.props.schema.showEnterButton && (React.createElement(Button, { variant: "outlined", onClick: () => {
299
+ this.props.schema.showEnterButton && !this.props.schema.readOnly && (React.createElement(Button, { variant: "outlined", disabled: disabled, onClick: () => {
225
300
  void this.props.oContext.socket.setState(this.getObjectID(), this.state.stateValue, false);
226
301
  } }, this.getText(typeof this.props.schema.showEnterButton === 'string'
227
302
  ? this.props.schema.showEnterButton
@@ -289,7 +364,7 @@ class ConfigState extends ConfigGeneric {
289
364
  if (this.props.schema.trueImage) {
290
365
  iconTrue = getIconByName(this.props.schema.trueImage, textTrue ? { marginRight: 8 } : undefined);
291
366
  }
292
- content = (React.createElement(Switch, { checked: !!this.state.stateValue, disabled: !!this.props.schema.readOnly, onChange: async () => {
367
+ content = (React.createElement(Switch, { checked: !!this.state.stateValue, disabled: !!this.props.schema.readOnly || disabled, onChange: async () => {
293
368
  if (this.props.schema.confirm) {
294
369
  this.setState({
295
370
  confirmDialog: true,
@@ -345,7 +420,7 @@ class ConfigState extends ConfigGeneric {
345
420
  : this.state.obj.common.max
346
421
  : this.props.schema.max;
347
422
  const step = this.props.schema.step === undefined ? this.state.obj.common.step || 1 : this.props.schema.step;
348
- content = (React.createElement(Slider, { style: { width: '100%', flexGrow: 1 }, min: min, max: max, disabled: !!this.props.schema.readOnly, step: step, value: this.state.stateValue, valueLabelDisplay: "auto", valueLabelFormat: (value) => `${value}${this.getText(this.props.schema.unit, this.props.schema.noTranslation) || this.state.obj.common.unit || ''}`, onChange: (_e, value) => {
423
+ content = (React.createElement(Slider, { style: { width: '100%', flexGrow: 1 }, min: min, max: max, disabled: !!this.props.schema.readOnly || disabled, step: step, value: this.state.stateValue, valueLabelDisplay: "auto", valueLabelFormat: (value) => `${value}${this.getText(this.props.schema.unit, this.props.schema.noTranslation) || this.state.obj.common.unit || ''}`, onChange: (_e, value) => {
349
424
  this.setState({ stateValue: value }, () => {
350
425
  if (this.controlTimeout) {
351
426
  clearTimeout(this.controlTimeout);
@@ -378,7 +453,7 @@ class ConfigState extends ConfigGeneric {
378
453
  content));
379
454
  }
380
455
  }
381
- else if (this.state.obj.common.type === 'number' && this.state.obj.common.write) {
456
+ else if (this.state.obj.common.type === 'number' && this.state.obj.common.write && !this.state.controlType) {
382
457
  // Auto-detection of the type
383
458
  const min = this.props.schema.min === undefined
384
459
  ? this.state.obj.common.min === undefined
@@ -395,7 +470,7 @@ class ConfigState extends ConfigGeneric {
395
470
  ? undefined
396
471
  : this.state.obj.common.step
397
472
  : this.props.schema.step;
398
- content = (React.createElement(TextField, { variant: "standard", style: { width: '100%' }, value: this.state.stateValue, type: "number", slotProps: {
473
+ content = (React.createElement(TextField, { variant: "standard", style: { width: '100%' }, value: this.state.stateValue, type: "number", disabled: !!this.props.schema.readOnly || disabled, slotProps: {
399
474
  htmlInput: { min, max, step, readOnly: !!this.props.schema.readOnly },
400
475
  input: {
401
476
  endAdornment: this.getText(this.props.schema.unit, this.props.schema.noTranslation) ||
@@ -443,11 +518,22 @@ class ConfigState extends ConfigGeneric {
443
518
  else {
444
519
  // text or HTML
445
520
  const unit = this.getText(this.props.schema.unit, this.props.schema.noTranslation) || this.state.obj.common.unit;
521
+ let mappedValue = this.state.stateValue;
522
+ // if options or states are defined, map the value to the label
523
+ if (mappedValue !== null &&
524
+ mappedValue !== undefined &&
525
+ (this.props.schema.options || this.state.obj.common.states)) {
526
+ const states = this.getNormalizedStates();
527
+ const state = states.find(s => s.value === mappedValue);
528
+ if (state) {
529
+ mappedValue = state.label;
530
+ }
531
+ }
446
532
  let value;
447
533
  let key;
448
534
  if (this.state.controlType === 'html') {
449
- key = (this.state.stateValue || '').toString();
450
- value = React.createElement("span", { dangerouslySetInnerHTML: { __html: this.state.stateValue } });
535
+ key = (mappedValue || '').toString();
536
+ value = React.createElement("span", { dangerouslySetInnerHTML: { __html: mappedValue } });
451
537
  }
452
538
  else if (this.state.stateValue === null) {
453
539
  value = 'null';
@@ -458,7 +544,7 @@ class ConfigState extends ConfigGeneric {
458
544
  key = value;
459
545
  }
460
546
  else {
461
- value = this.state.stateValue.toString();
547
+ value = mappedValue.toString();
462
548
  key = value;
463
549
  }
464
550
  content = (React.createElement("div", { style: divStyle },