@iobroker/json-config 1.0.0

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 (221) hide show
  1. package/LICENSE +21 -0
  2. package/build/JsonConfig.d.ts +22 -0
  3. package/build/JsonConfig.js +535 -0
  4. package/build/JsonConfig.js.map +1 -0
  5. package/build/JsonConfigComponent/ChipInput.d.ts +12 -0
  6. package/build/JsonConfigComponent/ChipInput.js +595 -0
  7. package/build/JsonConfigComponent/ChipInput.js.map +1 -0
  8. package/build/JsonConfigComponent/ConfigAccordion.d.ts +15 -0
  9. package/build/JsonConfigComponent/ConfigAccordion.js +185 -0
  10. package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -0
  11. package/build/JsonConfigComponent/ConfigAlive.d.ts +10 -0
  12. package/build/JsonConfigComponent/ConfigAlive.js +63 -0
  13. package/build/JsonConfigComponent/ConfigAlive.js.map +1 -0
  14. package/build/JsonConfigComponent/ConfigAutocomplete.d.ts +37 -0
  15. package/build/JsonConfigComponent/ConfigAutocomplete.js +69 -0
  16. package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -0
  17. package/build/JsonConfigComponent/ConfigAutocompleteSendTo.d.ts +17 -0
  18. package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js +127 -0
  19. package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -0
  20. package/build/JsonConfigComponent/ConfigCRON.d.ts +15 -0
  21. package/build/JsonConfigComponent/ConfigCRON.js +55 -0
  22. package/build/JsonConfigComponent/ConfigCRON.js.map +1 -0
  23. package/build/JsonConfigComponent/ConfigCertCollection.d.ts +14 -0
  24. package/build/JsonConfigComponent/ConfigCertCollection.js +50 -0
  25. package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -0
  26. package/build/JsonConfigComponent/ConfigCertificateSelect.d.ts +14 -0
  27. package/build/JsonConfigComponent/ConfigCertificateSelect.js +59 -0
  28. package/build/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -0
  29. package/build/JsonConfigComponent/ConfigCertificates.d.ts +14 -0
  30. package/build/JsonConfigComponent/ConfigCertificates.js +104 -0
  31. package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -0
  32. package/build/JsonConfigComponent/ConfigCheckLicense.d.ts +3 -0
  33. package/build/JsonConfigComponent/ConfigCheckLicense.js +546 -0
  34. package/build/JsonConfigComponent/ConfigCheckLicense.js.map +1 -0
  35. package/build/JsonConfigComponent/ConfigCheckbox.d.ts +15 -0
  36. package/build/JsonConfigComponent/ConfigCheckbox.js +36 -0
  37. package/build/JsonConfigComponent/ConfigCheckbox.js.map +1 -0
  38. package/build/JsonConfigComponent/ConfigChip.d.ts +14 -0
  39. package/build/JsonConfigComponent/ConfigChip.js +67 -0
  40. package/build/JsonConfigComponent/ConfigChip.js.map +1 -0
  41. package/build/JsonConfigComponent/ConfigColor.d.ts +22 -0
  42. package/build/JsonConfigComponent/ConfigColor.js +57 -0
  43. package/build/JsonConfigComponent/ConfigColor.js.map +1 -0
  44. package/build/JsonConfigComponent/ConfigCoordinates.d.ts +14 -0
  45. package/build/JsonConfigComponent/ConfigCoordinates.js +146 -0
  46. package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -0
  47. package/build/JsonConfigComponent/ConfigCustom.d.ts +26 -0
  48. package/build/JsonConfigComponent/ConfigCustom.js +195 -0
  49. package/build/JsonConfigComponent/ConfigCustom.js.map +1 -0
  50. package/build/JsonConfigComponent/ConfigDatePicker.d.ts +14 -0
  51. package/build/JsonConfigComponent/ConfigDatePicker.js +39 -0
  52. package/build/JsonConfigComponent/ConfigDatePicker.js.map +1 -0
  53. package/build/JsonConfigComponent/ConfigDeviceManager.d.ts +6 -0
  54. package/build/JsonConfigComponent/ConfigDeviceManager.js +14 -0
  55. package/build/JsonConfigComponent/ConfigDeviceManager.js.map +1 -0
  56. package/build/JsonConfigComponent/ConfigFile.d.ts +15 -0
  57. package/build/JsonConfigComponent/ConfigFile.js +131 -0
  58. package/build/JsonConfigComponent/ConfigFile.js.map +1 -0
  59. package/build/JsonConfigComponent/ConfigFileSelector.d.ts +3 -0
  60. package/build/JsonConfigComponent/ConfigFileSelector.js +434 -0
  61. package/build/JsonConfigComponent/ConfigFileSelector.js.map +1 -0
  62. package/build/JsonConfigComponent/ConfigFunc.d.ts +14 -0
  63. package/build/JsonConfigComponent/ConfigFunc.js +56 -0
  64. package/build/JsonConfigComponent/ConfigFunc.js.map +1 -0
  65. package/build/JsonConfigComponent/ConfigGeneric.d.ts +95 -0
  66. package/build/JsonConfigComponent/ConfigGeneric.js +632 -0
  67. package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -0
  68. package/build/JsonConfigComponent/ConfigIP.d.ts +14 -0
  69. package/build/JsonConfigComponent/ConfigIP.js +64 -0
  70. package/build/JsonConfigComponent/ConfigIP.js.map +1 -0
  71. package/build/JsonConfigComponent/ConfigImageSendTo.d.ts +10 -0
  72. package/build/JsonConfigComponent/ConfigImageSendTo.js +62 -0
  73. package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -0
  74. package/build/JsonConfigComponent/ConfigImageUpload.d.ts +14 -0
  75. package/build/JsonConfigComponent/ConfigImageUpload.js +91 -0
  76. package/build/JsonConfigComponent/ConfigImageUpload.js.map +1 -0
  77. package/build/JsonConfigComponent/ConfigInstanceSelect.d.ts +14 -0
  78. package/build/JsonConfigComponent/ConfigInstanceSelect.js +133 -0
  79. package/build/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -0
  80. package/build/JsonConfigComponent/ConfigInterface.d.ts +14 -0
  81. package/build/JsonConfigComponent/ConfigInterface.js +74 -0
  82. package/build/JsonConfigComponent/ConfigInterface.js.map +1 -0
  83. package/build/JsonConfigComponent/ConfigJsonEditor.d.ts +13 -0
  84. package/build/JsonConfigComponent/ConfigJsonEditor.js +59 -0
  85. package/build/JsonConfigComponent/ConfigJsonEditor.js.map +1 -0
  86. package/build/JsonConfigComponent/ConfigLanguage.d.ts +7 -0
  87. package/build/JsonConfigComponent/ConfigLanguage.js +105 -0
  88. package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -0
  89. package/build/JsonConfigComponent/ConfigLicense.d.ts +24 -0
  90. package/build/JsonConfigComponent/ConfigLicense.js +95 -0
  91. package/build/JsonConfigComponent/ConfigLicense.js.map +1 -0
  92. package/build/JsonConfigComponent/ConfigNumber.d.ts +17 -0
  93. package/build/JsonConfigComponent/ConfigNumber.js +114 -0
  94. package/build/JsonConfigComponent/ConfigNumber.js.map +1 -0
  95. package/build/JsonConfigComponent/ConfigObjectId.d.ts +17 -0
  96. package/build/JsonConfigComponent/ConfigObjectId.js +59 -0
  97. package/build/JsonConfigComponent/ConfigObjectId.js.map +1 -0
  98. package/build/JsonConfigComponent/ConfigPanel.d.ts +3 -0
  99. package/build/JsonConfigComponent/ConfigPanel.js +271 -0
  100. package/build/JsonConfigComponent/ConfigPanel.js.map +1 -0
  101. package/build/JsonConfigComponent/ConfigPassword.d.ts +14 -0
  102. package/build/JsonConfigComponent/ConfigPassword.js +105 -0
  103. package/build/JsonConfigComponent/ConfigPassword.js.map +1 -0
  104. package/build/JsonConfigComponent/ConfigPattern.d.ts +21 -0
  105. package/build/JsonConfigComponent/ConfigPattern.js +32 -0
  106. package/build/JsonConfigComponent/ConfigPattern.js.map +1 -0
  107. package/build/JsonConfigComponent/ConfigPort.d.ts +3 -0
  108. package/build/JsonConfigComponent/ConfigPort.js +174 -0
  109. package/build/JsonConfigComponent/ConfigPort.js.map +1 -0
  110. package/build/JsonConfigComponent/ConfigRoom.d.ts +14 -0
  111. package/build/JsonConfigComponent/ConfigRoom.js +56 -0
  112. package/build/JsonConfigComponent/ConfigRoom.js.map +1 -0
  113. package/build/JsonConfigComponent/ConfigSelect.d.ts +14 -0
  114. package/build/JsonConfigComponent/ConfigSelect.js +90 -0
  115. package/build/JsonConfigComponent/ConfigSelect.js.map +1 -0
  116. package/build/JsonConfigComponent/ConfigSelectSendTo.d.ts +17 -0
  117. package/build/JsonConfigComponent/ConfigSelectSendTo.js +175 -0
  118. package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -0
  119. package/build/JsonConfigComponent/ConfigSendto.d.ts +24 -0
  120. package/build/JsonConfigComponent/ConfigSendto.js +290 -0
  121. package/build/JsonConfigComponent/ConfigSendto.js.map +1 -0
  122. package/build/JsonConfigComponent/ConfigSetState.d.ts +18 -0
  123. package/build/JsonConfigComponent/ConfigSetState.js +93 -0
  124. package/build/JsonConfigComponent/ConfigSetState.js.map +1 -0
  125. package/build/JsonConfigComponent/ConfigSlider.d.ts +14 -0
  126. package/build/JsonConfigComponent/ConfigSlider.js +62 -0
  127. package/build/JsonConfigComponent/ConfigSlider.js.map +1 -0
  128. package/build/JsonConfigComponent/ConfigStaticDivider.d.ts +14 -0
  129. package/build/JsonConfigComponent/ConfigStaticDivider.js +39 -0
  130. package/build/JsonConfigComponent/ConfigStaticDivider.js.map +1 -0
  131. package/build/JsonConfigComponent/ConfigStaticHeader.d.ts +14 -0
  132. package/build/JsonConfigComponent/ConfigStaticHeader.js +45 -0
  133. package/build/JsonConfigComponent/ConfigStaticHeader.js.map +1 -0
  134. package/build/JsonConfigComponent/ConfigStaticImage.d.ts +14 -0
  135. package/build/JsonConfigComponent/ConfigStaticImage.js +36 -0
  136. package/build/JsonConfigComponent/ConfigStaticImage.js.map +1 -0
  137. package/build/JsonConfigComponent/ConfigStaticText.d.ts +14 -0
  138. package/build/JsonConfigComponent/ConfigStaticText.js +51 -0
  139. package/build/JsonConfigComponent/ConfigStaticText.js.map +1 -0
  140. package/build/JsonConfigComponent/ConfigTable.d.ts +3 -0
  141. package/build/JsonConfigComponent/ConfigTable.js +670 -0
  142. package/build/JsonConfigComponent/ConfigTable.js.map +1 -0
  143. package/build/JsonConfigComponent/ConfigTabs.d.ts +34 -0
  144. package/build/JsonConfigComponent/ConfigTabs.js +90 -0
  145. package/build/JsonConfigComponent/ConfigTabs.js.map +1 -0
  146. package/build/JsonConfigComponent/ConfigText.d.ts +14 -0
  147. package/build/JsonConfigComponent/ConfigText.js +105 -0
  148. package/build/JsonConfigComponent/ConfigText.js.map +1 -0
  149. package/build/JsonConfigComponent/ConfigTextSendTo.d.ts +10 -0
  150. package/build/JsonConfigComponent/ConfigTextSendTo.js +76 -0
  151. package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -0
  152. package/build/JsonConfigComponent/ConfigTimePicker.d.ts +14 -0
  153. package/build/JsonConfigComponent/ConfigTimePicker.js +37 -0
  154. package/build/JsonConfigComponent/ConfigTimePicker.js.map +1 -0
  155. package/build/JsonConfigComponent/ConfigTopic.d.ts +17 -0
  156. package/build/JsonConfigComponent/ConfigTopic.js +61 -0
  157. package/build/JsonConfigComponent/ConfigTopic.js.map +1 -0
  158. package/build/JsonConfigComponent/ConfigUUID.d.ts +15 -0
  159. package/build/JsonConfigComponent/ConfigUUID.js +31 -0
  160. package/build/JsonConfigComponent/ConfigUUID.js.map +1 -0
  161. package/build/JsonConfigComponent/ConfigUser.d.ts +14 -0
  162. package/build/JsonConfigComponent/ConfigUser.js +70 -0
  163. package/build/JsonConfigComponent/ConfigUser.js.map +1 -0
  164. package/build/JsonConfigComponent/index.d.ts +26 -0
  165. package/build/JsonConfigComponent/index.js +312 -0
  166. package/build/JsonConfigComponent/index.js.map +1 -0
  167. package/build/JsonConfigComponent/wrapper/AdminConnection.d.ts +2 -0
  168. package/build/JsonConfigComponent/wrapper/AdminConnection.js +3 -0
  169. package/build/JsonConfigComponent/wrapper/AdminConnection.js.map +1 -0
  170. package/build/JsonConfigComponent/wrapper/Components/ColorPicker.d.ts +2 -0
  171. package/build/JsonConfigComponent/wrapper/Components/ColorPicker.js +3 -0
  172. package/build/JsonConfigComponent/wrapper/Components/ColorPicker.js.map +1 -0
  173. package/build/JsonConfigComponent/wrapper/Components/CustomModal.d.ts +3 -0
  174. package/build/JsonConfigComponent/wrapper/Components/CustomModal.js +87 -0
  175. package/build/JsonConfigComponent/wrapper/Components/CustomModal.js.map +1 -0
  176. package/build/JsonConfigComponent/wrapper/Components/Editor.d.ts +14 -0
  177. package/build/JsonConfigComponent/wrapper/Components/Editor.js +43 -0
  178. package/build/JsonConfigComponent/wrapper/Components/Editor.js.map +1 -0
  179. package/build/JsonConfigComponent/wrapper/Components/Icon.d.ts +2 -0
  180. package/build/JsonConfigComponent/wrapper/Components/Icon.js +3 -0
  181. package/build/JsonConfigComponent/wrapper/Components/Icon.js.map +1 -0
  182. package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.d.ts +2 -0
  183. package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.js +3 -0
  184. package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.js.map +1 -0
  185. package/build/JsonConfigComponent/wrapper/Components/UploadImage.d.ts +2 -0
  186. package/build/JsonConfigComponent/wrapper/Components/UploadImage.js +3 -0
  187. package/build/JsonConfigComponent/wrapper/Components/UploadImage.js.map +1 -0
  188. package/build/JsonConfigComponent/wrapper/Components/Utils.d.ts +2 -0
  189. package/build/JsonConfigComponent/wrapper/Components/Utils.js +3 -0
  190. package/build/JsonConfigComponent/wrapper/Components/Utils.js.map +1 -0
  191. package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.d.ts +2 -0
  192. package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.js +3 -0
  193. package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.js.map +1 -0
  194. package/build/JsonConfigComponent/wrapper/Dialogs/Cron.d.ts +2 -0
  195. package/build/JsonConfigComponent/wrapper/Dialogs/Cron.js +3 -0
  196. package/build/JsonConfigComponent/wrapper/Dialogs/Cron.js.map +1 -0
  197. package/build/JsonConfigComponent/wrapper/Dialogs/Error.d.ts +2 -0
  198. package/build/JsonConfigComponent/wrapper/Dialogs/Error.js +3 -0
  199. package/build/JsonConfigComponent/wrapper/Dialogs/Error.js.map +1 -0
  200. package/build/JsonConfigComponent/wrapper/Dialogs/Message.d.ts +2 -0
  201. package/build/JsonConfigComponent/wrapper/Dialogs/Message.js +3 -0
  202. package/build/JsonConfigComponent/wrapper/Dialogs/Message.js.map +1 -0
  203. package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.d.ts +2 -0
  204. package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.js +3 -0
  205. package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.js.map +1 -0
  206. package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.d.ts +2 -0
  207. package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.js +3 -0
  208. package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.js.map +1 -0
  209. package/build/JsonConfigComponent/wrapper/i18n.d.ts +2 -0
  210. package/build/JsonConfigComponent/wrapper/i18n.js +3 -0
  211. package/build/JsonConfigComponent/wrapper/i18n.js.map +1 -0
  212. package/build/JsonConfigComponent/wrapper/icons/IconCopy.d.ts +2 -0
  213. package/build/JsonConfigComponent/wrapper/icons/IconCopy.js +3 -0
  214. package/build/JsonConfigComponent/wrapper/icons/IconCopy.js.map +1 -0
  215. package/build/Utils.d.ts +376 -0
  216. package/build/Utils.js +1595 -0
  217. package/build/Utils.js.map +1 -0
  218. package/build/index.d.ts +5 -0
  219. package/build/index.js +6 -0
  220. package/build/index.js.map +1 -0
  221. package/package.json +17 -0
