@iobroker/json-config 8.4.7 → 8.4.9
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.
- package/README.md +19 -4
- package/build/JsonConfig.js +7 -7
- package/build/JsonConfig.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAccordion.js +9 -9
- package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAlive.js +2 -2
- package/build/JsonConfigComponent/ConfigAlive.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocomplete.js +11 -2
- package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js +10 -3
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCRON.js +1 -1
- package/build/JsonConfigComponent/ConfigCRON.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertCollection.js +2 -2
- package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertificates.js +6 -6
- package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckDocker.js +4 -4
- package/build/JsonConfigComponent/ConfigCheckDocker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckLicense.js +31 -31
- package/build/JsonConfigComponent/ConfigCheckLicense.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckbox.js +1 -1
- package/build/JsonConfigComponent/ConfigCheckbox.js.map +1 -1
- package/build/JsonConfigComponent/ConfigChip.js +1 -1
- package/build/JsonConfigComponent/ConfigChip.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCoordinates.js +7 -7
- package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCredentialSelect.d.ts +24 -0
- package/build/JsonConfigComponent/ConfigCredentialSelect.js +210 -11
- package/build/JsonConfigComponent/ConfigCredentialSelect.js.map +1 -1
- package/build/JsonConfigComponent/ConfigFileSelector.js +6 -6
- package/build/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
- package/build/JsonConfigComponent/ConfigGeneric.js +6 -6
- package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIFrameSendTo.js +1 -1
- package/build/JsonConfigComponent/ConfigIFrameSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIP.js +2 -2
- package/build/JsonConfigComponent/ConfigIP.js.map +1 -1
- package/build/JsonConfigComponent/ConfigImageSendTo.js +2 -2
- package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigJsonEditor.js +2 -2
- package/build/JsonConfigComponent/ConfigJsonEditor.js.map +1 -1
- package/build/JsonConfigComponent/ConfigLanguage.js +2 -2
- package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -1
- package/build/JsonConfigComponent/ConfigLicense.js +3 -3
- package/build/JsonConfigComponent/ConfigLicense.js.map +1 -1
- package/build/JsonConfigComponent/ConfigNumber.js +5 -5
- package/build/JsonConfigComponent/ConfigNumber.js.map +1 -1
- package/build/JsonConfigComponent/ConfigOAuth2.js +9 -9
- package/build/JsonConfigComponent/ConfigOAuth2.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPassword.js +4 -4
- package/build/JsonConfigComponent/ConfigPassword.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPattern.js +1 -1
- package/build/JsonConfigComponent/ConfigPattern.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPort.js +7 -7
- package/build/JsonConfigComponent/ConfigPort.js.map +1 -1
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js +3 -3
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSelectSendTo.js +2 -2
- package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSendto.js +10 -10
- package/build/JsonConfigComponent/ConfigSendto.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSetState.js +2 -2
- package/build/JsonConfigComponent/ConfigSetState.js.map +1 -1
- package/build/JsonConfigComponent/ConfigState.js +1 -1
- package/build/JsonConfigComponent/ConfigState.js.map +1 -1
- package/build/JsonConfigComponent/ConfigStaticImage.js +2 -2
- package/build/JsonConfigComponent/ConfigStaticImage.js.map +1 -1
- package/build/JsonConfigComponent/ConfigStaticInfo.js +1 -1
- package/build/JsonConfigComponent/ConfigStaticInfo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTable.js +33 -33
- package/build/JsonConfigComponent/ConfigTable.js.map +1 -1
- package/build/JsonConfigComponent/ConfigText.js +3 -3
- package/build/JsonConfigComponent/ConfigText.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTextSendTo.js +2 -2
- package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigUUID.js +2 -2
- package/build/JsonConfigComponent/ConfigUUID.js.map +1 -1
- package/build/JsonConfigComponent/ConfigYamlEditor.js +2 -2
- package/build/JsonConfigComponent/ConfigYamlEditor.js.map +1 -1
- package/build/JsonConfigComponent/i18n/de.json +116 -0
- package/build/JsonConfigComponent/i18n/en.json +136 -0
- package/build/JsonConfigComponent/i18n/es.json +116 -0
- package/build/JsonConfigComponent/i18n/fr.json +116 -0
- package/build/JsonConfigComponent/i18n/it.json +116 -0
- package/build/JsonConfigComponent/i18n/nl.json +116 -0
- package/build/JsonConfigComponent/i18n/pl.json +116 -0
- package/build/JsonConfigComponent/i18n/pt.json +116 -0
- package/build/JsonConfigComponent/i18n/ru.json +116 -0
- package/build/JsonConfigComponent/i18n/uk.json +116 -0
- package/build/JsonConfigComponent/i18n/zh-cn.json +116 -0
- package/build/JsonConfigComponent/index.d.ts +1 -0
- package/build/JsonConfigComponent/index.js +28 -0
- package/build/JsonConfigComponent/index.js.map +1 -1
- package/build/JsonConfigComponent/wrapper/Components/CustomModal.js +3 -3
- package/build/JsonConfigComponent/wrapper/Components/CustomModal.js.map +1 -1
- package/build/types.d.ts +2 -0
- package/package.json +13 -9
|
@@ -33,7 +33,7 @@ export default class ConfigImageSendTo extends ConfigGeneric {
|
|
|
33
33
|
if (instance !== `${this.props.oContext.adapterName}.${this.props.oContext.instance}`) {
|
|
34
34
|
const alive = await this.props.oContext.socket.getState(`system.adapter.${instance}.alive`);
|
|
35
35
|
if (!alive?.val) {
|
|
36
|
-
window.alert(I18n.t('
|
|
36
|
+
window.alert(I18n.t('jc_Instance %s is not alive', instance));
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -68,7 +68,7 @@ export default class ConfigImageSendTo extends ConfigGeneric {
|
|
|
68
68
|
alignItems: 'center',
|
|
69
69
|
justifyContent: 'center',
|
|
70
70
|
cursor: this.state.loading ? 'default' : 'pointer',
|
|
71
|
-
}, onClick: () => !this.state.loading && this.askInstance() }, this.state.loading ? (React.createElement(CircularProgress, null)) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (I18n.t('
|
|
71
|
+
}, onClick: () => !this.state.loading && this.askInstance() }, this.state.loading ? (React.createElement(CircularProgress, null)) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (I18n.t('jc_Click to show')) : (this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation))));
|
|
72
72
|
}
|
|
73
73
|
if (this.state.image === undefined) {
|
|
74
74
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigImageSendTo.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigImageSendTo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAWlG,MAAM,CAA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SAAS;iBACrD,EACD,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,IAEvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAClB,oBAAC,gBAAgB,OAAG,CACvB,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,CAC1D,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAC7B,CAAC,CAAC,CAAC,CACA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CACpF,CACC,CACT,CAAC;QACN,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,CACH,oBAAC,IAAI,IACD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC9C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACrB,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GACvF,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { CircularProgress } from '@mui/material';\nimport { I18n, Icon } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemImageSendTo } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigImageSendToProps extends ConfigGenericProps {\n schema: ConfigItemImageSendTo;\n}\n\ninterface ConfigImageSendToState extends ConfigGenericState {\n image?: string;\n loading?: boolean;\n}\n\nexport default class ConfigImageSendTo extends ConfigGeneric<ConfigImageSendToProps, ConfigImageSendToState> {\n private initialized = false;\n\n private localContext: string | undefined;\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n\n if (!this.props.schema.sendFirstByClick) {\n this.askInstance().catch((err: Error) => console.error(err));\n }\n }\n\n async askInstance(): Promise<void> {\n if (this.props.alive) {\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n const dataStr: string = await this.getPatternAsync(this.props.schema.jsonData, null, true);\n if (dataStr) {\n try {\n data = JSON.parse(dataStr);\n } catch {\n console.error(`Cannot parse json data: ${JSON.stringify(data)}`);\n }\n }\n }\n\n if (data === undefined) {\n data = null;\n }\n const instance = await this.getPatternAsync(\n this.props.schema.instance || `${this.props.oContext.adapterName}.${this.props.oContext.instance}`,\n );\n // Check that instance is alive\n if (instance !== `${this.props.oContext.adapterName}.${this.props.oContext.instance}`) {\n const alive = await this.props.oContext.socket.getState(`system.adapter.${instance}.alive`);\n if (!alive?.val) {\n window.alert(I18n.t('
|
|
1
|
+
{"version":3,"file":"ConfigImageSendTo.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigImageSendTo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAWlG,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,aAA6D;IAChG,WAAW,GAAG,KAAK,CAAC;IAEpB,YAAY,CAAqB;IAEzC,KAAK,CAAC,iBAAiB;QACnB,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAEhC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,g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AAC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,CAC1D,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAC7B,CAAC,CAAC,CAAC,CACA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CACpF,CACC,CACT,CAAC;QACN,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,CACH,oBAAC,IAAI,IACD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC9C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACrB,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GACvF,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { CircularProgress } from '@mui/material';\nimport { I18n, Icon } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemImageSendTo } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigImageSendToProps extends ConfigGenericProps {\n schema: ConfigItemImageSendTo;\n}\n\ninterface ConfigImageSendToState extends ConfigGenericState {\n image?: string;\n loading?: boolean;\n}\n\nexport default class ConfigImageSendTo extends ConfigGeneric<ConfigImageSendToProps, ConfigImageSendToState> {\n private initialized = false;\n\n private localContext: string | undefined;\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n\n if (!this.props.schema.sendFirstByClick) {\n this.askInstance().catch((err: Error) => console.error(err));\n }\n }\n\n async askInstance(): Promise<void> {\n if (this.props.alive) {\n let data = this.props.schema.data;\n if (data === undefined && this.props.schema.jsonData) {\n const dataStr: string = await this.getPatternAsync(this.props.schema.jsonData, null, true);\n if (dataStr) {\n try {\n data = JSON.parse(dataStr);\n } catch {\n console.error(`Cannot parse json data: ${JSON.stringify(data)}`);\n }\n }\n }\n\n if (data === undefined) {\n data = null;\n }\n const instance = await this.getPatternAsync(\n this.props.schema.instance || `${this.props.oContext.adapterName}.${this.props.oContext.instance}`,\n );\n // Check that instance is alive\n if (instance !== `${this.props.oContext.adapterName}.${this.props.oContext.instance}`) {\n const alive = await this.props.oContext.socket.getState(`system.adapter.${instance}.alive`);\n if (!alive?.val) {\n window.alert(I18n.t('jc_Instance %s is not alive', instance));\n return;\n }\n }\n this.setState({ loading: true }, () =>\n this.props.oContext.socket\n .sendTo(instance, this.props.schema.command || 'send', data)\n .then(image => this.setState({ image: image || '' })),\n );\n }\n }\n\n getContext(): string {\n const localContext: Record<string, any> = {};\n\n if (Array.isArray(this.props.schema.alsoDependsOn)) {\n this.props.schema.alsoDependsOn.forEach(\n attr => (localContext[attr] = ConfigGeneric.getValue(this.props.data, attr)),\n );\n }\n\n return JSON.stringify(localContext);\n }\n\n renderItem(/* error, disabled, defaultValue */): JSX.Element {\n if (this.props.alive) {\n const localContext = this.getContext();\n if (localContext !== this.localContext || !this.initialized) {\n this.localContext = localContext;\n if (!this.props.schema.sendFirstByClick || this.state.image !== undefined) {\n setTimeout(() => this.askInstance(), this.initialized ? 300 : 50);\n }\n this.initialized = true;\n }\n }\n\n if (!this.state.image && this.props.schema.sendFirstByClick) {\n return (\n <div\n style={{\n width: this.props.schema.width || '100%',\n height: this.props.schema.height,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n cursor: this.state.loading ? 'default' : 'pointer',\n }}\n onClick={() => !this.state.loading && this.askInstance()}\n >\n {this.state.loading ? (\n <CircularProgress />\n ) : typeof this.props.schema.sendFirstByClick === 'boolean' ? (\n I18n.t('jc_Click to show')\n ) : (\n this.getText(this.props.schema.sendFirstByClick, this.props.schema.noTranslation)\n )}\n </div>\n );\n }\n\n if (this.state.image === undefined) {\n return null;\n }\n\n return (\n <Icon\n title={this.getText(this.props.schema.tooltip)}\n src={this.state.image}\n style={{ width: this.props.schema.width || '100%', height: this.props.schema.height }}\n />\n );\n }\n}\n"]}
|
|
@@ -58,7 +58,7 @@ export default class ConfigJsonEditor extends ConfigGeneric {
|
|
|
58
58
|
const isReadOnly = schema.readOnly === true || disabled;
|
|
59
59
|
return (React.createElement(FormControl, { fullWidth: true, variant: "standard" },
|
|
60
60
|
React.createElement("div", { style: styles.flex },
|
|
61
|
-
React.createElement(Button, { color: "grey", style: styles.button, size: "small", variant: "outlined", onClick: () => this.setState({ showSelectId: true }) }, I18n.t('
|
|
61
|
+
React.createElement(Button, { color: "grey", style: styles.button, size: "small", variant: "outlined", onClick: () => this.setState({ showSelectId: true }) }, I18n.t('jc_JSON editor'))),
|
|
62
62
|
showSelectId ? (React.createElement(CustomModal, { title: this.getText(schema.label), overflowHidden: true, applyDisabled: (this.state.jsonError && this.props.schema.doNotApplyWithError) || isReadOnly, onClose: () => {
|
|
63
63
|
if (isReadOnly) {
|
|
64
64
|
this.setState({ showSelectId: false });
|
|
@@ -80,7 +80,7 @@ export default class ConfigJsonEditor extends ConfigGeneric {
|
|
|
80
80
|
jsonError: this.validateJson(newValue),
|
|
81
81
|
}), name: "ConfigJsonEditor", themeType: this.props.oContext.themeType })))) : null,
|
|
82
82
|
schema.help || this.state.jsonError ? (React.createElement(FormHelperText, null, this.state.jsonError
|
|
83
|
-
? I18n.t('
|
|
83
|
+
? I18n.t('jc_Invalid JSON')
|
|
84
84
|
: this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation))) : null));
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigJs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CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAChE,QAAQ,EACJ,UAAU;4BACN,CAAC,CAAC,SAAS;4BACX,CAAC,CAAC,QAAQ,CAAC,EAAE,CACP,IAAI,CAAC,QAAQ,CAAC;gCACV,KAAK,EAAE,QAAQ;gCACf,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC;6BACzC,CAAC,EAEhB,IAAI,EAAC,kBAAkB,EACvB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,GAC1C,CACA,CACI,CACjB,CAAC,CAAC,CAAC,IAAI;YACP,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CACnC,oBAAC,cAAc,QACV,IAAI,CAAC,KAAK,CAAC,SAAS;gBACjB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC;gBAC3B,CAAC,CAAC,IAAI,CAAC,UAAU,CACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,CACM,CACpB,CAAC,CAAC,CAAC,IAAI,CACE,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\nimport JSON5 from 'json5';\n\nimport { FormHelperText, FormControl, Button } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\nimport type { ConfigItemJsonEditor } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport CustomModal from './wrapper/Components/CustomModal';\nimport Editor from './wrapper/Components/Editor';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n flex: {\n display: 'flex',\n },\n button: {\n height: 48,\n // marginLeft: 4,\n minWidth: 48,\n },\n wrapper: {\n width: 'calc(100vw - 40px)',\n height: 'calc(100vh - 188px)',\n },\n};\n\ninterface ConfigJsonEditorProps extends ConfigGenericProps {\n schema: ConfigItemJsonEditor;\n}\n\ninterface ConfigJsonEditorState extends ConfigGenericState {\n initialized?: boolean;\n showSelectId?: boolean;\n jsonError?: boolean;\n}\n\nexport default class ConfigJsonEditor extends ConfigGeneric<ConfigJsonEditorProps, ConfigJsonEditorState> {\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n const { data, attr } = this.props;\n const value: string = ConfigGeneric.getValue(data, attr) || '{}';\n this.setState({ value, initialized: true, jsonError: this.validateJson(value) });\n }\n\n validateJson(value: string | null | undefined): boolean {\n let jsonError = false;\n if (this.props.schema.validateJson !== false) {\n if (value || !this.props.schema.allowEmpty) {\n try {\n if (this.props.schema.json5) {\n JSON5.parse(value);\n } else {\n JSON.parse(value);\n }\n } catch (err: unknown) {\n console.log('Error in JSON', err);\n jsonError = true;\n }\n }\n }\n\n return jsonError;\n }\n\n renderItem(_error: string, disabled: boolean /* , defaultValue */): JSX.Element | null {\n if (!this.state.initialized) {\n return null;\n }\n\n const { schema, data, attr } = this.props;\n const { value, showSelectId } = this.state;\n const isReadOnly = schema.readOnly === true || disabled;\n\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n <div style={styles.flex}>\n <Button\n color=\"grey\"\n style={styles.button}\n size=\"small\"\n variant=\"outlined\"\n onClick={() => this.setState({ showSelectId: true })}\n >\n {I18n.t('
|
|
1
|
+
{"version":3,"file":"ConfigJsonEditor.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigJsonEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD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,EAEhB,IAAI,EAAC,kBAAkB,EACvB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,GAC1C,CACA,CACI,CACjB,CAAC,CAAC,CAAC,IAAI;YACP,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CACnC,oBAAC,cAAc,QACV,IAAI,CAAC,KAAK,CAAC,SAAS;gBACjB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC;gBAC3B,CAAC,CAAC,IAAI,CAAC,UAAU,CACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,CACM,CACpB,CAAC,CAAC,CAAC,IAAI,CACE,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\nimport JSON5 from 'json5';\n\nimport { FormHelperText, FormControl, Button } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\nimport type { ConfigItemJsonEditor } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport CustomModal from './wrapper/Components/CustomModal';\nimport Editor from './wrapper/Components/Editor';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n flex: {\n display: 'flex',\n },\n button: {\n height: 48,\n // marginLeft: 4,\n minWidth: 48,\n },\n wrapper: {\n width: 'calc(100vw - 40px)',\n height: 'calc(100vh - 188px)',\n },\n};\n\ninterface ConfigJsonEditorProps extends ConfigGenericProps {\n schema: ConfigItemJsonEditor;\n}\n\ninterface ConfigJsonEditorState extends ConfigGenericState {\n initialized?: boolean;\n showSelectId?: boolean;\n jsonError?: boolean;\n}\n\nexport default class ConfigJsonEditor extends ConfigGeneric<ConfigJsonEditorProps, ConfigJsonEditorState> {\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n const { data, attr } = this.props;\n const value: string = ConfigGeneric.getValue(data, attr) || '{}';\n this.setState({ value, initialized: true, jsonError: this.validateJson(value) });\n }\n\n validateJson(value: string | null | undefined): boolean {\n let jsonError = false;\n if (this.props.schema.validateJson !== false) {\n if (value || !this.props.schema.allowEmpty) {\n try {\n if (this.props.schema.json5) {\n JSON5.parse(value);\n } else {\n JSON.parse(value);\n }\n } catch (err: unknown) {\n console.log('Error in JSON', err);\n jsonError = true;\n }\n }\n }\n\n return jsonError;\n }\n\n renderItem(_error: string, disabled: boolean /* , defaultValue */): JSX.Element | null {\n if (!this.state.initialized) {\n return null;\n }\n\n const { schema, data, attr } = this.props;\n const { value, showSelectId } = this.state;\n const isReadOnly = schema.readOnly === true || disabled;\n\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n <div style={styles.flex}>\n <Button\n color=\"grey\"\n style={styles.button}\n size=\"small\"\n variant=\"outlined\"\n onClick={() => this.setState({ showSelectId: true })}\n >\n {I18n.t('jc_JSON editor')}\n </Button>\n </div>\n {showSelectId ? (\n <CustomModal\n title={this.getText(schema.label)}\n overflowHidden\n applyDisabled={(this.state.jsonError && this.props.schema.doNotApplyWithError) || isReadOnly}\n onClose={() => {\n if (isReadOnly) {\n this.setState({ showSelectId: false });\n } else {\n this.setState({ showSelectId: false, value: ConfigGeneric.getValue(data, attr) || {} });\n }\n }}\n onApply={\n isReadOnly\n ? undefined\n : () => this.setState({ showSelectId: false }, () => this.onChange(attr, value))\n }\n >\n <div\n style={{\n ...styles.wrapper,\n border: this.state.jsonError ? '2px solid red' : '2px solid transparent',\n }}\n >\n <Editor\n mode={this.props.schema.json5 ? 'json5' : 'json'}\n value={typeof value === 'object' ? JSON.stringify(value) : value}\n onChange={\n isReadOnly\n ? undefined\n : newValue =>\n this.setState({\n value: newValue,\n jsonError: this.validateJson(newValue),\n })\n }\n name=\"ConfigJsonEditor\"\n themeType={this.props.oContext.themeType}\n />\n </div>\n </CustomModal>\n ) : null}\n {schema.help || this.state.jsonError ? (\n <FormHelperText>\n {this.state.jsonError\n ? I18n.t('jc_Invalid JSON')\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"]}
|
|
@@ -54,10 +54,10 @@ class ConfigLanguage extends ConfigGeneric {
|
|
|
54
54
|
const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
|
|
55
55
|
const languages = [...LANGUAGES];
|
|
56
56
|
if (this.props.schema.system) {
|
|
57
|
-
languages.unshift({ value: '', label: I18n.t('
|
|
57
|
+
languages.unshift({ value: '', label: I18n.t('jc_System language') });
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
languages.unshift({ value: '', label: I18n.t('
|
|
60
|
+
languages.unshift({ value: '', label: I18n.t('jc_none') });
|
|
61
61
|
}
|
|
62
62
|
this.setState({
|
|
63
63
|
value: this.props.schema.system ? value || '' : value || I18n.getLanguage(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigLanguage.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigLanguage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,SAAS,GAAG;IACd;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE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C,CAAC;qCACD,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC,CAAC;4BACtE,CAAC;wBACL,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,IAEA,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CACjC,oBAAC,QAAQ,IACL,GAAG,EAAE,EAAE,CAAC,KAAK,EACb,KAAK,EAAE,EAAE,CAAC,KAAK,IAEd,EAAE,CAAC,KAAK,CACF,CACd,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,cAAc,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { InputLabel, MenuItem, FormHelperText, FormControl, Select } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemLanguage } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst LANGUAGES = [\n {\n value: 'en',\n label: 'English',\n },\n {\n value: 'de',\n label: 'Deutsch',\n },\n {\n value: 'ru',\n label: 'русский',\n },\n {\n value: 'pt',\n label: 'Portugues',\n },\n {\n value: 'nl',\n label: 'Nederlands',\n },\n {\n value: 'fr',\n label: 'français',\n },\n {\n value: 'it',\n label: 'Italiano',\n },\n {\n value: 'es',\n label: 'Espanol',\n },\n {\n value: 'pl',\n label: 'Polski',\n },\n {\n value: 'uk',\n label: 'Український',\n },\n {\n value: 'zh-cn',\n label: '简体中文',\n },\n] as const;\n\ninterface LanguageSelectOption {\n /** Value to save */\n value: string;\n /** Label to show */\n label: string;\n}\n\ninterface ConfigLanguageProps extends ConfigGenericProps {\n schema: ConfigItemLanguage;\n}\n\ninterface ConfigLanguageState extends ConfigGenericState {\n selectOptions: LanguageSelectOption[];\n}\n\nclass ConfigLanguage extends ConfigGeneric<ConfigLanguageProps, ConfigLanguageState> {\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n const languages: LanguageSelectOption[] = [...LANGUAGES];\n if (this.props.schema.system) {\n languages.unshift({ value: '', label: I18n.t('ra_System language') });\n } else {\n languages.unshift({ value: '', label: I18n.t('ra_none') });\n }\n\n this.setState({\n value: this.props.schema.system ? value || '' : value || I18n.getLanguage(),\n selectOptions: languages,\n });\n }\n\n renderItem(error: unknown, disabled: boolean): JSX.Element | null {\n if (!this.state.selectOptions) {\n return null;\n }\n\n const item = this.state.selectOptions?.find(\n it => it.value === this.state.value || (!it.value && !this.state.value),\n );\n\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n {this.props.schema.label ? <InputLabel>{this.getText(this.props.schema.label)}</InputLabel> : null}\n <Select\n variant=\"standard\"\n error={!!error}\n disabled={disabled}\n value={this.state.value || '_'}\n renderValue={() => this.getText(item?.label, this.props.schema.noTranslation)}\n onChange={e => {\n let { value } = e.target;\n if (value === '_') {\n value = '';\n }\n\n this.setState({ value }, () => {\n const mayBePromise = this.onChange(this.props.attr, value);\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(err => console.error(err));\n }\n if (this.props.schema.changeGuiLanguage) {\n if (value) {\n if (value === I18n.getLanguage()) {\n return;\n }\n I18n.setLanguage(value);\n if (this.props.oContext.changeLanguage) {\n this.props.oContext.changeLanguage();\n }\n } else {\n void this.props.oContext.socket\n .getSystemConfig()\n .then((systemConfig: ioBroker.SystemConfigObject) => {\n if (systemConfig.common.language === I18n.getLanguage()) {\n return;\n }\n if (systemConfig.common.language) {\n I18n.setLanguage(systemConfig.common.language);\n if (this.props.oContext.changeLanguage) {\n this.props.oContext.changeLanguage();\n }\n }\n })\n .catch(e => console.error(`Cannot read system config: ${e}`));\n }\n }\n });\n }}\n >\n {this.state.selectOptions?.map(it => (\n <MenuItem\n key={it.value}\n value={it.value}\n >\n {it.label}\n </MenuItem>\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 ConfigLanguage;\n"]}
|
|
1
|
+
{"version":3,"file":"ConfigLanguage.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigLanguage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,SAAS,GAAG;IACd;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACnB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,WAAW;KACrB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,YAAY;KACtB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,UAAU;KACpB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,UAAU;KACpB;IACD;QACI,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,S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EAAE,CAAC,EAAE,CAAC,CACjC,oBAAC,QAAQ,IACL,GAAG,EAAE,EAAE,CAAC,KAAK,EACb,KAAK,EAAE,EAAE,CAAC,KAAK,IAEd,EAAE,CAAC,KAAK,CACF,CACd,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,cAAc,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { InputLabel, MenuItem, FormHelperText, FormControl, Select } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemLanguage } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst LANGUAGES = [\n {\n value: 'en',\n label: 'English',\n },\n {\n value: 'de',\n label: 'Deutsch',\n },\n {\n value: 'ru',\n label: 'русский',\n },\n {\n value: 'pt',\n label: 'Portugues',\n },\n {\n value: 'nl',\n label: 'Nederlands',\n },\n {\n value: 'fr',\n label: 'français',\n },\n {\n value: 'it',\n label: 'Italiano',\n },\n {\n value: 'es',\n label: 'Espanol',\n },\n {\n value: 'pl',\n label: 'Polski',\n },\n {\n value: 'uk',\n label: 'Український',\n },\n {\n value: 'zh-cn',\n label: '简体中文',\n },\n] as const;\n\ninterface LanguageSelectOption {\n /** Value to save */\n value: string;\n /** Label to show */\n label: string;\n}\n\ninterface ConfigLanguageProps extends ConfigGenericProps {\n schema: ConfigItemLanguage;\n}\n\ninterface ConfigLanguageState extends ConfigGenericState {\n selectOptions: LanguageSelectOption[];\n}\n\nclass ConfigLanguage extends ConfigGeneric<ConfigLanguageProps, ConfigLanguageState> {\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n const languages: LanguageSelectOption[] = [...LANGUAGES];\n if (this.props.schema.system) {\n languages.unshift({ value: '', label: I18n.t('jc_System language') });\n } else {\n languages.unshift({ value: '', label: I18n.t('jc_none') });\n }\n\n this.setState({\n value: this.props.schema.system ? value || '' : value || I18n.getLanguage(),\n selectOptions: languages,\n });\n }\n\n renderItem(error: unknown, disabled: boolean): JSX.Element | null {\n if (!this.state.selectOptions) {\n return null;\n }\n\n const item = this.state.selectOptions?.find(\n it => it.value === this.state.value || (!it.value && !this.state.value),\n );\n\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n {this.props.schema.label ? <InputLabel>{this.getText(this.props.schema.label)}</InputLabel> : null}\n <Select\n variant=\"standard\"\n error={!!error}\n disabled={disabled}\n value={this.state.value || '_'}\n renderValue={() => this.getText(item?.label, this.props.schema.noTranslation)}\n onChange={e => {\n let { value } = e.target;\n if (value === '_') {\n value = '';\n }\n\n this.setState({ value }, () => {\n const mayBePromise = this.onChange(this.props.attr, value);\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(err => console.error(err));\n }\n if (this.props.schema.changeGuiLanguage) {\n if (value) {\n if (value === I18n.getLanguage()) {\n return;\n }\n I18n.setLanguage(value);\n if (this.props.oContext.changeLanguage) {\n this.props.oContext.changeLanguage();\n }\n } else {\n void this.props.oContext.socket\n .getSystemConfig()\n .then((systemConfig: ioBroker.SystemConfigObject) => {\n if (systemConfig.common.language === I18n.getLanguage()) {\n return;\n }\n if (systemConfig.common.language) {\n I18n.setLanguage(systemConfig.common.language);\n if (this.props.oContext.changeLanguage) {\n this.props.oContext.changeLanguage();\n }\n }\n })\n .catch(e => console.error(`Cannot read system config: ${e}`));\n }\n }\n });\n }}\n >\n {this.state.selectOptions?.map(it => (\n <MenuItem\n key={it.value}\n value={it.value}\n >\n {it.label}\n </MenuItem>\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 ConfigLanguage;\n"]}
|
|
@@ -61,7 +61,7 @@ class ConfigLicense extends ConfigGeneric {
|
|
|
61
61
|
this.setState({ showLicenseDialog: false });
|
|
62
62
|
}
|
|
63
63
|
} },
|
|
64
|
-
React.createElement(DialogTitle, null, this.props.schema.title ? I18n.t(this.props.schema.title) : I18n.t('
|
|
64
|
+
React.createElement(DialogTitle, null, this.props.schema.title ? I18n.t(this.props.schema.title) : I18n.t('jc_License agreement')),
|
|
65
65
|
React.createElement(DialogContent, null,
|
|
66
66
|
this.props.schema.licenseUrl ? (React.createElement(React.Fragment, null,
|
|
67
67
|
this.state.loading ? React.createElement(LinearProgress, null) : null,
|
|
@@ -91,11 +91,11 @@ class ConfigLicense extends ConfigGeneric {
|
|
|
91
91
|
}
|
|
92
92
|
}, color: "primary", variant: "contained", startIcon: React.createElement(Check, null) }, this.props.schema.agreeText
|
|
93
93
|
? I18n.t(this.props.schema.agreeText)
|
|
94
|
-
: I18n.t('
|
|
94
|
+
: I18n.t('jc_Accept license')),
|
|
95
95
|
React.createElement(Button, { onClick: () => {
|
|
96
96
|
this.setState({ showLicenseDialog: false });
|
|
97
97
|
setTimeout(() => this.setState({ showLicenseDialog: true }), 2000);
|
|
98
|
-
}, color: "grey", variant: "contained", startIcon: React.createElement(Close, null) }, I18n.t('
|
|
98
|
+
}, color: "grey", variant: "contained", startIcon: React.createElement(Close, null) }, I18n.t('jc_Close')))));
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
export default ConfigLicense;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigLicense.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigLicense.tsx"],"names":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ialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n LinearProgress,\n FormControlLabel,\n Checkbox,\n} from '@mui/material';\n\nimport { Check, Close } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemLicense } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigLicenseProps extends ConfigGenericProps {\n schema: ConfigItemLicense;\n}\n\ninterface ConfigLicenseState extends ConfigGenericState {\n showLicenseDialog?: boolean;\n licenseChecked?: boolean;\n license?: string;\n loading?: boolean;\n error?: boolean;\n scrolledDown?: boolean;\n}\n\nclass ConfigLicense extends ConfigGeneric<ConfigLicenseProps, ConfigLicenseState> {\n private readonly scrollRef: React.RefObject<HTMLDivElement | HTMLPreElement>;\n\n constructor(props: ConfigLicenseProps) {\n super(props);\n this.scrollRef = React.createRef();\n }\n\n scrolledDown(): boolean {\n if (!this.scrollRef.current) {\n return false;\n }\n return (\n this.scrollRef.current.offsetHeight + this.scrollRef.current.scrollTop >=\n this.scrollRef.current.scrollHeight\n );\n }\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n if (!ConfigGeneric.getValue(this.props.data, this.props.attr)) {\n if (this.props.schema.licenseUrl) {\n this.setState({ showLicenseDialog: true, loading: true, scrolledDown: false });\n\n fetch(this.props.schema.licenseUrl)\n .then(res => res.text())\n .then(text => this.setState({ license: text, loading: false }))\n .catch(e =>\n this.setState({\n license: e.toString(),\n loading: false,\n error: true,\n scrolledDown: false,\n }),\n );\n } else {\n this.setState({ showLicenseDialog: true, scrolledDown: false });\n }\n setTimeout(() => {\n // install scroll handler\n if (this.scrollRef.current) {\n const scrolledDown = this.scrolledDown();\n if (!scrolledDown) {\n this.scrollRef.current.addEventListener('scroll', () => {\n if (!this.state.scrolledDown && this.scrolledDown()) {\n this.setState({ scrolledDown: true });\n }\n });\n } else {\n this.setState({ scrolledDown: true });\n }\n }\n }, 1000);\n }\n }\n\n renderItem(_error: string, disabled: boolean /*, defaultValue */): JSX.Element | null {\n if (!this.state.showLicenseDialog) {\n return null;\n }\n\n return (\n <Dialog\n maxWidth=\"lg\"\n open={!0}\n onClose={(e, reason) => {\n if (reason !== 'escapeKeyDown' && reason !== 'backdropClick') {\n this.setState({ showLicenseDialog: false });\n }\n }}\n >\n <DialogTitle>\n {this.props.schema.title ? I18n.t(this.props.schema.title) : I18n.t('ra_License agreement')}\n </DialogTitle>\n <DialogContent>\n {this.props.schema.licenseUrl ? (\n <>\n {this.state.loading ? <LinearProgress /> : null}\n <pre\n ref={this.scrollRef as React.RefObject<HTMLPreElement>}\n style={{\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n fontSize: 14,\n }}\n >\n {this.state.license}\n </pre>\n </>\n ) : null}\n {!this.props.schema.licenseUrl && this.props.schema.texts ? (\n <div\n ref={this.scrollRef as React.RefObject<HTMLDivElement>}\n style={{\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n fontSize: 14,\n }}\n >\n {this.props.schema.texts.map((text, i) =>\n this.props.schema.noTranslation ? <p key={i}>{text}</p> : <p key={i}>{I18n.t(text)}</p>,\n )}\n </div>\n ) : null}\n </DialogContent>\n <DialogActions>\n {this.props.schema.checkBox ? (\n <FormControlLabel\n control={\n <Checkbox\n disabled={disabled}\n checked={!!this.state.licenseChecked}\n onClick={() => this.setState({ licenseChecked: !this.state.licenseChecked })}\n />\n }\n label={I18n.t(this.props.schema.checkBox)}\n />\n ) : null}\n <Button\n disabled={\n disabled ||\n this.state.loading ||\n this.state.error ||\n (this.props.schema.checkBox && !this.state.licenseChecked) ||\n !this.state.scrolledDown\n }\n onClick={() => {\n this.setState({ showLicenseDialog: false });\n const mayBePromise = this.onChange(this.props.attr, true);\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n color=\"primary\"\n variant=\"contained\"\n startIcon={<Check />}\n >\n {this.props.schema.agreeText\n ? I18n.t(this.props.schema.agreeText)\n : I18n.t('ra_Accept license')}\n </Button>\n <Button\n onClick={() => {\n this.setState({ showLicenseDialog: false });\n setTimeout(() => this.setState({ showLicenseDialog: true }), 2000);\n }}\n color=\"grey\"\n variant=\"contained\"\n startIcon={<Close />}\n >\n {I18n.t('ra_Close')}\n </Button>\n </DialogActions>\n </Dialog>\n );\n }\n}\n\nexport default ConfigLicense;\n"]}
|
|
1
|
+
{"version":3,"file":"ConfigLicense.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigLicense.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EACH,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,QAAQ,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAelG,MAAM,aAAc,SAAQ,aAAqD;IAC5D,SAAS,CAAmD;IAE7E,YAAY,KAAyB;QACjC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IACvC,CAAC;IAED,YAAY;QACR,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CACH,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS;YACtE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,CACtC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,iBAAiB;QACnB,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAChC,IAAI,CAAC,aAAa,CAAC,QAAQ,CA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QAAQ,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;oBACvE,CAAC,EACD,KAAK,EAAC,MAAM,EACZ,OAAO,EAAC,WAAW,EACnB,SAAS,EAAE,oBAAC,KAAK,OAAG,IAEnB,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CACd,CACG,CACX,CACZ,CAAC;IACN,CAAC;CACJ;AAED,eAAe,aAAa,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport {\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n LinearProgress,\n FormControlLabel,\n Checkbox,\n} from '@mui/material';\n\nimport { Check, Close } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemLicense } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigLicenseProps extends ConfigGenericProps {\n schema: ConfigItemLicense;\n}\n\ninterface ConfigLicenseState extends ConfigGenericState {\n showLicenseDialog?: boolean;\n licenseChecked?: boolean;\n license?: string;\n loading?: boolean;\n error?: boolean;\n scrolledDown?: boolean;\n}\n\nclass ConfigLicense extends ConfigGeneric<ConfigLicenseProps, ConfigLicenseState> {\n private readonly scrollRef: React.RefObject<HTMLDivElement | HTMLPreElement>;\n\n constructor(props: ConfigLicenseProps) {\n super(props);\n this.scrollRef = React.createRef();\n }\n\n scrolledDown(): boolean {\n if (!this.scrollRef.current) {\n return false;\n }\n return (\n this.scrollRef.current.offsetHeight + this.scrollRef.current.scrollTop >=\n this.scrollRef.current.scrollHeight\n );\n }\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n if (!ConfigGeneric.getValue(this.props.data, this.props.attr)) {\n if (this.props.schema.licenseUrl) {\n this.setState({ showLicenseDialog: true, loading: true, scrolledDown: false });\n\n fetch(this.props.schema.licenseUrl)\n .then(res => res.text())\n .then(text => this.setState({ license: text, loading: false }))\n .catch(e =>\n this.setState({\n license: e.toString(),\n loading: false,\n error: true,\n scrolledDown: false,\n }),\n );\n } else {\n this.setState({ showLicenseDialog: true, scrolledDown: false });\n }\n setTimeout(() => {\n // install scroll handler\n if (this.scrollRef.current) {\n const scrolledDown = this.scrolledDown();\n if (!scrolledDown) {\n this.scrollRef.current.addEventListener('scroll', () => {\n if (!this.state.scrolledDown && this.scrolledDown()) {\n this.setState({ scrolledDown: true });\n }\n });\n } else {\n this.setState({ scrolledDown: true });\n }\n }\n }, 1000);\n }\n }\n\n renderItem(_error: string, disabled: boolean /*, defaultValue */): JSX.Element | null {\n if (!this.state.showLicenseDialog) {\n return null;\n }\n\n return (\n <Dialog\n maxWidth=\"lg\"\n open={!0}\n onClose={(e, reason) => {\n if (reason !== 'escapeKeyDown' && reason !== 'backdropClick') {\n this.setState({ showLicenseDialog: false });\n }\n }}\n >\n <DialogTitle>\n {this.props.schema.title ? I18n.t(this.props.schema.title) : I18n.t('jc_License agreement')}\n </DialogTitle>\n <DialogContent>\n {this.props.schema.licenseUrl ? (\n <>\n {this.state.loading ? <LinearProgress /> : null}\n <pre\n ref={this.scrollRef as React.RefObject<HTMLPreElement>}\n style={{\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n fontSize: 14,\n }}\n >\n {this.state.license}\n </pre>\n </>\n ) : null}\n {!this.props.schema.licenseUrl && this.props.schema.texts ? (\n <div\n ref={this.scrollRef as React.RefObject<HTMLDivElement>}\n style={{\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n fontSize: 14,\n }}\n >\n {this.props.schema.texts.map((text, i) =>\n this.props.schema.noTranslation ? <p key={i}>{text}</p> : <p key={i}>{I18n.t(text)}</p>,\n )}\n </div>\n ) : null}\n </DialogContent>\n <DialogActions>\n {this.props.schema.checkBox ? (\n <FormControlLabel\n control={\n <Checkbox\n disabled={disabled}\n checked={!!this.state.licenseChecked}\n onClick={() => this.setState({ licenseChecked: !this.state.licenseChecked })}\n />\n }\n label={I18n.t(this.props.schema.checkBox)}\n />\n ) : null}\n <Button\n disabled={\n disabled ||\n this.state.loading ||\n this.state.error ||\n (this.props.schema.checkBox && !this.state.licenseChecked) ||\n !this.state.scrolledDown\n }\n onClick={() => {\n this.setState({ showLicenseDialog: false });\n const mayBePromise = this.onChange(this.props.attr, true);\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n color=\"primary\"\n variant=\"contained\"\n startIcon={<Check />}\n >\n {this.props.schema.agreeText\n ? I18n.t(this.props.schema.agreeText)\n : I18n.t('jc_Accept license')}\n </Button>\n <Button\n onClick={() => {\n this.setState({ showLicenseDialog: false });\n setTimeout(() => this.setState({ showLicenseDialog: true }), 2000);\n }}\n color=\"grey\"\n variant=\"contained\"\n startIcon={<Close />}\n >\n {I18n.t('jc_Close')}\n </Button>\n </DialogActions>\n </Dialog>\n );\n }\n}\n\nexport default ConfigLicense;\n"]}
|
|
@@ -56,21 +56,21 @@ class ConfigNumber extends ConfigGeneric {
|
|
|
56
56
|
}
|
|
57
57
|
const f = value === '' ? 0 : parseFloat(value);
|
|
58
58
|
if (value !== '' && Number.isNaN(f)) {
|
|
59
|
-
return '
|
|
59
|
+
return 'jc_Not a number';
|
|
60
60
|
}
|
|
61
61
|
if (value !== '' && window.isFinite(f)) {
|
|
62
62
|
if (this.props.schema.min !== undefined && f < this.props.schema.min) {
|
|
63
|
-
return '
|
|
63
|
+
return 'jc_Too small';
|
|
64
64
|
}
|
|
65
65
|
if (this.props.schema.max !== undefined && f > this.props.schema.max) {
|
|
66
|
-
return '
|
|
66
|
+
return 'jc_Too big';
|
|
67
67
|
}
|
|
68
68
|
if (value === '' || value === '-' || Number.isNaN(f)) {
|
|
69
|
-
return '
|
|
69
|
+
return 'jc_Not a number';
|
|
70
70
|
}
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
return '
|
|
73
|
+
return 'jc_Not a number';
|
|
74
74
|
}
|
|
75
75
|
renderItem(error, disabled) {
|
|
76
76
|
const isIndeterminate = Array.isArray(this.state._value) || this.state._value === ConfigGeneric.DIFFERENT_VALUE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigNumber.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigNumber.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,aAAa,EAAE;QACX,OAAO,EAAE,GAAG;KACf;IACD,OAAO,EAAE;QACL,aAAa,EAAE,KAAK;QACpB,KAAK,EAAE,MAAM;KAChB;CACJ,CAAC;AAWF,MAAM,YAAa,SAAQ,aAAmD;IAClE,aAAa,CAAiC;IAEtD,KAAK,CAAC,iBAAiB;QACnB,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAChC,IAAI,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEtE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,GAAG,EAAE,CAAC;QAChB,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACzD,MAAM,GAAG,aAAa,CAAC,eAAe,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5C,OAAO;QACX,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAA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AAI,CAAC,UAAU,CACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,GAEb,CACQ,CACjB,CAAC;IACN,CAAC;CACJ;AAED,eAAe,YAAY,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Autocomplete, TextField, FormControl } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemNumber } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n indeterminate: {\n opacity: 0.5,\n },\n control: {\n flexDirection: 'row',\n width: '100%',\n },\n};\n\ninterface ConfigNumberProps extends ConfigGenericProps {\n schema: ConfigItemNumber;\n}\n\ninterface ConfigNumberState extends ConfigGenericState {\n _value: string;\n oldValue: string | null;\n}\n\nclass ConfigNumber extends ConfigGeneric<ConfigNumberProps, ConfigNumberState> {\n private updateTimeout?: ReturnType<typeof setTimeout>;\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n let _value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n\n if (_value === null || _value === undefined) {\n _value = '';\n }\n\n if (Array.isArray(_value) && this.props.oContext.multiEdit) {\n _value = ConfigGeneric.DIFFERENT_VALUE;\n this.setState({ _value, oldValue: _value });\n return;\n }\n\n this.setState({ _value: _value.toString(), oldValue: _value.toString() });\n }\n\n static getDerivedStateFromProps(\n props: ConfigNumberProps,\n state: ConfigNumberState,\n ): Partial<ConfigNumberState> | null {\n if (\n (props.schema.min !== undefined && props.schema.min < 0) ||\n (props.schema.max !== undefined && props.schema.max < 0)\n ) {\n return null;\n }\n const _value = ConfigGeneric.getValue(props.data, props.attr);\n\n if (props.oContext.multiEdit && state._value === ConfigGeneric.DIFFERENT_VALUE) {\n return { _value: ConfigGeneric.DIFFERENT_VALUE };\n }\n\n if (\n _value === null ||\n _value === undefined ||\n state.oldValue === null ||\n state.oldValue === undefined ||\n (_value.toString() !== parseFloat(state._value).toString() &&\n _value.toString() !== state.oldValue.toString())\n ) {\n return { _value };\n }\n\n return null;\n }\n\n checkValue(value: string): string | null {\n if (value === null || value === undefined) {\n return null;\n }\n value = value.toString().trim().replace(',', '.');\n if (value === '-') {\n // User wants to enter a negative number\n return null;\n }\n\n const f = value === '' ? 0 : parseFloat(value);\n\n if (value !== '' && Number.isNaN(f)) {\n return 'ra_Not a number';\n }\n\n if (value !== '' && window.isFinite(f)) {\n if (this.props.schema.min !== undefined && f < this.props.schema.min) {\n return 'ra_Too small';\n }\n if (this.props.schema.max !== undefined && f > this.props.schema.max) {\n return 'ra_Too big';\n }\n if (value === '' || value === '-' || Number.isNaN(f)) {\n return 'ra_Not a number';\n }\n\n return null;\n }\n\n return 'ra_Not a number';\n }\n\n renderItem(error: unknown, disabled: boolean): JSX.Element | null {\n const isIndeterminate = Array.isArray(this.state._value) || this.state._value === ConfigGeneric.DIFFERENT_VALUE;\n\n if (this.state.oldValue !== null && this.state.oldValue !== undefined) {\n if (this.updateTimeout) {\n clearTimeout(this.updateTimeout);\n }\n this.updateTimeout = setTimeout(() => {\n this.updateTimeout = undefined;\n this.setState({ oldValue: null });\n }, 30);\n } else if (this.updateTimeout) {\n clearTimeout(this.updateTimeout);\n this.updateTimeout = undefined;\n }\n\n if (isIndeterminate) {\n const autoCompleteOptions = ConfigGeneric.getValue(this.props.data, this.props.attr);\n const arr =\n autoCompleteOptions\n ?.filter((a: number | null | undefined) => a || a === 0)\n .map((item: number) => ({ label: item.toString(), value: item })) || [];\n\n arr.unshift({ label: I18n.t(ConfigGeneric.DIFFERENT_LABEL), value: ConfigGeneric.DIFFERENT_VALUE });\n\n return (\n <Autocomplete\n style={styles.indeterminate}\n fullWidth\n freeSolo\n value={arr[0]}\n // @ts-expect-error needs investigation if this really has no effect\n getOptionSelected={(option, value) => option.label === value.label}\n onChange={(_, value: (typeof arr)[number]) => {\n const mayBePromise = this.onChange(this.props.attr, value?.value, () => {\n this.setState({ _value: value?.value, oldValue: this.state._value });\n });\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n }}\n options={arr}\n getOptionLabel={(option: (typeof arr)[number]) => option.label}\n renderInput={params => (\n <TextField\n {...params}\n label={this.getText(this.props.schema.label)}\n variant=\"standard\"\n slotProps={{\n htmlInput: {\n ...params.inputProps,\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment: this.props.schema.unit\n ? this.getText(this.props.schema.unit, this.props.schema.noTranslation)\n : undefined,\n },\n }}\n error={!!error}\n placeholder={this.getText(this.props.schema.placeholder)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n disabled={!!disabled}\n />\n )}\n />\n );\n }\n if (!error && this.state._value !== null && this.state._value !== undefined && this.state._value) {\n error = this.checkValue(this.state._value);\n if (error) {\n error = I18n.t(error as string);\n }\n }\n const parsed = parseFloat(this.state._value?.toString().replace(',', '.') || '');\n\n return (\n <FormControl\n variant=\"standard\"\n style={styles.control}\n >\n <TextField\n sx={{\n '& .up-down': {\n display: 'none',\n },\n '&:hover .up-down': {\n display: 'block',\n },\n }}\n variant=\"standard\"\n type={\n // because some users want to enter \"-\" first\n Number.isNaN(parsed)\n ? 'text'\n : this.props.schema.min !== undefined && this.props.schema.min >= 0\n ? 'number'\n : 'text'\n }\n fullWidth\n slotProps={{\n htmlInput: {\n min: this.props.schema.min,\n max: this.props.schema.max,\n step: this.props.schema.step,\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment: this.props.schema.unit\n ? this.getText(this.props.schema.unit, this.props.schema.noTranslation)\n : null,\n },\n }}\n value={this.state._value ?? ''}\n error={!!error}\n disabled={!!disabled}\n onChange={e => {\n const _value = e.target.value; // value is always a string and it is validly formatted\n const _error = this.checkValue(_value);\n if (_error) {\n this.onError(this.props.attr, I18n.t(_error));\n } else {\n this.onError(this.props.attr); // clear error\n }\n\n this.setState({ _value, oldValue: this.state._value }, () => {\n const parsed = parseFloat(_value.toString().replace(',', '.'));\n if (!Number.isNaN(parsed)) {\n void this.onChange(this.props.attr, parsed);\n } else {\n void this.onChange(this.props.attr, _value.toString().replace(',', '.'));\n }\n });\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={\n error && typeof error === 'string'\n ? error\n : this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )\n }\n />\n </FormControl>\n );\n }\n}\n\nexport default ConfigNumber;\n"]}
|
|
1
|
+
{"version":3,"file":"ConfigNumber.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigNumber.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,aAAa,EAAE;QACX,OAAO,EAAE,GAAG;KACf;IACD,OAAO,EAAE;QACL,aAAa,EAAE,KAAK;QACpB,KAAK,EAAE,MAAM;KAChB;CACJ,CAAC;AAWF,MAAM,YAAa,SAAQ,aAAmD;IAClE,aAAa,CAAiC;IAEtD,KAAK,CAAC,iBAAiB;QACnB,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAChC,IAAI,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEtE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,GAAG,EAAE,CAAC;QAChB,CAAC;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;wBAC7E,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,EACD,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,EACxD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAC5C,UAAU,EACN,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;oBAC9B,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,IAAI,CAAC,UAAU,CACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,GAEb,CACQ,CACjB,CAAC;IACN,CAAC;CACJ;AAED,eAAe,YAAY,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Autocomplete, TextField, FormControl } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemNumber } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n indeterminate: {\n opacity: 0.5,\n },\n control: {\n flexDirection: 'row',\n width: '100%',\n },\n};\n\ninterface ConfigNumberProps extends ConfigGenericProps {\n schema: ConfigItemNumber;\n}\n\ninterface ConfigNumberState extends ConfigGenericState {\n _value: string;\n oldValue: string | null;\n}\n\nclass ConfigNumber extends ConfigGeneric<ConfigNumberProps, ConfigNumberState> {\n private updateTimeout?: ReturnType<typeof setTimeout>;\n\n async componentDidMount(): Promise<void> {\n await super.componentDidMount();\n let _value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n\n if (_value === null || _value === undefined) {\n _value = '';\n }\n\n if (Array.isArray(_value) && this.props.oContext.multiEdit) {\n _value = ConfigGeneric.DIFFERENT_VALUE;\n this.setState({ _value, oldValue: _value });\n return;\n }\n\n this.setState({ _value: _value.toString(), oldValue: _value.toString() });\n }\n\n static getDerivedStateFromProps(\n props: ConfigNumberProps,\n state: ConfigNumberState,\n ): Partial<ConfigNumberState> | null {\n if (\n (props.schema.min !== undefined && props.schema.min < 0) ||\n (props.schema.max !== undefined && props.schema.max < 0)\n ) {\n return null;\n }\n const _value = ConfigGeneric.getValue(props.data, props.attr);\n\n if (props.oContext.multiEdit && state._value === ConfigGeneric.DIFFERENT_VALUE) {\n return { _value: ConfigGeneric.DIFFERENT_VALUE };\n }\n\n if (\n _value === null ||\n _value === undefined ||\n state.oldValue === null ||\n state.oldValue === undefined ||\n (_value.toString() !== parseFloat(state._value).toString() &&\n _value.toString() !== state.oldValue.toString())\n ) {\n return { _value };\n }\n\n return null;\n }\n\n checkValue(value: string): string | null {\n if (value === null || value === undefined) {\n return null;\n }\n value = value.toString().trim().replace(',', '.');\n if (value === '-') {\n // User wants to enter a negative number\n return null;\n }\n\n const f = value === '' ? 0 : parseFloat(value);\n\n if (value !== '' && Number.isNaN(f)) {\n return 'jc_Not a number';\n }\n\n if (value !== '' && window.isFinite(f)) {\n if (this.props.schema.min !== undefined && f < this.props.schema.min) {\n return 'jc_Too small';\n }\n if (this.props.schema.max !== undefined && f > this.props.schema.max) {\n return 'jc_Too big';\n }\n if (value === '' || value === '-' || Number.isNaN(f)) {\n return 'jc_Not a number';\n }\n\n return null;\n }\n\n return 'jc_Not a number';\n }\n\n renderItem(error: unknown, disabled: boolean): JSX.Element | null {\n const isIndeterminate = Array.isArray(this.state._value) || this.state._value === ConfigGeneric.DIFFERENT_VALUE;\n\n if (this.state.oldValue !== null && this.state.oldValue !== undefined) {\n if (this.updateTimeout) {\n clearTimeout(this.updateTimeout);\n }\n this.updateTimeout = setTimeout(() => {\n this.updateTimeout = undefined;\n this.setState({ oldValue: null });\n }, 30);\n } else if (this.updateTimeout) {\n clearTimeout(this.updateTimeout);\n this.updateTimeout = undefined;\n }\n\n if (isIndeterminate) {\n const autoCompleteOptions = ConfigGeneric.getValue(this.props.data, this.props.attr);\n const arr =\n autoCompleteOptions\n ?.filter((a: number | null | undefined) => a || a === 0)\n .map((item: number) => ({ label: item.toString(), value: item })) || [];\n\n arr.unshift({ label: I18n.t(ConfigGeneric.DIFFERENT_LABEL), value: ConfigGeneric.DIFFERENT_VALUE });\n\n return (\n <Autocomplete\n style={styles.indeterminate}\n fullWidth\n freeSolo\n value={arr[0]}\n // @ts-expect-error needs investigation if this really has no effect\n getOptionSelected={(option, value) => option.label === value.label}\n onChange={(_, value: (typeof arr)[number]) => {\n const mayBePromise = this.onChange(this.props.attr, value?.value, () => {\n this.setState({ _value: value?.value, oldValue: this.state._value });\n });\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n }}\n options={arr}\n getOptionLabel={(option: (typeof arr)[number]) => option.label}\n renderInput={params => (\n <TextField\n {...params}\n label={this.getText(this.props.schema.label)}\n variant=\"standard\"\n slotProps={{\n htmlInput: {\n ...params.inputProps,\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment: this.props.schema.unit\n ? this.getText(this.props.schema.unit, this.props.schema.noTranslation)\n : undefined,\n },\n }}\n error={!!error}\n placeholder={this.getText(this.props.schema.placeholder)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n disabled={!!disabled}\n />\n )}\n />\n );\n }\n if (!error && this.state._value !== null && this.state._value !== undefined && this.state._value) {\n error = this.checkValue(this.state._value);\n if (error) {\n error = I18n.t(error as string);\n }\n }\n const parsed = parseFloat(this.state._value?.toString().replace(',', '.') || '');\n\n return (\n <FormControl\n variant=\"standard\"\n style={styles.control}\n >\n <TextField\n sx={{\n '& .up-down': {\n display: 'none',\n },\n '&:hover .up-down': {\n display: 'block',\n },\n }}\n variant=\"standard\"\n type={\n // because some users want to enter \"-\" first\n Number.isNaN(parsed)\n ? 'text'\n : this.props.schema.min !== undefined && this.props.schema.min >= 0\n ? 'number'\n : 'text'\n }\n fullWidth\n slotProps={{\n htmlInput: {\n min: this.props.schema.min,\n max: this.props.schema.max,\n step: this.props.schema.step,\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment: this.props.schema.unit\n ? this.getText(this.props.schema.unit, this.props.schema.noTranslation)\n : null,\n },\n }}\n value={this.state._value ?? ''}\n error={!!error}\n disabled={!!disabled}\n onChange={e => {\n const _value = e.target.value; // value is always a string and it is validly formatted\n const _error = this.checkValue(_value);\n if (_error) {\n this.onError(this.props.attr, I18n.t(_error));\n } else {\n this.onError(this.props.attr); // clear error\n }\n\n this.setState({ _value, oldValue: this.state._value }, () => {\n const parsed = parseFloat(_value.toString().replace(',', '.'));\n if (!Number.isNaN(parsed)) {\n void this.onChange(this.props.attr, parsed);\n } else {\n void this.onChange(this.props.attr, _value.toString().replace(',', '.'));\n }\n });\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={\n error && typeof error === 'string'\n ? error\n : this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )\n }\n />\n </FormControl>\n );\n }\n}\n\nexport default ConfigNumber;\n"]}
|
|
@@ -148,19 +148,19 @@ export default class ConfigOAuth2 extends ConfigGeneric {
|
|
|
148
148
|
if (this.state.accessTokens) {
|
|
149
149
|
label = this.props.schema.refreshLabel
|
|
150
150
|
? this.getText(this.props.schema.refreshLabel)
|
|
151
|
-
: I18n.t('
|
|
151
|
+
: I18n.t('jc_Renew %s access', this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1));
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
154
|
label = this.props.schema.label
|
|
155
155
|
? this.getText(this.props.schema.label)
|
|
156
|
-
: I18n.t('
|
|
156
|
+
: I18n.t('jc_Get %s access', this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1));
|
|
157
157
|
}
|
|
158
158
|
const icon = this.getIcon();
|
|
159
159
|
return (React.createElement("div", { style: { width: '100%', margin: '0 0 1rem 0' } },
|
|
160
160
|
this.props.schema.ownClientId ? (React.createElement(TextField, { value: this.state.clientId, onChange: e => {
|
|
161
161
|
const value = e.target.value;
|
|
162
162
|
this.setState({ clientId: value }, () => this.onChange(this.props.schema.ownClientId, value));
|
|
163
|
-
}, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientId, disabled: !!disabled, label: I18n.t('
|
|
163
|
+
}, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientId, disabled: !!disabled, label: I18n.t('jc_OAuth Client ID'), slotProps: {
|
|
164
164
|
input: {
|
|
165
165
|
endAdornment: this.state.clientId ? (React.createElement(IconButton, { size: "small", tabIndex: -1, onClick: () => this.setState({ clientId: '' }, () => this.onChange(this.props.schema.ownClientId, '')) },
|
|
166
166
|
React.createElement(CloseIcon, null))) : null,
|
|
@@ -169,7 +169,7 @@ export default class ConfigOAuth2 extends ConfigGeneric {
|
|
|
169
169
|
this.props.schema.ownClientSecret ? (React.createElement(TextField, { value: this.state.clientSecret, onChange: e => {
|
|
170
170
|
const value = e.target.value;
|
|
171
171
|
this.setState({ clientSecret: value }, () => this.onChange(this.props.schema.ownClientSecret, value));
|
|
172
|
-
}, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientSecret, disabled: !!disabled, label: I18n.t('
|
|
172
|
+
}, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientSecret, disabled: !!disabled, label: I18n.t('jc_OAuth Client secret'), slotProps: {
|
|
173
173
|
input: {
|
|
174
174
|
endAdornment: this.state.clientSecret ? (React.createElement(IconButton, { size: "small", tabIndex: -1, onClick: () => this.setState({ clientSecret: '' }, () => this.onChange(this.props.schema.ownClientSecret, '')) },
|
|
175
175
|
React.createElement(CloseIcon, null))) : null,
|
|
@@ -178,18 +178,18 @@ export default class ConfigOAuth2 extends ConfigGeneric {
|
|
|
178
178
|
React.createElement(Button, { disabled: this.state.running ||
|
|
179
179
|
(this.props.schema.ownClientSecret && !this.state.clientSecret) ||
|
|
180
180
|
(this.props.schema.ownClientId && !this.state.clientId), endIcon: icon || React.createElement(CloudUpload, null), variant: "contained", onClick: () => this.onOpenUrl() }, label),
|
|
181
|
-
this.state.blocked ? (React.createElement("div", { style: { color: 'red', fontSize: 16, marginTop: 20 } }, I18n.t('
|
|
181
|
+
this.state.blocked ? (React.createElement("div", { style: { color: 'red', fontSize: 16, marginTop: 20 } }, I18n.t('jc_Please allow popups in your browser for this page!'))) : null,
|
|
182
182
|
this.state.accessTokens ? (React.createElement("div", { style: { color: 'green', fontSize: 16, marginTop: 20 } }, this.props.alive
|
|
183
|
-
? I18n.t('
|
|
184
|
-
: I18n.t('
|
|
183
|
+
? I18n.t('jc_Successfully authorized. Token valid till %s and will be automatically renewed.', validTill)
|
|
184
|
+
: I18n.t('jc_Successfully authorized. Token valid till %s but it can expire as the instance is not running.', validTill))) : null,
|
|
185
185
|
this.state.pressed ? (React.createElement(React.Fragment, null,
|
|
186
186
|
React.createElement("div", { style: { width: '100%', margin: '1rem 0 1rem 0' } },
|
|
187
187
|
React.createElement("span", { style: { marginRight: 4 } },
|
|
188
|
-
`${I18n.t('
|
|
188
|
+
`${I18n.t('jc_If the button above does not work, you can authorize manually this app by visiting this url')}`,
|
|
189
189
|
":"),
|
|
190
190
|
React.createElement("br", null),
|
|
191
191
|
React.createElement("a", { target: this.props.schema.identifier, href: this.url, rel: "noreferrer" }, this.url)),
|
|
192
|
-
React.createElement(TextField, { value: this.state.accessTokens, label: I18n.t('
|
|
192
|
+
React.createElement(TextField, { value: this.state.accessTokens, label: I18n.t('jc_Enter the code from that page here'), variant: "standard", error: !!this.state.accessTokenError, helperText: this.state.accessTokenError || '', onChange: e => {
|
|
193
193
|
let accessTokens = e.target.value;
|
|
194
194
|
try {
|
|
195
195
|
if (accessTokens?.trim() && !accessTokens.trim().startsWith('{')) {
|