@iobroker/adapter-react-v5 2.1.10 → 3.0.1

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.
Files changed (86) hide show
  1. package/Components/FileBrowser.js +248 -222
  2. package/Components/FileBrowser.js.map +1 -1
  3. package/Components/FileViewer.js +219 -75
  4. package/Components/FileViewer.js.map +1 -1
  5. package/Components/JsonConfigComponent/ChipInput.js +926 -0
  6. package/Components/JsonConfigComponent/ChipInput.js.map +1 -0
  7. package/Components/JsonConfigComponent/ConfigAlive.js +135 -0
  8. package/Components/JsonConfigComponent/ConfigAlive.js.map +1 -0
  9. package/Components/JsonConfigComponent/ConfigAutocomplete.js +204 -0
  10. package/Components/JsonConfigComponent/ConfigAutocomplete.js.map +1 -0
  11. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js +311 -0
  12. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -0
  13. package/Components/JsonConfigComponent/ConfigCRON.js +195 -0
  14. package/Components/JsonConfigComponent/ConfigCRON.js.map +1 -0
  15. package/Components/JsonConfigComponent/ConfigCertificateSelect.js +178 -0
  16. package/Components/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -0
  17. package/Components/JsonConfigComponent/ConfigCheckbox.js +112 -0
  18. package/Components/JsonConfigComponent/ConfigCheckbox.js.map +1 -0
  19. package/Components/JsonConfigComponent/ConfigChip.js +149 -0
  20. package/Components/JsonConfigComponent/ConfigChip.js.map +1 -0
  21. package/Components/JsonConfigComponent/ConfigColor.js +156 -0
  22. package/Components/JsonConfigComponent/ConfigColor.js.map +1 -0
  23. package/Components/JsonConfigComponent/ConfigCoordinates.js +165 -0
  24. package/Components/JsonConfigComponent/ConfigCoordinates.js.map +1 -0
  25. package/Components/JsonConfigComponent/ConfigCustomEasyAccess.js +180 -0
  26. package/Components/JsonConfigComponent/ConfigCustomEasyAccess.js.map +1 -0
  27. package/Components/JsonConfigComponent/ConfigDatePicker.js +117 -0
  28. package/Components/JsonConfigComponent/ConfigDatePicker.js.map +1 -0
  29. package/Components/JsonConfigComponent/ConfigGeneric.js +660 -0
  30. package/Components/JsonConfigComponent/ConfigGeneric.js.map +1 -0
  31. package/Components/JsonConfigComponent/ConfigIP.js +151 -0
  32. package/Components/JsonConfigComponent/ConfigIP.js.map +1 -0
  33. package/Components/JsonConfigComponent/ConfigImageUpload.js +215 -0
  34. package/Components/JsonConfigComponent/ConfigImageUpload.js.map +1 -0
  35. package/Components/JsonConfigComponent/ConfigInstanceSelect.js +197 -0
  36. package/Components/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -0
  37. package/Components/JsonConfigComponent/ConfigJsonEditor.js +211 -0
  38. package/Components/JsonConfigComponent/ConfigJsonEditor.js.map +1 -0
  39. package/Components/JsonConfigComponent/ConfigLanguage.js +175 -0
  40. package/Components/JsonConfigComponent/ConfigLanguage.js.map +1 -0
  41. package/Components/JsonConfigComponent/ConfigNumber.js +194 -0
  42. package/Components/JsonConfigComponent/ConfigNumber.js.map +1 -0
  43. package/Components/JsonConfigComponent/ConfigObjectId.js +201 -0
  44. package/Components/JsonConfigComponent/ConfigObjectId.js.map +1 -0
  45. package/Components/JsonConfigComponent/ConfigPanel.js +421 -0
  46. package/Components/JsonConfigComponent/ConfigPanel.js.map +1 -0
  47. package/Components/JsonConfigComponent/ConfigPassword.js +236 -0
  48. package/Components/JsonConfigComponent/ConfigPassword.js.map +1 -0
  49. package/Components/JsonConfigComponent/ConfigPattern.js +94 -0
  50. package/Components/JsonConfigComponent/ConfigPattern.js.map +1 -0
  51. package/Components/JsonConfigComponent/ConfigSelect.js +163 -0
  52. package/Components/JsonConfigComponent/ConfigSelect.js.map +1 -0
  53. package/Components/JsonConfigComponent/ConfigSelectSendTo.js +258 -0
  54. package/Components/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -0
  55. package/Components/JsonConfigComponent/ConfigSendto.js +282 -0
  56. package/Components/JsonConfigComponent/ConfigSendto.js.map +1 -0
  57. package/Components/JsonConfigComponent/ConfigSetState.js +266 -0
  58. package/Components/JsonConfigComponent/ConfigSetState.js.map +1 -0
  59. package/Components/JsonConfigComponent/ConfigStaticDivider.js +88 -0
  60. package/Components/JsonConfigComponent/ConfigStaticDivider.js.map +1 -0
  61. package/Components/JsonConfigComponent/ConfigStaticHeader.js +81 -0
  62. package/Components/JsonConfigComponent/ConfigStaticHeader.js.map +1 -0
  63. package/Components/JsonConfigComponent/ConfigStaticImage.js +88 -0
  64. package/Components/JsonConfigComponent/ConfigStaticImage.js.map +1 -0
  65. package/Components/JsonConfigComponent/ConfigStaticText.js +104 -0
  66. package/Components/JsonConfigComponent/ConfigStaticText.js.map +1 -0
  67. package/Components/JsonConfigComponent/ConfigTable.js +651 -0
  68. package/Components/JsonConfigComponent/ConfigTable.js.map +1 -0
  69. package/Components/JsonConfigComponent/ConfigTabs.js +166 -0
  70. package/Components/JsonConfigComponent/ConfigTabs.js.map +1 -0
  71. package/Components/JsonConfigComponent/ConfigText.js +170 -0
  72. package/Components/JsonConfigComponent/ConfigText.js.map +1 -0
  73. package/Components/JsonConfigComponent/ConfigTextSendTo.js +168 -0
  74. package/Components/JsonConfigComponent/ConfigTextSendTo.js.map +1 -0
  75. package/Components/JsonConfigComponent/ConfigTimePicker.js +111 -0
  76. package/Components/JsonConfigComponent/ConfigTimePicker.js.map +1 -0
  77. package/Components/JsonConfigComponent/ConfigTopic.js +140 -0
  78. package/Components/JsonConfigComponent/ConfigTopic.js.map +1 -0
  79. package/Components/JsonConfigComponent/ConfigUser.js +176 -0
  80. package/Components/JsonConfigComponent/ConfigUser.js.map +1 -0
  81. package/Components/JsonConfigComponent/index.js +511 -0
  82. package/Components/JsonConfigComponent/index.js.map +1 -0
  83. package/Components/Utils.js +25 -0
  84. package/Components/Utils.js.map +1 -1
  85. package/README.md +7 -1
  86. package/package.json +1 -1
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _propTypes = _interopRequireDefault(require("prop-types"));
23
+
24
+ var _styles = require("@mui/styles");
25
+
26
+ var _InputLabel = _interopRequireDefault(require("@mui/material/InputLabel"));
27
+
28
+ var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
29
+
30
+ var _FormHelperText = _interopRequireDefault(require("@mui/material/FormHelperText"));
31
+
32
+ var _FormControl = _interopRequireDefault(require("@mui/material/FormControl"));
33
+
34
+ var _Select = _interopRequireDefault(require("@mui/material/Select"));
35
+
36
+ var _ConfigGeneric2 = _interopRequireDefault(require("./ConfigGeneric"));
37
+
38
+ var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
39
+
40
+ var _react = _interopRequireDefault(require("react"));
41
+
42
+ var _material = require("@mui/material");
43
+
44
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
45
+
46
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
47
+
48
+ var styles = function styles(theme) {
49
+ return {
50
+ fullWidth: {
51
+ width: '100%'
52
+ }
53
+ };
54
+ };
55
+ /*
56
+ to use this option, your adapter must implement listUart message
57
+
58
+ adapter.on('message', obj => {
59
+ if (obj) {
60
+ switch (obj.command) {
61
+ case 'command':
62
+ if (obj.callback) {
63
+ try {
64
+ const serialport = require('serialport');
65
+ if (serialport) {
66
+ // read all found serial ports
67
+ serialport.list()
68
+ .then(ports => {
69
+ adapter.log.info('List of port: ' + JSON.stringify(ports));
70
+ adapter.sendTo(obj.from, obj.command, ports.map(item =>
71
+ ({label: item.path, value: item.path})), obj.callback);
72
+ })
73
+ .catch(e => {
74
+ adapter.sendTo(obj.from, obj.command, [], obj.callback);
75
+ adapter.log.error(e)
76
+ });
77
+ } else {
78
+ adapter.log.warn('Module serialport is not available');
79
+ adapter.sendTo(obj.from, obj.command, [{label: 'Not available', value: ''}], obj.callback);
80
+ }
81
+ } catch (e) {
82
+ adapter.sendTo(obj.from, obj.command, [{label: 'Not available', value: ''}], obj.callback);
83
+ }
84
+ }
85
+
86
+ break;
87
+ }
88
+ }
89
+ });
90
+ */
91
+
92
+
93
+ var ConfigSelectSendTo = /*#__PURE__*/function (_ConfigGeneric) {
94
+ (0, _inherits2["default"])(ConfigSelectSendTo, _ConfigGeneric);
95
+
96
+ var _super = _createSuper(ConfigSelectSendTo);
97
+
98
+ function ConfigSelectSendTo() {
99
+ (0, _classCallCheck2["default"])(this, ConfigSelectSendTo);
100
+ return _super.apply(this, arguments);
101
+ }
102
+
103
+ (0, _createClass2["default"])(ConfigSelectSendTo, [{
104
+ key: "componentDidMount",
105
+ value: function componentDidMount() {
106
+ (0, _get2["default"])((0, _getPrototypeOf2["default"])(ConfigSelectSendTo.prototype), "componentDidMount", this).call(this);
107
+ this.askInstance();
108
+ }
109
+ }, {
110
+ key: "askInstance",
111
+ value: function askInstance() {
112
+ var _this = this;
113
+
114
+ if (this.props.alive) {
115
+ var data = this.props.schema.data;
116
+
117
+ if (data === undefined && this.props.schema.jsonData) {
118
+ data = this.getPattern(this.props.schema.jsonData, {}, this.props.data);
119
+
120
+ try {
121
+ data = JSON.parse(data);
122
+ } catch (e) {
123
+ console.error('Cannot parse json data: ' + data);
124
+ }
125
+ }
126
+
127
+ if (data === undefined) {
128
+ data = null;
129
+ }
130
+
131
+ this.props.socket.sendTo(this.props.adapterName + '.' + this.props.instance, this.props.schema.command || 'send', data).then(function (list) {
132
+ _this.setState({
133
+ list: list,
134
+ context: _this.getContext()
135
+ });
136
+ });
137
+ } else {
138
+ var value = _ConfigGeneric2["default"].getValue(this.props.data, this.props.attr);
139
+
140
+ this.setState({
141
+ value: value
142
+ });
143
+ }
144
+ }
145
+ }, {
146
+ key: "getContext",
147
+ value: function getContext() {
148
+ var _this2 = this;
149
+
150
+ var context = {};
151
+
152
+ if (Array.isArray(this.props.schema.alsoDependsOn)) {
153
+ this.props.schema.alsoDependsOn.forEach(function (attr) {
154
+ return context[attr] = _ConfigGeneric2["default"].getValue(_this2.props.data, attr);
155
+ });
156
+ }
157
+
158
+ return JSON.stringify(context);
159
+ }
160
+ }, {
161
+ key: "renderItem",
162
+ value: function renderItem(error, disabled, defaultValue) {
163
+ var _this3 = this;
164
+
165
+ if (this.props.alive) {
166
+ var context = this.getContext();
167
+
168
+ if (context !== this.state.context) {
169
+ setTimeout(function () {
170
+ _this3.askInstance();
171
+ }, 300);
172
+ }
173
+ }
174
+
175
+ if (!this.props.alive) {
176
+ return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
177
+ variant: "standard",
178
+ fullWidth: true,
179
+ value: this.state.value === null || this.state.value === undefined ? '' : this.state.value,
180
+ error: !!error,
181
+ disabled: !!disabled,
182
+ onChange: function onChange(e) {
183
+ var value = e.target.value;
184
+
185
+ _this3.setState({
186
+ value: value
187
+ }, function () {
188
+ return _this3.onChange(_this3.props.attr, (value || '').trim());
189
+ });
190
+ },
191
+ placeholder: this.getText(this.props.schema.placeholder),
192
+ label: this.getText(this.props.schema.label),
193
+ helperText: this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)
194
+ });
195
+ } else if (!this.state.list) {
196
+ return /*#__PURE__*/_react["default"].createElement(_material.CircularProgress, {
197
+ size: "small"
198
+ });
199
+ } else {
200
+ var value = _ConfigGeneric2["default"].getValue(this.props.data, this.props.attr);
201
+
202
+ var selectOptions = (this.state.list || []).filter(function (item) {
203
+ if (!item.hidden) {
204
+ return true;
205
+ } else if (_this3.props.custom) {
206
+ return !_this3.executeCustom(item.hidden, _this3.props.schema["default"], _this3.props.data, _this3.props.instanceObj);
207
+ } else {
208
+ return !_this3.execute(item.hidden, _this3.props.schema["default"], _this3.props.data);
209
+ }
210
+ });
211
+ var item = selectOptions.find(function (item) {
212
+ return item.value === value;
213
+ });
214
+ return /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
215
+ variant: "standard",
216
+ className: this.props.classes.fullWidth
217
+ }, /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], null, this.getText(this.props.schema.label)), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
218
+ variant: "standard",
219
+ error: !!error,
220
+ disabled: !!disabled,
221
+ value: value,
222
+ renderValue: function renderValue(val) {
223
+ return (item === null || item === void 0 ? void 0 : item.label) || val;
224
+ },
225
+ onChange: function onChange(e) {
226
+ return _this3.onChange(_this3.props.attr, e.target.value);
227
+ }
228
+ }, selectOptions.map(function (item, i) {
229
+ return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
230
+ key: i,
231
+ value: item.value
232
+ }, item.label);
233
+ })), this.props.schema.help ? /*#__PURE__*/_react["default"].createElement(_FormHelperText["default"], null, this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)) : null);
234
+ }
235
+ }
236
+ }]);
237
+ return ConfigSelectSendTo;
238
+ }(_ConfigGeneric2["default"]);
239
+
240
+ ConfigSelectSendTo.propTypes = {
241
+ socket: _propTypes["default"].object.isRequired,
242
+ themeType: _propTypes["default"].string,
243
+ themeName: _propTypes["default"].string,
244
+ style: _propTypes["default"].object,
245
+ adapterName: _propTypes["default"].string,
246
+ alive: _propTypes["default"].bool,
247
+ instance: _propTypes["default"].number,
248
+ className: _propTypes["default"].string,
249
+ data: _propTypes["default"].object.isRequired,
250
+ schema: _propTypes["default"].object,
251
+ onError: _propTypes["default"].func,
252
+ onChange: _propTypes["default"].func
253
+ };
254
+
255
+ var _default = (0, _styles.withStyles)(styles)(ConfigSelectSendTo);
256
+
257
+ exports["default"] = _default;
258
+ //# sourceMappingURL=ConfigSelectSendTo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigSelectSendTo.js","names":["styles","theme","fullWidth","width","ConfigSelectSendTo","askInstance","props","alive","data","schema","undefined","jsonData","getPattern","JSON","parse","e","console","error","socket","sendTo","adapterName","instance","command","then","list","setState","context","getContext","value","ConfigGeneric","getValue","attr","Array","isArray","alsoDependsOn","forEach","stringify","disabled","defaultValue","state","setTimeout","target","onChange","trim","getText","placeholder","label","renderHelp","help","helpLink","noTranslation","selectOptions","filter","item","hidden","custom","executeCustom","instanceObj","execute","find","classes","val","map","i","propTypes","PropTypes","object","isRequired","themeType","string","themeName","style","bool","number","className","onError","func","withStyles"],"sources":["JsonConfigComponent/ConfigSelectSendTo.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport { withStyles } from '@mui/styles';\n\nimport InputLabel from '@mui/material/InputLabel';\nimport MenuItem from '@mui/material/MenuItem';\nimport FormHelperText from '@mui/material/FormHelperText';\nimport FormControl from '@mui/material/FormControl';\nimport Select from '@mui/material/Select';\n\nimport ConfigGeneric from './ConfigGeneric';\nimport TextField from \"@mui/material/TextField\";\nimport React from \"react\";\nimport {CircularProgress} from \"@mui/material\";\n\nconst styles = theme => ({\n fullWidth: {\n width: '100%'\n }\n});\n\n/*\nto use this option, your adapter must implement listUart message\n\nadapter.on('message', obj => {\n if (obj) {\n switch (obj.command) {\n case 'command':\n if (obj.callback) {\n try {\n const serialport = require('serialport');\n if (serialport) {\n // read all found serial ports\n serialport.list()\n .then(ports => {\n adapter.log.info('List of port: ' + JSON.stringify(ports));\n adapter.sendTo(obj.from, obj.command, ports.map(item =>\n ({label: item.path, value: item.path})), obj.callback);\n })\n .catch(e => {\n adapter.sendTo(obj.from, obj.command, [], obj.callback);\n adapter.log.error(e)\n });\n } else {\n adapter.log.warn('Module serialport is not available');\n adapter.sendTo(obj.from, obj.command, [{label: 'Not available', value: ''}], obj.callback);\n }\n } catch (e) {\n adapter.sendTo(obj.from, obj.command, [{label: 'Not available', value: ''}], obj.callback);\n }\n }\n\n break;\n }\n }\n});\n */\n\nclass ConfigSelectSendTo extends ConfigGeneric {\n componentDidMount() {\n super.componentDidMount();\n\n this.askInstance();\n }\n\n askInstance(){\n if (this.props.alive) {\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n data = this.getPattern(this.props.schema.jsonData, {}, this.props.data);\n try {\n data = JSON.parse(data);\n } catch (e) {\n console.error('Cannot parse json data: ' + data);\n }\n }\n\n if (data === undefined) {\n data = null;\n }\n\n this.props.socket.sendTo(this.props.adapterName + '.' + this.props.instance, this.props.schema.command || 'send', data)\n .then(list => {\n this.setState({list, context: this.getContext()});\n });\n } else {\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.setState({value});\n }\n }\n\n getContext() {\n const context = {};\n if (Array.isArray(this.props.schema.alsoDependsOn)) {\n this.props.schema.alsoDependsOn.forEach(attr =>\n context[attr] = ConfigGeneric.getValue(this.props.data, attr));\n }\n return JSON.stringify(context);\n }\n\n renderItem(error, disabled, defaultValue) {\n if (this.props.alive) {\n const context = this.getContext();\n if (context !== this.state.context) {\n setTimeout(() => {\n this.askInstance();\n }, 300);\n }\n }\n\n if (!this.props.alive) {\n return <TextField\n variant=\"standard\"\n fullWidth\n value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}\n error={!!error}\n disabled={!!disabled}\n onChange={e => {\n const value = e.target.value;\n this.setState({value}, () =>\n this.onChange(this.props.attr, (value || '').trim()));\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}\n />;\n } else\n if (!this.state.list) {\n return <CircularProgress size=\"small\"/>;\n } else {\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n\n const selectOptions = (this.state.list || []).filter(item => {\n if (!item.hidden) {\n return true;\n } else if (this.props.custom) {\n return !this.executeCustom(item.hidden, this.props.schema.default, this.props.data, this.props.instanceObj);\n } else {\n return !this.execute(item.hidden, this.props.schema.default, this.props.data);\n }\n });\n\n const item = selectOptions.find(item => item.value === value);\n\n return <FormControl variant=\"standard\" className={this.props.classes.fullWidth}>\n <InputLabel>{this.getText(this.props.schema.label)}</InputLabel>\n <Select\n variant=\"standard\"\n error={!!error}\n disabled={!!disabled}\n value={value}\n renderValue={val => item?.label || val}\n onChange={e => this.onChange(this.props.attr, e.target.value)}\n >\n {selectOptions.map((item, i) =>\n <MenuItem key={i} value={item.value}>{item.label}</MenuItem>)}\n </Select>\n {this.props.schema.help ? <FormHelperText>{this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}</FormHelperText> : null}\n </FormControl>;\n }\n }\n}\n\nConfigSelectSendTo.propTypes = {\n socket: PropTypes.object.isRequired,\n themeType: PropTypes.string,\n themeName: PropTypes.string,\n style: PropTypes.object,\n adapterName: PropTypes.string,\n alive: PropTypes.bool,\n instance: PropTypes.number,\n className: PropTypes.string,\n data: PropTypes.object.isRequired,\n schema: PropTypes.object,\n onError: PropTypes.func,\n onChange: PropTypes.func,\n};\n\nexport default withStyles(styles)(ConfigSelectSendTo);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;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B,qBAAA,CAAUW;AAZO,CAA/B;;eAee,IAAAC,kBAAA,EAAW7E,MAAX,EAAmBI,kBAAnB,C"}
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _react = _interopRequireDefault(require("react"));
25
+
26
+ var _propTypes = _interopRequireDefault(require("prop-types"));
27
+
28
+ var _styles = require("@mui/styles");
29
+
30
+ var _Button = _interopRequireDefault(require("@mui/material/Button"));
31
+
32
+ var _i18n = _interopRequireDefault(require("@iobroker/adapter-react-v5/i18n"));
33
+
34
+ var _Icon = _interopRequireDefault(require("@iobroker/adapter-react-v5/Components/Icon"));
35
+
36
+ var _Error = _interopRequireDefault(require("@iobroker/adapter-react-v5/Dialogs/Error"));
37
+
38
+ var _Message = _interopRequireDefault(require("@iobroker/adapter-react-v5/Dialogs/Message"));
39
+
40
+ var _ConfigGeneric2 = _interopRequireDefault(require("./ConfigGeneric"));
41
+
42
+ var _Warning = _interopRequireDefault(require("@mui/icons-material/Warning"));
43
+
44
+ var _Error2 = _interopRequireDefault(require("@mui/icons-material/Error"));
45
+
46
+ var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
47
+
48
+ var _Confirm = _interopRequireDefault(require("@iobroker/adapter-react-v5/Dialogs/Confirm"));
49
+
50
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
51
+
52
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
53
+
54
+ var styles = function styles(theme) {
55
+ return {
56
+ fullWidth: {
57
+ width: '100%'
58
+ },
59
+ icon: {
60
+ width: 24,
61
+ height: 24,
62
+ marginRight: 4
63
+ }
64
+ };
65
+ };
66
+
67
+ var ConfigSendto = /*#__PURE__*/function (_ConfigGeneric) {
68
+ (0, _inherits2["default"])(ConfigSendto, _ConfigGeneric);
69
+
70
+ var _super = _createSuper(ConfigSendto);
71
+
72
+ function ConfigSendto() {
73
+ (0, _classCallCheck2["default"])(this, ConfigSendto);
74
+ return _super.apply(this, arguments);
75
+ }
76
+
77
+ (0, _createClass2["default"])(ConfigSendto, [{
78
+ key: "componentDidMount",
79
+ value: function componentDidMount() {
80
+ (0, _get2["default"])((0, _getPrototypeOf2["default"])(ConfigSendto.prototype), "componentDidMount", this).call(this);
81
+ this.setState({
82
+ _error: '',
83
+ _message: ''
84
+ });
85
+ }
86
+ }, {
87
+ key: "renderErrorDialog",
88
+ value: function renderErrorDialog() {
89
+ var _this = this;
90
+
91
+ if (this.state._error) {
92
+ return /*#__PURE__*/_react["default"].createElement(_Error["default"], {
93
+ text: this.state._error,
94
+ classes: undefined,
95
+ onClose: function onClose() {
96
+ return _this.setState({
97
+ _error: ''
98
+ });
99
+ }
100
+ });
101
+ } else {
102
+ return null;
103
+ }
104
+ }
105
+ }, {
106
+ key: "renderMessageDialog",
107
+ value: function renderMessageDialog() {
108
+ var _this2 = this;
109
+
110
+ if (this.state._message) {
111
+ return /*#__PURE__*/_react["default"].createElement(_Message["default"], {
112
+ text: this.state._message,
113
+ classes: undefined,
114
+ onClose: function onClose() {
115
+ return _this2.setState({
116
+ _error: ''
117
+ });
118
+ }
119
+ });
120
+ } else {
121
+ return null;
122
+ }
123
+ }
124
+ }, {
125
+ key: "_onClick",
126
+ value: function _onClick() {
127
+ var _this3 = this;
128
+
129
+ this.props.onCommandRunning(true);
130
+ var data = this.props.schema.data;
131
+
132
+ if (data === undefined && this.props.schema.jsonData) {
133
+ data = this.getPattern(this.props.schema.jsonData, {}, this.props.data);
134
+
135
+ try {
136
+ data = JSON.parse(data);
137
+ } catch (e) {
138
+ console.error('Cannot parse json data: ' + data);
139
+ }
140
+ }
141
+
142
+ if (data === undefined) {
143
+ data = null;
144
+ }
145
+
146
+ this.props.socket.sendTo(this.props.adapterName + '.' + this.props.instance, this.props.schema.command || 'send', data).then(function (response) {
147
+ if (response !== null && response !== void 0 && response.error) {
148
+ if (_this3.props.schema.error && _this3.props.schema.error[response.error]) {
149
+ var error = _this3.getText(_this3.props.schema.error[response.error]);
150
+
151
+ if (response.args) {
152
+ response.args.forEach(function (arg) {
153
+ return error = error.replace('%s', arg);
154
+ });
155
+ }
156
+
157
+ _this3.setState({
158
+ _error: error
159
+ });
160
+ } else {
161
+ _this3.setState({
162
+ _error: response.error ? _i18n["default"].t(response.error) : _i18n["default"].t('Error')
163
+ });
164
+ }
165
+ } else {
166
+ if (response !== null && response !== void 0 && response.result && _this3.props.schema.result && _this3.props.schema.result[response.result]) {
167
+ var text = _this3.getText(_this3.props.schema.result[response.result]);
168
+
169
+ if (response.args) {
170
+ response.args.forEach(function (arg) {
171
+ return text = text.replace('%s', arg);
172
+ });
173
+ }
174
+
175
+ window.alert(text);
176
+ } else {
177
+ if (response !== null && response !== void 0 && response.result) {
178
+ window.alert((0, _typeof2["default"])(response.result) === 'object' ? JSON.stringify(response.result) : response.result);
179
+ } else {
180
+ window.alert(_i18n["default"].t('Ok'));
181
+ }
182
+ }
183
+ }
184
+ })["catch"](function (e) {
185
+ if (_this3.props.schema.error && _this3.props.schema.error[e.toString()]) {
186
+ _this3.setState({
187
+ _error: _this3.getText(_this3.props.schema.error[e.toString()])
188
+ });
189
+ } else {
190
+ _this3.setState({
191
+ _error: _i18n["default"].t(e.toString()) || _i18n["default"].t('Error')
192
+ });
193
+ }
194
+ }).then(function () {
195
+ return _this3.props.onCommandRunning(false);
196
+ });
197
+ }
198
+ }, {
199
+ key: "renderConfirmDialog",
200
+ value: function renderConfirmDialog() {
201
+ var _this4 = this;
202
+
203
+ if (!this.state.confirmDialog) {
204
+ return null;
205
+ }
206
+
207
+ var confirm = this.state.confirmData || this.props.schema.confirm;
208
+ var icon = null;
209
+
210
+ if (confirm.type === 'warning') {
211
+ icon = /*#__PURE__*/_react["default"].createElement(_Warning["default"], null);
212
+ } else if (confirm.type === 'error') {
213
+ icon = /*#__PURE__*/_react["default"].createElement(_Error2["default"], null);
214
+ } else if (confirm.type === 'info') {
215
+ icon = /*#__PURE__*/_react["default"].createElement(_Info["default"], null);
216
+ }
217
+
218
+ return /*#__PURE__*/_react["default"].createElement(_Confirm["default"], {
219
+ title: this.getText(confirm.title) || _i18n["default"].t('Please confirm'),
220
+ text: this.getText(confirm.text),
221
+ ok: this.getText(confirm.ok) || _i18n["default"].t('Ok'),
222
+ cancel: this.getText(confirm.cancel) || _i18n["default"].t('Cancel'),
223
+ icon: icon,
224
+ onClose: function onClose(isOk) {
225
+ return _this4.setState({
226
+ confirmDialog: false
227
+ }, function () {
228
+ return isOk && _this4._onClick();
229
+ });
230
+ }
231
+ });
232
+ }
233
+ }, {
234
+ key: "renderItem",
235
+ value: function renderItem(error, disabled, defaultValue) {
236
+ var _this5 = this;
237
+
238
+ return /*#__PURE__*/_react["default"].createElement("div", {
239
+ className: this.props.classes.fullWidth
240
+ }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
241
+ variant: this.props.schema.variant || undefined,
242
+ color: this.props.schema.color || 'grey',
243
+ className: this.props.classes.fullWidth,
244
+ disabled: disabled,
245
+ onClick: function onClick() {
246
+ if (_this5.props.schema.confirm) {
247
+ _this5.setState({
248
+ confirmDialog: true
249
+ });
250
+ } else {
251
+ _this5._onClick();
252
+ }
253
+ }
254
+ }, this.props.schema.icon ? /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
255
+ src: this.props.schema.icon,
256
+ className: this.props.classes.icon
257
+ }) : null, this.getText(this.props.schema.label, this.props.schema.noTranslation)), this.renderErrorDialog(), this.renderMessageDialog());
258
+ }
259
+ }]);
260
+ return ConfigSendto;
261
+ }(_ConfigGeneric2["default"]);
262
+
263
+ ConfigSendto.propTypes = {
264
+ socket: _propTypes["default"].object.isRequired,
265
+ themeType: _propTypes["default"].string,
266
+ themeName: _propTypes["default"].string,
267
+ style: _propTypes["default"].object,
268
+ className: _propTypes["default"].string,
269
+ data: _propTypes["default"].object.isRequired,
270
+ schema: _propTypes["default"].object,
271
+ onError: _propTypes["default"].func,
272
+ onChange: _propTypes["default"].func,
273
+ adapterName: _propTypes["default"].string,
274
+ instance: _propTypes["default"].number,
275
+ commandRunning: _propTypes["default"].bool,
276
+ onCommandRunning: _propTypes["default"].func
277
+ };
278
+
279
+ var _default = (0, _styles.withStyles)(styles)(ConfigSendto);
280
+
281
+ exports["default"] = _default;
282
+ //# sourceMappingURL=ConfigSendto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigSendto.js","names":["styles","theme","fullWidth","width","icon","height","marginRight","ConfigSendto","setState","_error","_message","state","undefined","props","onCommandRunning","data","schema","jsonData","getPattern","JSON","parse","e","console","error","socket","sendTo","adapterName","instance","command","then","response","getText","args","forEach","arg","replace","I18n","t","result","text","window","alert","stringify","toString","confirmDialog","confirm","confirmData","type","title","ok","cancel","isOk","_onClick","disabled","defaultValue","classes","variant","color","label","noTranslation","renderErrorDialog","renderMessageDialog","ConfigGeneric","propTypes","PropTypes","object","isRequired","themeType","string","themeName","style","className","onError","func","onChange","number","commandRunning","bool","withStyles"],"sources":["JsonConfigComponent/ConfigSendto.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@mui/styles';\n\nimport Button from '@mui/material/Button';\n\nimport I18n from '@iobroker/adapter-react-v5/i18n';\nimport Icon from '@iobroker/adapter-react-v5/Components/Icon';\nimport DialogError from '@iobroker/adapter-react-v5/Dialogs/Error';\nimport DialogMessage from '@iobroker/adapter-react-v5/Dialogs/Message';\n\nimport ConfigGeneric from './ConfigGeneric';\nimport IconWarning from '@mui/icons-material/Warning';\nimport IconError from '@mui/icons-material/Error';\nimport IconInfo from '@mui/icons-material/Info';\nimport ConfirmDialog from '@iobroker/adapter-react-v5/Dialogs/Confirm';\n\nconst styles = theme => ({\n fullWidth: {\n width: '100%'\n },\n icon: {\n width: 24,\n height: 24,\n marginRight: 4\n }\n});\n\nclass ConfigSendto extends ConfigGeneric {\n componentDidMount() {\n super.componentDidMount();\n\n this.setState( {_error: '', _message: ''});\n }\n\n renderErrorDialog() {\n if (this.state._error) {\n return <DialogError text={this.state._error} classes={undefined} onClose={() => this.setState({_error: ''})} />;\n } else {\n return null;\n }\n }\n\n renderMessageDialog() {\n if (this.state._message) {\n return <DialogMessage text={this.state._message} classes={undefined} onClose={() => this.setState({_error: ''})} />;\n } else {\n return null;\n }\n }\n\n _onClick() {\n this.props.onCommandRunning(true);\n\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n data = this.getPattern(this.props.schema.jsonData, {}, this.props.data);\n try {\n data = JSON.parse(data);\n } catch (e) {\n console.error('Cannot parse json data: ' + data);\n }\n }\n if (data === undefined) {\n data = null;\n }\n\n this.props.socket.sendTo(\n this.props.adapterName + '.' + this.props.instance,\n this.props.schema.command || 'send',\n data\n )\n .then(response => {\n if (response?.error) {\n if (this.props.schema.error && this.props.schema.error[response.error]) {\n let error = this.getText(this.props.schema.error[response.error]);\n if (response.args) {\n response.args.forEach(arg => error = error.replace('%s', arg));\n }\n this.setState({_error: error});\n } else {\n this.setState({_error: response.error ? I18n.t(response.error) : I18n.t('Error')});\n }\n } else {\n if (response?.result && this.props.schema.result && this.props.schema.result[response.result]) {\n let text = this.getText(this.props.schema.result[response.result]);\n if (response.args) {\n response.args.forEach(arg => text = text.replace('%s', arg));\n }\n window.alert(text);\n } else {\n if (response?.result) {\n window.alert(typeof response.result === 'object' ? JSON.stringify(response.result) : response.result);\n } else {\n window.alert(I18n.t('Ok'));\n }\n }\n }\n })\n .catch(e => {\n if (this.props.schema.error && this.props.schema.error[e.toString()]) {\n this.setState({_error: this.getText(this.props.schema.error[e.toString()])});\n } else {\n this.setState({_error: I18n.t(e.toString()) || I18n.t('Error')});\n }\n })\n .then(() => this.props.onCommandRunning(false))\n }\n\n renderConfirmDialog() {\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 <ConfirmDialog\n title={ this.getText(confirm.title) || I18n.t('Please confirm') }\n text={ this.getText(confirm.text) }\n ok={ this.getText(confirm.ok) || I18n.t('Ok') }\n cancel={ this.getText(confirm.cancel) || I18n.t('Cancel') }\n icon={icon}\n onClose={isOk =>\n this.setState({ confirmDialog: false}, () =>\n isOk && this._onClick())\n }\n />;\n }\n\n renderItem(error, disabled, defaultValue) {\n return <div className={this.props.classes.fullWidth}>\n <Button\n variant={this.props.schema.variant || undefined}\n color={this.props.schema.color || 'grey'}\n className={this.props.classes.fullWidth}\n disabled={disabled}\n onClick={() => {\n if (this.props.schema.confirm) {\n this.setState({confirmDialog: true});\n } else {\n this._onClick();\n }\n }}\n >\n {this.props.schema.icon ? <Icon src={this.props.schema.icon} className={this.props.classes.icon}/> : null}\n {this.getText(this.props.schema.label, this.props.schema.noTranslation)}\n </Button>\n {this.renderErrorDialog()}\n {this.renderMessageDialog()}\n </div>;\n }\n}\n\nConfigSendto.propTypes = {\n socket: PropTypes.object.isRequired,\n themeType: PropTypes.string,\n themeName: PropTypes.string,\n style: PropTypes.object,\n className: PropTypes.string,\n data: PropTypes.object.isRequired,\n schema: PropTypes.object,\n onError: PropTypes.func,\n onChange: PropTypes.func,\n adapterName: PropTypes.string,\n instance: PropTypes.number,\n commandRunning: PropTypes.bool,\n onCommandRunning: PropTypes.func,\n};\n\nexport default withStyles(styles)(ConfigSendto);"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;EAAA,OAAK;IACrBC,SAAS,EAAE;MACPC,KAAK,EAAE;IADA,CADU;IAIrBC,IAAI,EAAE;MACFD,KAAK,EAAE,EADL;MAEFE,MAAM,EAAE,EAFN;MAGFC,WAAW,EAAE;IAHX;EAJe,CAAL;AAAA,CAApB;;IAWMC,Y;;;;;;;;;;;;WACF,6BAAoB;MAChB;MAEA,KAAKC,QAAL,CAAe;QAACC,MAAM,EAAE,EAAT;QAAaC,QAAQ,EAAE;MAAvB,CAAf;IACH;;;WAED,6BAAoB;MAAA;;MAChB,IAAI,KAAKC,KAAL,CAAWF,MAAf,EAAuB;QACnB,oBAAO,gCAAC,iBAAD;UAAa,IAAI,EAAE,KAAKE,KAAL,CAAWF,MAA9B;UAAsC,OAAO,EAAEG,SAA/C;UAA0D,OAAO,EAAE;YAAA,OAAM,KAAI,CAACJ,QAAL,CAAc;cAACC,MAAM,EAAE;YAAT,CAAd,CAAN;UAAA;QAAnE,EAAP;MACH,CAFD,MAEO;QAC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