@@ -0,0 +1,632 @@
1
+ import React, { Component } from 'react';
2
+ import { Grid, Button } from '@mui/material';
3
+ import { Info as IconInfo, Warning as IconWarning, Error as IconError, Key as IconAuth, Send as IconSend, Public as IconWeb, Search as IconSearch, MenuBook as IconMenuBook, Help as IconHelp, UploadFile as IconUploadFile, } from '@mui/icons-material';
4
+ import I18n from './wrapper/i18n';
5
+ import Utils from './wrapper/Components/Utils';
6
+ import ConfirmDialog from './wrapper/Dialogs/Confirm';
7
+ import Icon from './wrapper/Components/Icon';
8
+ // because this class is used in adapter-react-v5, do not include here any foreign files like from '../../helpers/utils.ts'
9
+ export function isObject(it) {
10
+ // This is necessary because:
11
+ // typeof null === 'object'
12
+ // typeof [] === 'object'
13
+ // [] instanceof Object === true
14
+ return Object.prototype.toString.call(it) === '[object Object]'; // this code is 25% faster than below one
15
+ // return it && typeof it === 'object' && !(it instanceof Array);
16
+ }
17
+ export default class ConfigGeneric extends Component {
18
+ static DIFFERENT_VALUE = '__different__';
19
+ static DIFFERENT_LABEL = 'ra___different__';
20
+ static NONE_VALUE = '';
21
+ static NONE_LABEL = 'ra_none';
22
+ defaultValue;
23
+ isError;
24
+ lang;
25
+ defaultSendToDone;
26
+ sendToTimeout;
27
+ noPlaceRequired;
28
+ constructor(props) {
29
+ super(props);
30
+ // @ts-expect-error of course, as we just
31
+ this.state = {
32
+ confirmDialog: false,
33
+ confirmNewValue: null,
34
+ confirmAttr: null,
35
+ confirmData: null,
36
+ };
37
+ this.isError = {};
38
+ if (props.schema) {
39
+ if (props.custom) {
40
+ this.defaultValue = props.schema.defaultFunc
41
+ ? this.executeCustom(props.schema.defaultFunc, props.schema.default, props.data, props.instanceObj, props.arrayIndex, props.globalData)
42
+ : props.schema.default;
43
+ }
44
+ else {
45
+ this.defaultValue = props.schema.defaultFunc
46
+ ? this.execute(props.schema.defaultFunc, props.schema.default, props.data, props.arrayIndex, props.globalData)
47
+ : props.schema.default;
48
+ }
49
+ }
50
+ this.lang = I18n.getLanguage();
51
+ }
52
+ componentDidMount() {
53
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr, this.onUpdate);
54
+ const LIKE_SELECT = ['select', 'autocomplete', 'autocompleteSendTo'];
55
+ // init default value
56
+ if (this.defaultValue !== undefined) {
57
+ const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
58
+ if (value === undefined ||
59
+ (LIKE_SELECT.includes(this.props.schema.type) && (value === '' || value === null))) {
60
+ setTimeout(() => {
61
+ if (this.props.custom) {
62
+ this.props.onChange(this.props.attr, this.defaultValue, () => setTimeout(() => this.props.forceUpdate([this.props.attr], this.props.data), 100));
63
+ }
64
+ else {
65
+ ConfigGeneric.setValue(this.props.data, this.props.attr, this.defaultValue);
66
+ this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
67
+ }
68
+ }, 100);
69
+ }
70
+ }
71
+ else if (this.props.schema.defaultSendTo) {
72
+ this.sendTo();
73
+ }
74
+ }
75
+ sendTo() {
76
+ if (this.props.alive) {
77
+ this.defaultSendToDone = true;
78
+ let data = this.props.schema.data;
79
+ if (data === undefined && this.props.schema.jsonData) {
80
+ data = this.getPattern(this.props.schema.jsonData);
81
+ try {
82
+ data = JSON.parse(data);
83
+ }
84
+ catch (e) {
85
+ console.error(`Cannot parse json data: ${data}`);
86
+ }
87
+ }
88
+ else {
89
+ data = {
90
+ attr: this.props.attr,
91
+ value: ConfigGeneric.getValue(this.props.data, this.props.attr),
92
+ };
93
+ }
94
+ if (data === undefined) {
95
+ data = null;
96
+ }
97
+ this.props.socket
98
+ .sendTo(`${this.props.adapterName}.${this.props.instance}`, this.props.schema.defaultSendTo, data)
99
+ .then((value) => {
100
+ if (value !== null && value !== undefined) {
101
+ if (this.props.custom) {
102
+ this.props.onChange(this.props.attr, value, () => this.props.forceUpdate([this.props.attr], this.props.data));
103
+ }
104
+ else {
105
+ ConfigGeneric.setValue(this.props.data, this.props.attr, value);
106
+ this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
107
+ }
108
+ }
109
+ });
110
+ }
111
+ else {
112
+ this.defaultSendToDone = false;
113
+ // show error, that instance did not start
114
+ this.onError(this.props.attr, I18n.t('ra_Instance %s is not alive', this.props.instance.toString()));
115
+ }
116
+ }
117
+ componentWillUnmount() {
118
+ this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr);
119
+ if (this.sendToTimeout) {
120
+ clearTimeout(this.sendToTimeout);
121
+ this.sendToTimeout = null;
122
+ }
123
+ }
124
+ onUpdate = (data) => {
125
+ const value = ConfigGeneric.getValue(data || this.props.data, this.props.attr) || '';
126
+ if (this.state.value !== value) {
127
+ this.setState({ value });
128
+ }
129
+ else {
130
+ this.forceUpdate();
131
+ }
132
+ };
133
+ /**
134
+ * Extract attribute out of data
135
+ *
136
+ * @param data
137
+ * @param attr
138
+ */
139
+ static getValue(data, attr) {
140
+ if (typeof attr === 'string') {
141
+ return ConfigGeneric.getValue(data, attr.split('.'));
142
+ }
143
+ if (attr.length === 1) {
144
+ return data[attr[0]];
145
+ }
146
+ const part = attr.shift();
147
+ if (typeof part === 'string' && typeof data[part] === 'object') {
148
+ return ConfigGeneric.getValue(data[part], attr);
149
+ }
150
+ return null;
151
+ }
152
+ static setValue(data, attr, value) {
153
+ if (typeof attr === 'string') {
154
+ ConfigGeneric.setValue(data, attr.split('.'), value);
155
+ return;
156
+ }
157
+ if (attr.length === 1) {
158
+ if (value === null) {
159
+ delete data[attr[0]];
160
+ }
161
+ else {
162
+ data[attr[0]] = value;
163
+ }
164
+ }
165
+ else {
166
+ const part = attr.shift();
167
+ if (typeof part !== 'string') {
168
+ return;
169
+ }
170
+ if (!data[part] || typeof data[part] === 'object') {
171
+ data[part] = data[part] || {};
172
+ }
173
+ ConfigGeneric.setValue(data[part], attr, value);
174
+ }
175
+ }
176
+ getText(text, noTranslation) {
177
+ if (!text) {
178
+ return '';
179
+ }
180
+ if (typeof text === 'string') {
181
+ const strText = noTranslation ? text : I18n.t(text);
182
+ if (strText.includes('${')) {
183
+ return this.getPattern(strText);
184
+ }
185
+ return strText;
186
+ }
187
+ if (isObject(text)) {
188
+ if (text.func) {
189
+ // calculate pattern
190
+ if (typeof text.func === 'object') {
191
+ return this.getPattern(text.func[this.lang] || text.func.en || '');
192
+ }
193
+ return this.getPattern(text.func);
194
+ }
195
+ return text[this.lang] || text.en || '';
196
+ }
197
+ return text.toString();
198
+ }
199
+ renderConfirmDialog() {
200
+ if (!this.state.confirmDialog) {
201
+ return null;
202
+ }
203
+ const confirm = this.state.confirmData || this.props.schema.confirm;
204
+ let icon = null;
205
+ if (confirm.type === 'warning') {
206
+ icon = React.createElement(IconWarning, null);
207
+ }
208
+ else if (confirm.type === 'error') {
209
+ icon = React.createElement(IconError, null);
210
+ }
211
+ else if (confirm.type === 'info') {
212
+ icon = React.createElement(IconInfo, null);
213
+ }
214
+ return React.createElement(ConfirmDialog, { 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 || undefined, onClose: isOk => this.setState({ confirmDialog: false }, () => {
215
+ if (isOk) {
216
+ const data = JSON.parse(JSON.stringify(this.props.data));
217
+ if (this.state.confirmDepAttr) {
218
+ ConfigGeneric.setValue(data, this.state.confirmDepAttr, this.state.confirmDepNewValue);
219
+ }
220
+ ConfigGeneric.setValue(data, this.state.confirmAttr, this.state.confirmNewValue);
221
+ this.setState({
222
+ confirmDialog: false,
223
+ confirmDepAttr: null,
224
+ confirmDepNewValue: null,
225
+ confirmNewValue: null,
226
+ confirmAttr: null,
227
+ confirmData: null,
228
+ }, () => this.props.onChange(data));
229
+ }
230
+ else {
231
+ this.setState({
232
+ confirmDialog: false,
233
+ confirmDepAttr: null,
234
+ confirmDepNewValue: null,
235
+ confirmNewValue: null,
236
+ confirmAttr: null,
237
+ confirmData: null,
238
+ });
239
+ }
240
+ }) });
241
+ }
242
+ // eslint-disable-next-line react/no-unused-class-component-methods
243
+ getIcon(iconSettings) {
244
+ iconSettings = iconSettings || this.props.schema.icon;
245
+ let icon = null;
246
+ if (iconSettings === 'auth') {
247
+ icon = React.createElement(IconAuth, null);
248
+ }
249
+ else if (iconSettings === 'send') {
250
+ icon = React.createElement(IconSend, null);
251
+ }
252
+ else if (iconSettings === 'web') {
253
+ icon = React.createElement(IconWeb, null);
254
+ }
255
+ else if (iconSettings === 'warning') {
256
+ icon = React.createElement(IconWarning, null);
257
+ }
258
+ else if (iconSettings === 'error') {
259
+ icon = React.createElement(IconError, null);
260
+ }
261
+ else if (iconSettings === 'info') {
262
+ icon = React.createElement(IconInfo, null);
263
+ }
264
+ else if (iconSettings === 'search') {
265
+ icon = React.createElement(IconSearch, null);
266
+ }
267
+ else if (iconSettings === 'book') {
268
+ icon = React.createElement(IconMenuBook, null);
269
+ }
270
+ else if (iconSettings === 'help') {
271
+ icon = React.createElement(IconHelp, null);
272
+ }
273
+ else if (iconSettings === 'upload') {
274
+ icon = React.createElement(IconUploadFile, null);
275
+ }
276
+ else if (iconSettings) {
277
+ if (iconSettings.endsWith('.png') || iconSettings.endsWith('.svg') || iconSettings.endsWith('.jpg')) {
278
+ // this path is relative to ./adapter/NAME
279
+ if (!iconSettings.startsWith('http://') && !iconSettings.startsWith('https://')) {
280
+ iconSettings = `./adapter/${this.props.adapterName}/${iconSettings}`;
281
+ }
282
+ }
283
+ icon = React.createElement(Icon, { src: iconSettings, style: { width: 22, height: 22 } });
284
+ }
285
+ return icon;
286
+ }
287
+ /**
288
+ * Trigger onChange, to activate save button on change
289
+ *
290
+ * @param attr the changed attribute
291
+ * @param newValue new value of the attribute
292
+ */
293
+ onChangeAsync(attr, newValue) {
294
+ return new Promise(resolve => this.onChange(attr, newValue, resolve));
295
+ }
296
+ /**
297
+ * Trigger onChange, to activate save button on change
298
+ *
299
+ * @param attr the changed attribute
300
+ * @param newValue new value of the attribute
301
+ * @param cb optional callback function, else returns a Promise
302
+ */
303
+ // eslint-disable-next-line react/no-unused-class-component-methods
304
+ onChange(attr, newValue, cb) {
305
+ // Do not use here deep copy, as it is not JsonConfig
306
+ const data = JSON.parse(JSON.stringify(this.props.data));
307
+ ConfigGeneric.setValue(data, attr, newValue);
308
+ if (this.props.schema.confirm &&
309
+ this.execute(this.props.schema.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
310
+ return new Promise(resolve => {
311
+ this.setState({
312
+ confirmDialog: true,
313
+ confirmNewValue: newValue,
314
+ confirmAttr: attr,
315
+ confirmData: null,
316
+ }, () => {
317
+ if (typeof cb === 'function') {
318
+ cb();
319
+ }
320
+ else {
321
+ resolve();
322
+ }
323
+ });
324
+ });
325
+ }
326
+ // find any inputs with confirmation
327
+ if (this.props.schema.confirmDependsOn) {
328
+ for (let z = 0; z < this.props.schema.confirmDependsOn.length; z++) {
329
+ const dep = this.props.schema.confirmDependsOn[z];
330
+ if (dep.confirm) {
331
+ const val = ConfigGeneric.getValue(data, dep.attr);
332
+ if (this.execute(dep.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
333
+ return new Promise(resolve => {
334
+ this.setState({
335
+ confirmDialog: true,
336
+ confirmNewValue: newValue,
337
+ confirmAttr: attr,
338
+ confirmDepNewValue: val,
339
+ confirmDepAttr: dep.attr,
340
+ confirmData: dep.confirm,
341
+ }, () => {
342
+ if (typeof cb === 'function') {
343
+ cb();
344
+ }
345
+ else {
346
+ resolve();
347
+ }
348
+ });
349
+ });
350
+ }
351
+ }
352
+ }
353
+ }
354
+ const changed = [];
355
+ if (this.props.schema.onChangeDependsOn) {
356
+ for (let z = 0; z < this.props.schema.onChangeDependsOn.length; z++) {
357
+ const dep = this.props.schema.onChangeDependsOn[z];
358
+ if (dep.onChange) {
359
+ const val = ConfigGeneric.getValue(data, dep.attr);
360
+ let _newValue;
361
+ if (this.props.custom) {
362
+ _newValue = this.executeCustom(dep.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData);
363
+ }
364
+ else {
365
+ _newValue = this.execute(dep.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
366
+ }
367
+ if (_newValue !== val) {
368
+ ConfigGeneric.setValue(data, dep.attr, _newValue);
369
+ changed.push(dep.attr);
370
+ }
371
+ }
372
+ }
373
+ }
374
+ if (this.props.schema.hiddenDependsOn) {
375
+ for (let z = 0; z < this.props.schema.hiddenDependsOn.length; z++) {
376
+ const dep = this.props.schema.hiddenDependsOn[z];
377
+ dep.hidden && changed.push(dep.attr);
378
+ }
379
+ }
380
+ if (this.props.schema.labelDependsOn) {
381
+ for (let z = 0; z < this.props.schema.labelDependsOn.length; z++) {
382
+ const dep = this.props.schema.labelDependsOn[z];
383
+ dep.hidden && changed.push(dep.attr);
384
+ }
385
+ }
386
+ if (this.props.schema.helpDependsOn) {
387
+ for (let z = 0; z < this.props.schema.helpDependsOn.length; z++) {
388
+ const dep = this.props.schema.helpDependsOn[z];
389
+ dep.hidden && changed.push(dep.attr);
390
+ }
391
+ }
392
+ if (this.props.schema.onChange && !this.props.schema.onChange.ignoreOwnChanges) {
393
+ const val = ConfigGeneric.getValue(data, this.props.attr);
394
+ const newValue_ = this.props.custom
395
+ ? this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
396
+ : this.execute(this.props.schema.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
397
+ if (newValue_ !== val) {
398
+ ConfigGeneric.setValue(data, this.props.attr, newValue_);
399
+ }
400
+ }
401
+ if (this.props.custom) {
402
+ this.props.onChange(attr, newValue, () => cb && cb());
403
+ changed &&
404
+ changed.length &&
405
+ changed.forEach((_attr, i) => setTimeout(() => this.props.onChange(_attr, ConfigGeneric.getValue(data, _attr)), i * 50));
406
+ }
407
+ else {
408
+ this.props.onChange(data, undefined, () => {
409
+ changed.length && this.props.forceUpdate(changed, data);
410
+ cb && cb();
411
+ });
412
+ }
413
+ return Promise.resolve();
414
+ }
415
+ execute(func, defaultValue, data, arrayIndex, globalData) {
416
+ let fun;
417
+ if (isObject(func)) {
418
+ fun = func.func;
419
+ }
420
+ else {
421
+ fun = func;
422
+ }
423
+ if (!fun) {
424
+ return defaultValue;
425
+ }
426
+ try {
427
+ // eslint-disable-next-line no-new-func
428
+ const f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
429
+ return f(data || this.props.data, this.props.originalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.instance, arrayIndex, globalData, this.props.changed);
430
+ }
431
+ catch (e) {
432
+ console.error(`Cannot execute ${func}: ${e}`);
433
+ return defaultValue;
434
+ }
435
+ }
436
+ executeCustom(func, data, customObj, instanceObj, arrayIndex, globalData) {
437
+ let fun;
438
+ if (isObject(func)) {
439
+ fun = func.func;
440
+ }
441
+ else {
442
+ fun = func;
443
+ }
444
+ if (!fun) {
445
+ return null;
446
+ }
447
+ try {
448
+ // eslint-disable-next-line no-new-func
449
+ const f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
450
+ return f(data || this.props.data, this.props.originalData, this.props.systemConfig, instanceObj, customObj, this.props.socket, arrayIndex, globalData, this.props.changed);
451
+ }
452
+ catch (e) {
453
+ console.error(`Cannot execute ${fun}: ${e}`);
454
+ return null;
455
+ }
456
+ }
457
+ calculate(schema) {
458
+ let error;
459
+ let disabled;
460
+ let hidden;
461
+ let defaultValue;
462
+ if (this.props.custom) {
463
+ error = schema.validator
464
+ ? !this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
465
+ : false;
466
+ disabled = schema.disabled
467
+ ? this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
468
+ : false;
469
+ hidden = schema.hidden
470
+ ? this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
471
+ : false;
472
+ defaultValue = schema.defaultFunc
473
+ ? this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
474
+ : schema.default;
475
+ }
476
+ else {
477
+ error = schema.validator
478
+ ? !this.execute(schema.validator, false, this.props.data, this.props.arrayIndex, this.props.globalData)
479
+ : false;
480
+ disabled = schema.disabled
481
+ ? this.execute(schema.disabled, false, this.props.data, this.props.arrayIndex, this.props.globalData)
482
+ : false;
483
+ hidden = schema.hidden
484
+ ? this.execute(schema.hidden, false, this.props.data, this.props.arrayIndex, this.props.globalData)
485
+ : false;
486
+ defaultValue = schema.defaultFunc
487
+ ? this.execute(schema.defaultFunc, schema.default, this.props.data, this.props.arrayIndex, this.props.globalData)
488
+ : schema.default;
489
+ }
490
+ return {
491
+ error, disabled, hidden, defaultValue,
492
+ };
493
+ }
494
+ onError(attr, error) {
495
+ if (!error) {
496
+ delete this.isError[attr];
497
+ }
498
+ else {
499
+ this.isError[attr] = error;
500
+ }
501
+ this.props.onError && this.props.onError(attr, error);
502
+ }
503
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
504
+ renderItem(_error, _disabled, _defaultValue) {
505
+ return this.getText(this.props.schema.label) || this.getText(this.props.schema.text);
506
+ }
507
+ // eslint-disable-next-line react/no-unused-class-component-methods
508
+ renderHelp(text, link, noTranslation) {
509
+ if (!link) {
510
+ text = this.getText(text, noTranslation) || '';
511
+ if (text &&
512
+ (text.includes('<a ') || text.includes('<br') || text.includes('<b>') || text.includes('<i>'))) {
513
+ return Utils.renderTextWithA(text);
514
+ }
515
+ return text;
516
+ }
517
+ return React.createElement("a", { href: link, target: "_blank", rel: "noreferrer", style: {
518
+ color: this.props.themeType === 'dark' ? '#a147ff' : '#5b238f',
519
+ textDecoration: 'underline',
520
+ } }, this.getText(text, noTranslation));
521
+ }
522
+ getPattern(pattern, data) {
523
+ data = data || this.props.data;
524
+ if (!pattern) {
525
+ return '';
526
+ }
527
+ if (typeof pattern === 'object') {
528
+ if (pattern.func) {
529
+ pattern = pattern.func;
530
+ }
531
+ else {
532
+ console.log(`Object must be stringified: ${JSON.stringify(pattern)}`);
533
+ pattern = JSON.stringify(pattern);
534
+ }
535
+ }
536
+ try {
537
+ if (this.props.custom) {
538
+ // eslint-disable-next-line no-new-func
539
+ const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
540
+ return f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.instanceObj, this.props.customObj, this.props.socket, this.props.changed);
541
+ }
542
+ // eslint-disable-next-line no-new-func
543
+ const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
544
+ return f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.changed);
545
+ }
546
+ catch (e) {
547
+ console.error(`Cannot execute ${pattern}: ${e}`);
548
+ return pattern;
549
+ }
550
+ }
551
+ render() {
552
+ const schema = this.props.schema;
553
+ if (!schema) {
554
+ return null;
555
+ }
556
+ if (this.props.alive && this.defaultSendToDone === false) {
557
+ this.sendToTimeout = setTimeout(() => {
558
+ this.sendToTimeout = null;
559
+ this.sendTo();
560
+ }, 200);
561
+ }
562
+ const { error, disabled, hidden, defaultValue, } = this.calculate(schema);
563
+ if (hidden) {
564
+ // Remove all errors if element is hidden
565
+ if (Object.keys(this.isError).length) {
566
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
567
+ this.isError = {};
568
+ }
569
+ if (schema.hideOnlyControl) {
570
+ const item = React.createElement(Grid, { item: true, xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: ({
571
+ marginBottom: 0,
572
+ textAlign: 'left',
573
+ ...schema.style,
574
+ ...(this.props.themeType === 'dark' ? schema.darkStyle : {}),
575
+ }) });
576
+ if (schema.newLine) {
577
+ return React.createElement(React.Fragment, null,
578
+ React.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
579
+ item);
580
+ }
581
+ return item;
582
+ }
583
+ return null;
584
+ }
585
+ // Add error
586
+ if (schema.validatorNoSaveOnError) {
587
+ if (error && !Object.keys(this.isError).length) {
588
+ this.isError = {
589
+ [this.props.attr]: schema.validatorErrorText ? I18n.t(schema.validatorErrorText) : true,
590
+ };
591
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr, isError[attr])), 100, JSON.parse(JSON.stringify(this.isError)));
592
+ }
593
+ else if (!error && Object.keys(this.isError).length) {
594
+ setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
595
+ this.isError = {};
596
+ }
597
+ }
598
+ const renderedItem = this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue);
599
+ if (this.noPlaceRequired) {
600
+ return renderedItem;
601
+ }
602
+ const item = React.createElement(Grid, { item: true, title: this.getText(schema.tooltip), xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: ({
603
+ marginBottom: 0,
604
+ // marginRight: 8,
605
+ textAlign: 'left',
606
+ width: schema.type === 'divider' || schema.type === 'header'
607
+ ? schema.width || '100%'
608
+ : undefined,
609
+ ...schema.style,
610
+ ...(this.props.themeType === 'dark' ? schema.darkStyle : {}),
611
+ }) }, this.props.schema.defaultSendTo && this.props.schema.button ?
612
+ React.createElement(Grid, { container: true, style: { width: '100%' } },
613
+ React.createElement(Grid, { item: true, flex: 1 }, renderedItem),
614
+ React.createElement(Grid, { item: true },
615
+ React.createElement(Button, { variant: "outlined", onClick: () => this.sendTo(), title: this.props.schema.buttonTooltip
616
+ ? this.getText(this.props.schema.buttonTooltip, this.props.schema.buttonTooltipNoTranslation)
617
+ : I18n.t('ra_Request data by instance') }, this.getText(this.props.schema.button)))) : renderedItem);
618
+ if (schema.newLine) {
619
+ return React.createElement(React.Fragment, null,
620
+ React.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
621
+ this.renderConfirmDialog(),
622
+ item);
623
+ }
624
+ if (this.state.confirmDialog) {
625
+ return React.createElement(React.Fragment, null,
626
+ this.renderConfirmDialog(),
627
+ item);
628
+ }
629
+ return item;
630
+ }
631
+ }
632
+ //# sourceMappingURL=ConfigGeneric.js.map