@iobroker/json-config 7.5.2 → 7.6.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 (67) hide show
  1. package/README.md +84 -5
  2. package/build/JsonConfig.js.map +1 -1
  3. package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -1
  4. package/build/JsonConfigComponent/ConfigAlive.js.map +1 -1
  5. package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -1
  6. package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -1
  7. package/build/JsonConfigComponent/ConfigCRON.js.map +1 -1
  8. package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -1
  9. package/build/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -1
  10. package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -1
  11. package/build/JsonConfigComponent/ConfigCheckLicense.js.map +1 -1
  12. package/build/JsonConfigComponent/ConfigCheckbox.js.map +1 -1
  13. package/build/JsonConfigComponent/ConfigChip.js.map +1 -1
  14. package/build/JsonConfigComponent/ConfigColor.js.map +1 -1
  15. package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -1
  16. package/build/JsonConfigComponent/ConfigCustom.d.ts +1 -1
  17. package/build/JsonConfigComponent/ConfigCustom.js +35 -76
  18. package/build/JsonConfigComponent/ConfigCustom.js.map +1 -1
  19. package/build/JsonConfigComponent/ConfigDatePicker.js.map +1 -1
  20. package/build/JsonConfigComponent/ConfigDeviceManager.js.map +1 -1
  21. package/build/JsonConfigComponent/ConfigFile.js.map +1 -1
  22. package/build/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
  23. package/build/JsonConfigComponent/ConfigFunc.js.map +1 -1
  24. package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -1
  25. package/build/JsonConfigComponent/ConfigIP.js.map +1 -1
  26. package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -1
  27. package/build/JsonConfigComponent/ConfigImageUpload.js.map +1 -1
  28. package/build/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -1
  29. package/build/JsonConfigComponent/ConfigInterface.js.map +1 -1
  30. package/build/JsonConfigComponent/ConfigJsonEditor.js +14 -5
  31. package/build/JsonConfigComponent/ConfigJsonEditor.js.map +1 -1
  32. package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -1
  33. package/build/JsonConfigComponent/ConfigLicense.js.map +1 -1
  34. package/build/JsonConfigComponent/ConfigNumber.js.map +1 -1
  35. package/build/JsonConfigComponent/ConfigObjectId.js.map +1 -1
  36. package/build/JsonConfigComponent/ConfigPanel.js.map +1 -1
  37. package/build/JsonConfigComponent/ConfigPassword.js.map +1 -1
  38. package/build/JsonConfigComponent/ConfigPattern.js.map +1 -1
  39. package/build/JsonConfigComponent/ConfigPort.js.map +1 -1
  40. package/build/JsonConfigComponent/ConfigQrCode.js.map +1 -1
  41. package/build/JsonConfigComponent/ConfigRoom.js.map +1 -1
  42. package/build/JsonConfigComponent/ConfigSelect.js.map +1 -1
  43. package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -1
  44. package/build/JsonConfigComponent/ConfigSendto.js.map +1 -1
  45. package/build/JsonConfigComponent/ConfigSetState.js.map +1 -1
  46. package/build/JsonConfigComponent/ConfigSlider.js.map +1 -1
  47. package/build/JsonConfigComponent/ConfigState.js.map +1 -1
  48. package/build/JsonConfigComponent/ConfigStaticDivider.js.map +1 -1
  49. package/build/JsonConfigComponent/ConfigStaticHeader.js.map +1 -1
  50. package/build/JsonConfigComponent/ConfigStaticImage.js.map +1 -1
  51. package/build/JsonConfigComponent/ConfigStaticInfo.js.map +1 -1
  52. package/build/JsonConfigComponent/ConfigStaticText.js.map +1 -1
  53. package/build/JsonConfigComponent/ConfigTable.js.map +1 -1
  54. package/build/JsonConfigComponent/ConfigTabs.js.map +1 -1
  55. package/build/JsonConfigComponent/ConfigText.js.map +1 -1
  56. package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -1
  57. package/build/JsonConfigComponent/ConfigTimePicker.js.map +1 -1
  58. package/build/JsonConfigComponent/ConfigTopic.js.map +1 -1
  59. package/build/JsonConfigComponent/ConfigUUID.js.map +1 -1
  60. package/build/JsonConfigComponent/ConfigUser.js.map +1 -1
  61. package/build/JsonConfigComponent/index.d.ts +2 -2
  62. package/build/JsonConfigComponent/index.js.map +1 -1
  63. package/build/JsonConfigComponent/wrapper/Components/Editor.d.ts +2 -1
  64. package/build/JsonConfigComponent/wrapper/Components/Editor.js +1 -0
  65. package/build/JsonConfigComponent/wrapper/Components/Editor.js.map +1 -1
  66. package/build/types.d.ts +7 -1
  67. package/package.json +8 -6
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigChip.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigChip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAMlD,MAAM,UAAW,SAAQ,aAAkD;IACvE,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAClC,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC3D,MAAM,KAAK,GAAG,KAAK;iBACd,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;iBAClC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBAClB,M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AAC,CAAC,oCAAoC,CAAC,CAAkB;YAC9E,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,UAAU,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { FormHelperText, FormControl } from '@mui/material';\n\nimport type { ConfigItemChip } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport ChipInput from './ChipInput';\nimport { I18n } from '@iobroker/adapter-react-v5';\n\ninterface ConfigChipProps extends ConfigGenericProps {\n schema: ConfigItemChip;\n}\n\nclass ConfigChip extends ConfigGeneric<ConfigChipProps, ConfigGenericState> {\n componentDidMount(): void {\n super.componentDidMount();\n const { data, attr } = this.props;\n const value = ConfigGeneric.getValue(data, attr);\n if (this.props.schema.delimiter && typeof value === 'string') {\n const parts = value\n .split(this.props.schema.delimiter)\n .map(a => a.trim())\n .filter(a => a);\n this.setState({ value: parts });\n } else {\n this.setState({ value: value || [] });\n }\n }\n\n renderItem(error: string, disabled: boolean): JSX.Element | null {\n const { attr, schema } = this.props;\n const { value } = this.state;\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n <ChipInput\n value={value}\n disabled={!!disabled}\n label={this.getText(schema.label)}\n error={!!error}\n onAdd={chip => {\n const newValue = JSON.parse(JSON.stringify(value));\n newValue.push(chip);\n this.setState({ value: newValue }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.props.schema.delimiter) {\n mayBePromise = this.onChange(attr, newValue.join(`${this.props.schema.delimiter} `));\n } else {\n mayBePromise = this.onChange(attr, newValue);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n theme={this.props.oContext.theme}\n onDelete={(_chip, index) => {\n const newValue = JSON.parse(JSON.stringify(value));\n newValue.splice(index, 1);\n this.setState({ value: newValue }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.props.schema.delimiter) {\n mayBePromise = this.onChange(attr, newValue.join(`${this.props.schema.delimiter} `));\n } else {\n mayBePromise = this.onChange(attr, newValue);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n />\n <FormHelperText>{I18n.t('ra_Press ENTER Key to add new item')}</FormHelperText>\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 ConfigChip;\n"]}
1
+ {"version":3,"file":"ConfigChip.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigChip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAMlD,MAAM,UAAW,SAAQ,aAAkD;IACvE,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAClC,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EA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YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC9C,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,GACH;YACF,oBAAC,cAAc,QAAE,IAAI,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAkB;YAC9E,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,UAAU,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { FormHelperText, FormControl } from '@mui/material';\n\nimport type { ConfigItemChip } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport ChipInput from './ChipInput';\nimport { I18n } from '@iobroker/adapter-react-v5';\n\ninterface ConfigChipProps extends ConfigGenericProps {\n schema: ConfigItemChip;\n}\n\nclass ConfigChip extends ConfigGeneric<ConfigChipProps, ConfigGenericState> {\n componentDidMount(): void {\n super.componentDidMount();\n const { data, attr } = this.props;\n const value = ConfigGeneric.getValue(data, attr);\n if (this.props.schema.delimiter && typeof value === 'string') {\n const parts = value\n .split(this.props.schema.delimiter)\n .map(a => a.trim())\n .filter(a => a);\n this.setState({ value: parts });\n } else {\n this.setState({ value: value || [] });\n }\n }\n\n renderItem(error: string, disabled: boolean): JSX.Element | null {\n const { attr, schema } = this.props;\n const { value } = this.state;\n return (\n <FormControl\n fullWidth\n variant=\"standard\"\n >\n <ChipInput\n value={value}\n disabled={!!disabled}\n label={this.getText(schema.label)}\n error={!!error}\n onAdd={chip => {\n const newValue = JSON.parse(JSON.stringify(value));\n newValue.push(chip);\n this.setState({ value: newValue }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.props.schema.delimiter) {\n mayBePromise = this.onChange(attr, newValue.join(`${this.props.schema.delimiter} `));\n } else {\n mayBePromise = this.onChange(attr, newValue);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n theme={this.props.oContext.theme}\n onDelete={(_chip, index) => {\n const newValue = JSON.parse(JSON.stringify(value));\n newValue.splice(index, 1);\n this.setState({ value: newValue }, () => {\n let mayBePromise: void | Promise<void>;\n if (this.props.schema.delimiter) {\n mayBePromise = this.onChange(attr, newValue.join(`${this.props.schema.delimiter} `));\n } else {\n mayBePromise = this.onChange(attr, newValue);\n }\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(e));\n }\n });\n }}\n />\n <FormHelperText>{I18n.t('ra_Press ENTER Key to add new item')}</FormHelperText>\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 ConfigChip;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigColor.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigColor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAWlG,MAAM,WAAY,SAAQ,aAAiD;IAC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CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gCACxD,IAAI,YAAY,YAAY,OAAO,EAAE,CAAC;oCAClC,KAAK,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;gCAC1E,CAAC;4BACL,CAAC;4BAED,oBAAC,SAAS,OAAG,CACJ,CAChB,CAAC,CAAC,CAAC,SAAS;qBACpB;oBACD,UAAU,EAAE;wBACR,MAAM,EAAE,IAAI;qBACf;iBACJ,GACH,CACH,CACN,CAAC;IACN,CAAC;CACJ;AAED,eAAe,WAAW,CAAC","sourcesContent":["import React, { type JSX } from 'react';\nimport { ChromePicker, type ColorResult } from 'react-color';\n\nimport { IconButton, TextField, Dialog } from '@mui/material';\n\nimport { Close as ClearIcon } from '@mui/icons-material';\n\nimport { Utils } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemText } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigColorProps extends ConfigGenericProps {\n schema: ConfigItemText;\n}\n\ninterface ConfigColorState extends ConfigGenericState {\n showColorDialog?: boolean;\n colorDialogValue?: string;\n}\n\nclass ConfigColor extends ConfigGeneric<ConfigColorProps, ConfigColorState> {\n renderColorDialog(): JSX.Element | null {\n return (\n !!this.state.showColorDialog && (\n <Dialog\n onClose={() => this.setState({ showColorDialog: false })}\n open={this.state.showColorDialog}\n >\n <ChromePicker\n color={this.state.colorDialogValue}\n onChange={(color: ColorResult) =>\n this.setState({ colorDialogValue: color.hex }, () =>\n this.onChange(this.props.attr, this.state.colorDialogValue),\n )\n }\n />\n </Dialog>\n )\n );\n }\n\n renderItem(_error: unknown, disabled: boolean /* , defaultValue */): JSX.Element {\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n let textColor = Utils.isUseBright(value, null);\n if (textColor === null) {\n textColor = undefined;\n }\n return (\n <>\n {this.renderColorDialog()}\n <TextField\n variant=\"standard\"\n disabled={!!disabled}\n style={{ minWidth: 100, width: 'calc(100% - 8px)' }}\n label={this.getText(this.props.schema.label)}\n value={value || ''}\n onClick={() =>\n !this.props.schema.readOnly &&\n this.setState({ showColorDialog: true, colorDialogValue: value || '' })\n }\n onChange={e => {\n const color = e.target.value;\n const mayBePromise = this.onChange(this.props.attr, color);\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n slotProps={{\n htmlInput: {\n style: {\n // paddingLeft: noPadding ? 0 : 8,\n backgroundColor: value,\n color: textColor ? '#FFF' : '#000',\n },\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment:\n !this.props.schema.readOnly && value && !this.props.schema.noClearButton ? (\n <IconButton\n size=\"small\"\n onClick={e => {\n e.stopPropagation();\n const mayBePromise = this.onChange(this.props.attr, '');\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n >\n <ClearIcon />\n </IconButton>\n ) : undefined,\n },\n inputLabel: {\n shrink: true,\n },\n }}\n />\n </>\n );\n }\n}\n\nexport default ConfigColor;\n"]}
1
+ {"version":3,"file":"ConfigColor.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigColor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAWlG,MAAM,WAAY,SAAQ,aAAiD;IACvE,iBAAiB;QACb,OAAO,CACH,CAAC,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E,CAAC,CAAC;gCACxD,IAAI,YAAY,YAAY,OAAO,EAAE,CAAC;oCAClC,KAAK,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;gCAC1E,CAAC;4BACL,CAAC;4BAED,oBAAC,SAAS,OAAG,CACJ,CAChB,CAAC,CAAC,CAAC,SAAS;qBACpB;oBACD,UAAU,EAAE;wBACR,MAAM,EAAE,IAAI;qBACf;iBACJ,GACH,CACH,CACN,CAAC;IACN,CAAC;CACJ;AAED,eAAe,WAAW,CAAC","sourcesContent":["import React, { type JSX } from 'react';\nimport { ChromePicker, type ColorResult } from 'react-color';\n\nimport { IconButton, TextField, Dialog } from '@mui/material';\n\nimport { Close as ClearIcon } from '@mui/icons-material';\n\nimport { Utils } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemText } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigColorProps extends ConfigGenericProps {\n schema: ConfigItemText;\n}\n\ninterface ConfigColorState extends ConfigGenericState {\n showColorDialog?: boolean;\n colorDialogValue?: string;\n}\n\nclass ConfigColor extends ConfigGeneric<ConfigColorProps, ConfigColorState> {\n renderColorDialog(): JSX.Element | null {\n return (\n !!this.state.showColorDialog && (\n <Dialog\n onClose={() => this.setState({ showColorDialog: false })}\n open={this.state.showColorDialog}\n >\n <ChromePicker\n color={this.state.colorDialogValue}\n onChange={(color: ColorResult) =>\n this.setState({ colorDialogValue: color.hex }, () =>\n this.onChange(this.props.attr, this.state.colorDialogValue),\n )\n }\n />\n </Dialog>\n )\n );\n }\n\n renderItem(_error: unknown, disabled: boolean /* , defaultValue */): JSX.Element {\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n let textColor = Utils.isUseBright(value, null);\n if (textColor === null) {\n textColor = undefined;\n }\n return (\n <>\n {this.renderColorDialog()}\n <TextField\n variant=\"standard\"\n disabled={!!disabled}\n style={{ minWidth: 100, width: 'calc(100% - 8px)' }}\n label={this.getText(this.props.schema.label)}\n value={value || ''}\n onClick={() =>\n !this.props.schema.readOnly &&\n this.setState({ showColorDialog: true, colorDialogValue: value || '' })\n }\n onChange={e => {\n const color = e.target.value;\n const mayBePromise = this.onChange(this.props.attr, color);\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n slotProps={{\n htmlInput: {\n style: {\n // paddingLeft: noPadding ? 0 : 8,\n backgroundColor: value,\n color: textColor ? '#FFF' : '#000',\n },\n readOnly: this.props.schema.readOnly || false,\n },\n input: {\n endAdornment:\n !this.props.schema.readOnly && value && !this.props.schema.noClearButton ? (\n <IconButton\n size=\"small\"\n onClick={e => {\n e.stopPropagation();\n const mayBePromise = this.onChange(this.props.attr, '');\n if (mayBePromise instanceof Promise) {\n void mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n }}\n >\n <ClearIcon />\n </IconButton>\n ) : undefined,\n },\n inputLabel: {\n shrink: true,\n },\n }}\n />\n </>\n );\n }\n}\n\nexport default ConfigColor;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigCoordinates.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigCoordinates.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE7F,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,KAAK,EAAE;QACH,KAAK,EAAE,mBAAmB;KAC7B;IACD,OAAO,EAAE;QACL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e,iBAAiB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { TextField, Fab, FormControlLabel, Checkbox } from '@mui/material';\n\nimport { GpsFixed as IconGpsFixed, LocationOn as IconLocationOn } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemCoordinates } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n width: {\n width: 'calc(100% - 85px)',\n },\n width50: {\n width: 120,\n marginRight: 5,\n },\n};\n\ninterface ConfigCoordinatesProps extends ConfigGenericProps {\n schema: ConfigItemCoordinates;\n}\n\ninterface ConfigCoordinatesState extends ConfigGenericState {\n useSystem?: boolean;\n longitude?: string | number;\n latitude?: string | number;\n}\n\nclass ConfigCoordinates extends ConfigGeneric<ConfigCoordinatesProps, ConfigCoordinatesState> {\n componentDidMount(): void {\n super.componentDidMount();\n\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.setState({ value });\n\n const newState: Partial<ConfigCoordinatesState> = {};\n if (this.props.schema.useSystemName) {\n newState.useSystem = !!ConfigGeneric.getValue(this.props.data, this.props.schema.useSystemName);\n }\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n newState.longitude = ConfigGeneric.getValue(this.props.data, this.props.schema.longitudeName);\n newState.latitude = ConfigGeneric.getValue(this.props.data, this.props.schema.latitudeName);\n if (!newState.longitude && !newState.latitude && this.props.schema.autoInit) {\n setTimeout(() => this.getCoordinates(), 300);\n }\n } else {\n const value_ = ConfigGeneric.getValue(this.props.data, this.props.attr);\n if (!value_ && this.props.schema.autoInit) {\n setTimeout(() => this.getCoordinates(), 300);\n }\n }\n if (Object.keys(newState).length) {\n setTimeout(() => this.setState(newState as ConfigCoordinatesState), 50);\n }\n }\n\n async getSystemCoordinates(): Promise<void> {\n const obj = await this.props.oContext.socket.getCompactSystemConfig();\n if (obj?.common && (obj.common.longitude || obj.common.latitude)) {\n window.alert(I18n.t('ra_Used system settings'));\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n this.setState(\n {\n longitude: obj.common.longitude,\n latitude: obj.common.latitude,\n },\n async () => {\n await this.onChange(this.props.schema.longitudeName, obj.common.longitude);\n await this.onChange(this.props.schema.latitudeName, obj.common.latitude);\n },\n );\n } else {\n const value = obj.common.latitude + (this.props.schema.divider || ',') + obj.common.longitude;\n this.setState(\n {\n value,\n },\n () => {\n const mayByPromise = this.onChange(this.props.attr, value);\n if (mayByPromise instanceof Promise) {\n mayByPromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n },\n );\n }\n } else {\n window.alert(\n I18n.t(\n 'ra_Cannot determine position: System settings are empty and GPS detection is disabled in browser',\n ),\n );\n }\n }\n\n getCoordinates(): void {\n if (navigator.geolocation) {\n navigator.geolocation.getCurrentPosition(\n async (position: GeolocationPosition): Promise<void> => {\n if (position?.coords) {\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n this.setState(\n {\n longitude: position.coords.longitude,\n latitude: position.coords.latitude,\n },\n async () => {\n await this.onChange(\n this.props.schema.longitudeName,\n position.coords.longitude || '',\n );\n await this.onChange(this.props.schema.latitudeName, position.coords.latitude || '');\n },\n );\n } else {\n const value =\n position.coords.latitude +\n (this.props.schema.divider || ',') +\n position.coords.longitude;\n this.setState({ value }, () => {\n const mayByPromise = this.onChange(this.props.attr, value);\n if (mayByPromise instanceof Promise) {\n mayByPromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n });\n }\n } else {\n await this.getSystemCoordinates();\n }\n },\n async (error: GeolocationPositionError): Promise<void> => {\n console.error(`Cannot determine coordinates from browser: ${error.message}`);\n await this.getSystemCoordinates();\n },\n );\n } else {\n void this.getSystemCoordinates().catch(e => {\n console.error(`Cannot determine coordinates: ${e}`);\n });\n }\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n return (\n <>\n {this.props.schema.useSystemName ? (\n <FormControlLabel\n control={\n <Checkbox\n checked={!!this.state.useSystem}\n onChange={e => {\n const useSystem = e.target.checked;\n if (useSystem) {\n void this.getSystemCoordinates().catch(e =>\n console.error(`Cannot determine coordinates: ${e}`),\n );\n }\n this.setState({ useSystem }, () =>\n this.onChange(this.props.schema.useSystemName, useSystem),\n );\n }}\n />\n }\n label={I18n.t('ra_Use system settings for position')}\n />\n ) : null}\n {this.props.schema.longitudeName && this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width50}\n value={this.state.longitude ?? ''}\n error={!!error}\n disabled={this.state.useSystem || !!disabled}\n onChange={e => {\n const longitude = e.target.value;\n this.setState({ longitude }, () => {\n const mayBePromise = this.onChange(\n this.props.schema.longitudeName,\n (longitude || '').trim(),\n );\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n });\n }}\n label={I18n.t('ra_Longitude')}\n />\n ) : null}\n {this.props.schema.longitudeName && this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width50}\n value={this.state.latitude ?? ''}\n error={!!error}\n disabled={this.state.useSystem || !!disabled}\n onChange={e => {\n const latitude = e.target.value;\n this.setState({ latitude }, () =>\n this.onChange(this.props.schema.latitudeName, (latitude || '').trim()),\n );\n }}\n label={I18n.t('ra_Latitude')}\n />\n ) : null}\n {!this.props.schema.longitudeName || !this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width}\n value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}\n error={!!error}\n disabled={!!disabled}\n slotProps={{\n htmlInput: {\n maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,\n readOnly: this.state.useSystem,\n },\n }}\n onChange={e => {\n const value = e.target.value;\n this.setState({ value }, () => this.onChange(this.props.attr, (value || '').trim()));\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n />\n ) : null}\n {!this.state.useSystem ? (\n <Fab\n size=\"small\"\n onClick={() => this.getCoordinates()}\n title={I18n.t('ra_Take browser position')}\n style={{ marginRight: 4 }}\n >\n <IconLocationOn />\n </Fab>\n ) : null}\n {!this.state.useSystem ? (\n <Fab\n size=\"small\"\n onClick={() => this.getSystemCoordinates()}\n title={I18n.t('ra_Take position from system settings')}\n >\n <IconGpsFixed />\n </Fab>\n ) : null}\n </>\n );\n }\n}\n\nexport default ConfigCoordinates;\n"]}
1
+ {"version":3,"file":"ConfigCoordinates.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigCoordinates.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE7F,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAElG,MAAM,MAAM,GAAwC;IAChD,KAAK,EAAE;QACH,KAAK,EAAE,mBAAmB;KAC7B;IACD,OAAO,EAAE;QACL,KAAK,EAAE,GAAG;QACV,WAAW,EAAE,CAAC;KACjB;CACJ,CAAC;AAYF,MAAM,iBAAkB,SAAQ,aAA6D;IACzF,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAE1B,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEzB,MAAM,QAAQ,GAAoC,EAAE,CAAC;QACrD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,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AAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,GACH,CACL,CAAC,CAAC,CAAC,IAAI;YACP,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CACrB,oBAAC,GAAG,IACA,IAAI,EAAC,OAAO,EACZ,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,EACpC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,0BAA0B,CAAC,EACzC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;gBAEzB,oBAAC,cAAc,OAAG,CAChB,CACT,CAAC,CAAC,CAAC,IAAI;YACP,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CACrB,oBAAC,GAAG,IACA,IAAI,EAAC,OAAO,EACZ,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAC1C,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,uCAAuC,CAAC;gBAEtD,oBAAC,YAAY,OAAG,CACd,CACT,CAAC,CAAC,CAAC,IAAI,CACT,CACN,CAAC;IACN,CAAC;CACJ;AAED,eAAe,iBAAiB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { TextField, Fab, FormControlLabel, Checkbox } from '@mui/material';\n\nimport { GpsFixed as IconGpsFixed, LocationOn as IconLocationOn } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemCoordinates } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\nconst styles: Record<string, React.CSSProperties> = {\n width: {\n width: 'calc(100% - 85px)',\n },\n width50: {\n width: 120,\n marginRight: 5,\n },\n};\n\ninterface ConfigCoordinatesProps extends ConfigGenericProps {\n schema: ConfigItemCoordinates;\n}\n\ninterface ConfigCoordinatesState extends ConfigGenericState {\n useSystem?: boolean;\n longitude?: string | number;\n latitude?: string | number;\n}\n\nclass ConfigCoordinates extends ConfigGeneric<ConfigCoordinatesProps, ConfigCoordinatesState> {\n componentDidMount(): void {\n super.componentDidMount();\n\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.setState({ value });\n\n const newState: Partial<ConfigCoordinatesState> = {};\n if (this.props.schema.useSystemName) {\n newState.useSystem = !!ConfigGeneric.getValue(this.props.data, this.props.schema.useSystemName);\n }\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n newState.longitude = ConfigGeneric.getValue(this.props.data, this.props.schema.longitudeName);\n newState.latitude = ConfigGeneric.getValue(this.props.data, this.props.schema.latitudeName);\n if (!newState.longitude && !newState.latitude && this.props.schema.autoInit) {\n setTimeout(() => this.getCoordinates(), 300);\n }\n } else {\n const value_ = ConfigGeneric.getValue(this.props.data, this.props.attr);\n if (!value_ && this.props.schema.autoInit) {\n setTimeout(() => this.getCoordinates(), 300);\n }\n }\n if (Object.keys(newState).length) {\n setTimeout(() => this.setState(newState as ConfigCoordinatesState), 50);\n }\n }\n\n async getSystemCoordinates(): Promise<void> {\n const obj = await this.props.oContext.socket.getCompactSystemConfig();\n if (obj?.common && (obj.common.longitude || obj.common.latitude)) {\n window.alert(I18n.t('ra_Used system settings'));\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n this.setState(\n {\n longitude: obj.common.longitude,\n latitude: obj.common.latitude,\n },\n async () => {\n await this.onChange(this.props.schema.longitudeName, obj.common.longitude);\n await this.onChange(this.props.schema.latitudeName, obj.common.latitude);\n },\n );\n } else {\n const value = obj.common.latitude + (this.props.schema.divider || ',') + obj.common.longitude;\n this.setState(\n {\n value,\n },\n () => {\n const mayByPromise = this.onChange(this.props.attr, value);\n if (mayByPromise instanceof Promise) {\n mayByPromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n },\n );\n }\n } else {\n window.alert(\n I18n.t(\n 'ra_Cannot determine position: System settings are empty and GPS detection is disabled in browser',\n ),\n );\n }\n }\n\n getCoordinates(): void {\n if (navigator.geolocation) {\n navigator.geolocation.getCurrentPosition(\n async (position: GeolocationPosition): Promise<void> => {\n if (position?.coords) {\n if (this.props.schema.longitudeName && this.props.schema.latitudeName) {\n this.setState(\n {\n longitude: position.coords.longitude,\n latitude: position.coords.latitude,\n },\n async () => {\n await this.onChange(\n this.props.schema.longitudeName,\n position.coords.longitude || '',\n );\n await this.onChange(this.props.schema.latitudeName, position.coords.latitude || '');\n },\n );\n } else {\n const value =\n position.coords.latitude +\n (this.props.schema.divider || ',') +\n position.coords.longitude;\n this.setState({ value }, () => {\n const mayByPromise = this.onChange(this.props.attr, value);\n if (mayByPromise instanceof Promise) {\n mayByPromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n });\n }\n } else {\n await this.getSystemCoordinates();\n }\n },\n async (error: GeolocationPositionError): Promise<void> => {\n console.error(`Cannot determine coordinates from browser: ${error.message}`);\n await this.getSystemCoordinates();\n },\n );\n } else {\n void this.getSystemCoordinates().catch(e => {\n console.error(`Cannot determine coordinates: ${e}`);\n });\n }\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n return (\n <>\n {this.props.schema.useSystemName ? (\n <FormControlLabel\n control={\n <Checkbox\n checked={!!this.state.useSystem}\n onChange={e => {\n const useSystem = e.target.checked;\n if (useSystem) {\n void this.getSystemCoordinates().catch(e =>\n console.error(`Cannot determine coordinates: ${e}`),\n );\n }\n this.setState({ useSystem }, () =>\n this.onChange(this.props.schema.useSystemName, useSystem),\n );\n }}\n />\n }\n label={I18n.t('ra_Use system settings for position')}\n />\n ) : null}\n {this.props.schema.longitudeName && this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width50}\n value={this.state.longitude ?? ''}\n error={!!error}\n disabled={this.state.useSystem || !!disabled}\n onChange={e => {\n const longitude = e.target.value;\n this.setState({ longitude }, () => {\n const mayBePromise = this.onChange(\n this.props.schema.longitudeName,\n (longitude || '').trim(),\n );\n if (mayBePromise instanceof Promise) {\n mayBePromise.catch(e => console.error(`Cannot set value: ${e}`));\n }\n });\n }}\n label={I18n.t('ra_Longitude')}\n />\n ) : null}\n {this.props.schema.longitudeName && this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width50}\n value={this.state.latitude ?? ''}\n error={!!error}\n disabled={this.state.useSystem || !!disabled}\n onChange={e => {\n const latitude = e.target.value;\n this.setState({ latitude }, () =>\n this.onChange(this.props.schema.latitudeName, (latitude || '').trim()),\n );\n }}\n label={I18n.t('ra_Latitude')}\n />\n ) : null}\n {!this.props.schema.longitudeName || !this.props.schema.latitudeName ? (\n <TextField\n variant=\"standard\"\n style={styles.width}\n value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}\n error={!!error}\n disabled={!!disabled}\n slotProps={{\n htmlInput: {\n maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,\n readOnly: this.state.useSystem,\n },\n }}\n onChange={e => {\n const value = e.target.value;\n this.setState({ value }, () => this.onChange(this.props.attr, (value || '').trim()));\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n />\n ) : null}\n {!this.state.useSystem ? (\n <Fab\n size=\"small\"\n onClick={() => this.getCoordinates()}\n title={I18n.t('ra_Take browser position')}\n style={{ marginRight: 4 }}\n >\n <IconLocationOn />\n </Fab>\n ) : null}\n {!this.state.useSystem ? (\n <Fab\n size=\"small\"\n onClick={() => this.getSystemCoordinates()}\n title={I18n.t('ra_Take position from system settings')}\n >\n <IconGpsFixed />\n </Fab>\n ) : null}\n </>\n );\n }\n}\n\nexport default ConfigCoordinates;\n"]}
@@ -1,6 +1,6 @@
1
1
  import React, { type JSX } from 'react';
2
+ import ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';
2
3
  import type { ConfigItemCustom } from '../types';
3
- import ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from '../JsonConfigComponent/ConfigGeneric';
4
4
  interface ConfigCustomProps extends ConfigGenericProps {
5
5
  schema: ConfigItemCustom;
6
6
  }
@@ -1,78 +1,29 @@
1
1
  import React from 'react';
2
2
  import { LinearProgress } from '@mui/material';
3
+ import { registerRemotes, loadRemote, init } from '@module-federation/runtime';
4
+ import * as IconsMaterial from '@mui/icons-material';
5
+ import * as AdapterReact from '@iobroker/adapter-react-v5';
3
6
  import { I18n } from '@iobroker/adapter-react-v5';
4
- import ConfigGeneric from '../JsonConfigComponent/ConfigGeneric';
5
- const getOrLoadRemote = (remote, shareScope, remoteFallbackUrl) => new Promise((resolve, reject) => {
6
- // check if remote exists on the global `window`object
7
- if (!window[remote]) {
8
- // search dom to see if remote tag exists, but might still be loading (async)
9
- const existingRemote = document.querySelector(`script[data-webpack="${remote}"]`);
10
- // when remote is loaded.
11
- const onload = async () => {
12
- // check if it was initialized
13
- if (window[remote]) {
14
- if (!window[remote].__initialized) {
15
- // if share scope doesn't exist (like in webpack 4) then expect shareScope to be a manual object
16
- // @ts-expect-error it is a trick and must be so
17
- if (typeof __webpack_share_scopes__ === 'undefined') {
18
- // use a default share scope object passed in manually
19
- await window[remote].init(shareScope);
20
- }
21
- else {
22
- // otherwise, init share scope as usual
23
- // @ts-expect-error it is a trick and must be so
24
- await window[remote].init(__webpack_share_scopes__[shareScope]);
25
- }
26
- // mark remote as initialized
27
- window[remote].__initialized = true;
28
- }
29
- }
30
- else {
31
- console.error(`Cannot load ${remote}`);
32
- reject(new Error(`Cannot load ${remote}`));
33
- return;
34
- }
35
- // resolve promise so marking remote as loaded
36
- resolve(window[remote]);
37
- };
38
- if (existingRemote) {
39
- // if existing remote but not loaded, hook into its onload and wait for it to be ready
40
- existingRemote.onload = onload;
41
- existingRemote.onerror = reject;
42
- // check if remote fallback exists as param passed to function
43
- // TODO: should scan public config for a matching key if no override exists
44
- }
45
- else if (remoteFallbackUrl) {
46
- // inject remote if a fallback exists and call the same onload function
47
- const d = document;
48
- const script = d.createElement('script');
49
- script.type = 'text/javascript';
50
- // mark as data-webpack so runtime can track it internally
51
- script.setAttribute('data-webpack', `${remote}`);
52
- script.async = true;
53
- script.onerror = reject;
54
- script.onload = onload;
55
- script.src = remoteFallbackUrl;
56
- d.getElementsByTagName('head')[0].appendChild(script);
57
- }
58
- else {
59
- // no remote and no fallback exist, reject
60
- reject(new Error(`Cannot Find Remote ${remote} to inject`));
61
- }
62
- }
63
- else {
64
- // remote already instantiated, resolve
65
- resolve(window[remote]);
66
- }
7
+ import ConfigGeneric from './ConfigGeneric';
8
+ import * as JsonConfig from '../';
9
+ init({
10
+ name: 'iobroker_admin',
11
+ shared: {
12
+ '@iobroker/adapter-react-v5': {
13
+ lib: () => AdapterReact,
14
+ version: '*',
15
+ },
16
+ '@mui/icons-material': {
17
+ lib: () => IconsMaterial,
18
+ version: '*',
19
+ },
20
+ '@iobroker/json-config': {
21
+ lib: () => JsonConfig,
22
+ version: '*',
23
+ },
24
+ },
25
+ remotes: [],
67
26
  });
68
- function loadComponent(remote, sharedScope, module, url) {
69
- return async () => {
70
- const container = await getOrLoadRemote(remote, sharedScope, url);
71
- // eslint-disable-next-line @typescript-eslint/await-thenable
72
- const factory = await container.get(module);
73
- return factory();
74
- };
75
- }
76
27
  export default class ConfigCustom extends ConfigGeneric {
77
28
  static runningLoads = {};
78
29
  constructor(props) {
@@ -153,10 +104,15 @@ export default class ConfigCustom extends ConfigGeneric {
153
104
  }
154
105
  }
155
106
  try {
156
- console.log(uniqueName, fileToLoad, componentName);
157
- setPromise = loadComponent(uniqueName, 'default', fileToLoad.startsWith('http://') || fileToLoad.startsWith('https://') || fileToLoad.startsWith('.')
158
- ? fileToLoad
159
- : `./${fileToLoad}`, url)();
107
+ console.log(url, uniqueName, fileToLoad, componentName);
108
+ registerRemotes([
109
+ {
110
+ name: uniqueName,
111
+ entry: url,
112
+ type: this.props.schema.bundlerType || undefined,
113
+ },
114
+ ]);
115
+ setPromise = loadRemote(`${uniqueName}/${fileToLoad}`);
160
116
  if (i18nPromise instanceof Promise) {
161
117
  setPromise = Promise.all([setPromise, i18nPromise]).then(result => result[0]);
162
118
  }
@@ -164,6 +120,7 @@ export default class ConfigCustom extends ConfigGeneric {
164
120
  ConfigCustom.runningLoads[`${url}!${fileToLoad}`] = setPromise;
165
121
  }
166
122
  catch (error) {
123
+ console.error(error);
167
124
  this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });
168
125
  }
169
126
  }
@@ -177,10 +134,12 @@ export default class ConfigCustom extends ConfigGeneric {
177
134
  });
178
135
  }
179
136
  else {
180
- this.setState({ Component: component[componentName] });
137
+ const _Component = component[componentName];
138
+ setTimeout(() => this.setState({ Component: _Component }), 2000);
181
139
  }
182
140
  }
183
141
  catch (error) {
142
+ console.error(error);
184
143
  this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });
185
144
  }
186
145
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigCustom.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigCustom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAS,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,aAAmE,MAAM,uCAAuC,CAAC;AAExH,MAAM,eAAe,GAAG,CACpB,MAAc,EACd,UAAkB,EAClB,iBAA0B,EACoF,EAAE,CAChH,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC5B,sDAAsD;IACtD,IAAI,CAAE,MAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,6EAA6E;QAC7E,MAAM,cAAc,GAAsB,QAAQ,CAAC,aAAa,CAAC,wBAAwB,MAAM,IAAI,CAAC,CAAC;QACrG,yBAAyB;QACzB,MAAM,MAAM,GA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MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,IAAK,EAAuB,CAAC;QAE7D,IAAI,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CACzB,oBAAC,eAAe,OACR,IAAI,CAAC,KAAK;YACd,gGAAgG;YAChG,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EACxC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EACtC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAC5C,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,EAC9C,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,GAC9C,CACL,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CACnB,iCAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAO,CAChC,CAAC,CAAC,CAAC,CACA,oBAAC,cAAc,OAAG,CACrB,CAAC;QAEF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CACH;gBACI,6BAAK,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAI;gBAC/C,IAAI,CACN,CACN,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\nimport { Grid2, LinearProgress } from '@mui/material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\nimport type { ConfigItemCustom } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from '#JC/JsonConfigComponent/ConfigGeneric';\n\nconst getOrLoadRemote = (\n remote: string,\n shareScope: string,\n remoteFallbackUrl?: string,\n): Promise<{ get: (module: string) => () => Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }> }> =>\n new Promise((resolve, reject) => {\n // check if remote exists on the global `window`object\n if (!(window as any)[remote]) {\n // search dom to see if remote tag exists, but might still be loading (async)\n const existingRemote: HTMLScriptElement = document.querySelector(`script[data-webpack=\"${remote}\"]`);\n // when remote is loaded.\n const onload = async (): Promise<void> => {\n // check if it was initialized\n if ((window as any)[remote]) {\n if (!(window as any)[remote].__initialized) {\n // if share scope doesn't exist (like in webpack 4) then expect shareScope to be a manual object\n // @ts-expect-error it is a trick and must be so\n if (typeof __webpack_share_scopes__ === 'undefined') {\n // use a default share scope object passed in manually\n await (window as any)[remote].init(shareScope);\n } else {\n // otherwise, init share scope as usual\n // @ts-expect-error it is a trick and must be so\n await (window as any)[remote].init((__webpack_share_scopes__ as any)[shareScope]);\n }\n // mark remote as initialized\n (window as any)[remote].__initialized = true;\n }\n } else {\n console.error(`Cannot load ${remote}`);\n reject(new Error(`Cannot load ${remote}`));\n return;\n }\n // resolve promise so marking remote as loaded\n resolve((window as any)[remote]);\n };\n\n if (existingRemote) {\n // if existing remote but not loaded, hook into its onload and wait for it to be ready\n existingRemote.onload = onload;\n existingRemote.onerror = reject;\n // check if remote fallback exists as param passed to function\n // TODO: should scan public config for a matching key if no override exists\n } else if (remoteFallbackUrl) {\n // inject remote if a fallback exists and call the same onload function\n const d = document;\n const script = d.createElement('script');\n script.type = 'text/javascript';\n // mark as data-webpack so runtime can track it internally\n script.setAttribute('data-webpack', `${remote}`);\n script.async = true;\n script.onerror = reject;\n script.onload = onload;\n script.src = remoteFallbackUrl;\n d.getElementsByTagName('head')[0].appendChild(script);\n } else {\n // no remote and no fallback exist, reject\n reject(new Error(`Cannot Find Remote ${remote} to inject`));\n }\n } else {\n // remote already instantiated, resolve\n resolve((window as any)[remote]);\n }\n });\n\nfunction loadComponent(\n remote: string,\n sharedScope: string,\n module: string,\n url: string,\n): () => Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }> {\n return async (): Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }> => {\n const container = await getOrLoadRemote(remote, sharedScope, url);\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const factory = await container.get(module);\n return factory();\n };\n}\n\ninterface ConfigCustomProps extends ConfigGenericProps {\n schema: ConfigItemCustom;\n}\n\ninterface ConfigCustomState extends ConfigGenericState {\n Component: React.FC<ConfigGenericProps> | null;\n error: string;\n}\n\nexport default class ConfigCustom extends ConfigGeneric<ConfigCustomProps, ConfigCustomState> {\n static runningLoads: Record<string, Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }>> = {};\n\n constructor(props: ConfigCustomProps) {\n super(props);\n // schema.url - location of Widget\n // schema.name - Component name\n // schema.i18n - i18n\n\n Object.assign(this.state, {\n Component: null,\n error: '',\n });\n }\n\n // load component dynamically\n async componentDidMount(): Promise<void> {\n if (!this.props.schema.url) {\n console.error('URL is empty. Cannot load custom component!');\n this.setState({ error: 'URL is empty. Cannot load custom component!' });\n return;\n }\n\n let url;\n /*\n if (this.props.schema.url.startsWith('http:') || this.props.schema.url.startsWith('https:')) {\n url = this.props.schema.url;\n } else\n */\n if (this.props.schema.url.startsWith('./')) {\n url = `${window.location.protocol}//${window.location.host}${this.props.schema.url.replace(/^\\./, '')}`;\n } else {\n url = `${window.location.protocol}//${window.location.host}/adapter/${this.props.oContext.adapterName}/${this.props.schema.url}`;\n }\n const [uniqueName, fileToLoad, ...componentNameParts] = this.props.schema.name.split('/');\n const componentName = componentNameParts.join('/');\n if (!url) {\n console.error(\n 'Cannot find URL for custom component! Please define \"url\" as \"custom/customComponents.js\" in the schema',\n );\n return;\n }\n if (!uniqueName || !fileToLoad || !componentName) {\n console.error(\n 'Invalid format of \"name\"! Please define \"name\" as \"ConfigCustomBackItUpSet/Components/AdapterExist\" in the schema',\n );\n return;\n }\n let setPromise: Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }> | undefined =\n ConfigCustom.runningLoads[`${url}!${fileToLoad}`];\n\n if (!(setPromise instanceof Promise)) {\n let i18nPromise: Promise<void> | undefined;\n if (this.props.schema.i18n === true) {\n // load i18n from files\n const pos = url.lastIndexOf('/');\n let i18nURL: string;\n if (pos !== -1) {\n i18nURL = url.substring(0, pos);\n } else {\n i18nURL = url;\n }\n const lang = I18n.getLanguage();\n const file = `${i18nURL}/i18n/${lang}.json`;\n\n i18nPromise = fetch(file)\n .then(data => data.json())\n .then(json => I18n.extendTranslations(json, lang))\n .catch(error => {\n if (lang !== 'en') {\n // try to load English\n fetch(`${i18nURL}/i18n/en.json`)\n .then(data => data.json())\n .then(json => I18n.extendTranslations(json, lang))\n .catch(err => console.log(`Cannot load i18n \"${file}\": ${err}`));\n return;\n }\n console.log(`Cannot load i18n \"${file}\": ${error}`);\n });\n } else if (this.props.schema.i18n && typeof this.props.schema.i18n === 'object') {\n try {\n I18n.extendTranslations(this.props.schema.i18n);\n } catch (error) {\n console.error(`Cannot import i18n: ${error}`);\n }\n }\n try {\n console.log(uniqueName, fileToLoad, componentName);\n setPromise = loadComponent(\n uniqueName,\n 'default',\n fileToLoad.startsWith('http://') || fileToLoad.startsWith('https://') || fileToLoad.startsWith('.')\n ? fileToLoad\n : `./${fileToLoad}`,\n url,\n )();\n if (i18nPromise instanceof Promise) {\n setPromise = Promise.all([setPromise, i18nPromise]).then(result => result[0]);\n }\n // remember promise\n ConfigCustom.runningLoads[`${url}!${fileToLoad}`] = setPromise;\n } catch (error) {\n this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });\n }\n }\n\n try {\n const component: Record<string, React.FC<ConfigGenericProps>> = (await setPromise).default;\n\n if (!component?.[componentName]) {\n const keys = Object.keys(component || {});\n console.error('URL is empty. Cannot load custom component!');\n this.setState({\n error: `Component ${this.props.schema.name} not found in ${this.props.schema.url}. Found: ${keys.join(', ')}`,\n });\n } else {\n this.setState({ Component: component[componentName] });\n }\n } catch (error) {\n this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });\n }\n }\n\n render(): JSX.Element {\n const CustomComponent: React.FC<ConfigGenericProps> = this.state.Component;\n const schema = this.props.schema || ({} as ConfigItemCustom);\n\n let item = CustomComponent ? (\n <CustomComponent\n {...this.props}\n // @ts-expect-error BF (2024-12-18) Remove after the 7.4 will be mainstream. All following lines\n socket={this.props.oContext.socket}\n theme={this.props.oContext.theme}\n themeType={this.props.oContext.themeType}\n instance={this.props.oContext.instance}\n adapterName={this.props.oContext.adapterName}\n systemConfig={this.props.oContext.systemConfig}\n forceUpdate={this.props.oContext.forceUpdate}\n />\n ) : this.state.error ? (\n <div>{this.state.error}</div>\n ) : (\n <LinearProgress />\n );\n\n if (schema.newLine) {\n return (\n <>\n <div style={{ flexBasis: '100%', height: 0 }} />\n {item}\n </>\n );\n }\n\n return item;\n }\n}\n"]}
1
+ {"version":3,"file":"ConfigCustom.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigCustom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAE/E,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,KAAK,UAAU,MAAM,KAAK,CAAC;AAYlC,IAAI,CAAC;IACD,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE;QACJ,4BAA4B,EAAE;YAC1B,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY;YACvB,OAAO,EAAE,GAAG;SACf;QACD,qBAAqB,EAAE;YACnB,GAAG,EAAE,GAAG,EAAE,CAAC,aAAa;YACxB,OAAO,EAAE,GAAG;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,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CACnB,iCAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAO,CAChC,CAAC,CAAC,CAAC,CACA,oBAAC,cAAc,OAAG,CACrB,CAAC;QAEF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CACH;gBACI,6BAAK,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAI;gBAC/C,IAAI,CACN,CACN,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\nimport { LinearProgress } from '@mui/material';\nimport { registerRemotes, loadRemote, init } from '@module-federation/runtime';\n\nimport * as IconsMaterial from '@mui/icons-material';\n\nimport * as AdapterReact from '@iobroker/adapter-react-v5';\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport * as JsonConfig from '../';\nimport type { ConfigItemCustom } from '../types';\n\ninterface ConfigCustomProps extends ConfigGenericProps {\n schema: ConfigItemCustom;\n}\n\ninterface ConfigCustomState extends ConfigGenericState {\n Component: React.FC<ConfigGenericProps> | null;\n error: string;\n}\n\ninit({\n name: 'iobroker_admin',\n shared: {\n '@iobroker/adapter-react-v5': {\n lib: () => AdapterReact,\n version: '*',\n },\n '@mui/icons-material': {\n lib: () => IconsMaterial,\n version: '*',\n },\n '@iobroker/json-config': {\n lib: () => JsonConfig,\n version: '*',\n },\n },\n remotes: [],\n})\n\nexport default class ConfigCustom extends ConfigGeneric<ConfigCustomProps, ConfigCustomState> {\n static runningLoads: Record<string, Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }>> = {};\n\n constructor(props: ConfigCustomProps) {\n super(props);\n // schema.url - location of Widget\n // schema.name - Component name\n // schema.i18n - i18n\n\n Object.assign(this.state, {\n Component: null,\n error: '',\n });\n }\n\n // load component dynamically\n async componentDidMount(): Promise<void> {\n if (!this.props.schema.url) {\n console.error('URL is empty. Cannot load custom component!');\n this.setState({ error: 'URL is empty. Cannot load custom component!' });\n return;\n }\n\n let url;\n /*\n if (this.props.schema.url.startsWith('http:') || this.props.schema.url.startsWith('https:')) {\n url = this.props.schema.url;\n } else\n */\n if (this.props.schema.url.startsWith('./')) {\n url = `${window.location.protocol}//${window.location.host}${this.props.schema.url.replace(/^\\./, '')}`;\n } else {\n url = `${window.location.protocol}//${window.location.host}/adapter/${this.props.oContext.adapterName}/${this.props.schema.url}`;\n }\n const [uniqueName, fileToLoad, ...componentNameParts] = this.props.schema.name.split('/');\n const componentName = componentNameParts.join('/');\n if (!url) {\n console.error(\n 'Cannot find URL for custom component! Please define \"url\" as \"custom/customComponents.js\" in the schema',\n );\n return;\n }\n if (!uniqueName || !fileToLoad || !componentName) {\n console.error(\n 'Invalid format of \"name\"! Please define \"name\" as \"ConfigCustomBackItUpSet/Components/AdapterExist\" in the schema',\n );\n return;\n }\n let setPromise: Promise<{ default: Record<string, React.FC<ConfigGenericProps>> }> | undefined =\n ConfigCustom.runningLoads[`${url}!${fileToLoad}`];\n\n if (!(setPromise instanceof Promise)) {\n let i18nPromise: Promise<void> | undefined;\n if (this.props.schema.i18n === true) {\n // load i18n from files\n const pos = url.lastIndexOf('/');\n let i18nURL: string;\n if (pos !== -1) {\n i18nURL = url.substring(0, pos);\n } else {\n i18nURL = url;\n }\n const lang = I18n.getLanguage();\n const file = `${i18nURL}/i18n/${lang}.json`;\n\n i18nPromise = fetch(file)\n .then(data => data.json())\n .then(json => I18n.extendTranslations(json, lang))\n .catch(error => {\n if (lang !== 'en') {\n // try to load English\n fetch(`${i18nURL}/i18n/en.json`)\n .then(data => data.json())\n .then(json => I18n.extendTranslations(json, lang))\n .catch(err => console.log(`Cannot load i18n \"${file}\": ${err}`));\n return;\n }\n console.log(`Cannot load i18n \"${file}\": ${error}`);\n });\n } else if (this.props.schema.i18n && typeof this.props.schema.i18n === 'object') {\n try {\n I18n.extendTranslations(this.props.schema.i18n);\n } catch (error) {\n console.error(`Cannot import i18n: ${error}`);\n }\n }\n try {\n console.log(url, uniqueName, fileToLoad, componentName);\n\n registerRemotes(\n [\n {\n name: uniqueName,\n entry: url,\n type: this.props.schema.bundlerType || undefined,\n },\n ],\n // force: true // may be needed to side-load remotes after the fact.\n );\n setPromise = loadRemote(`${uniqueName}/${fileToLoad}`);\n if (i18nPromise instanceof Promise) {\n setPromise = Promise.all([setPromise, i18nPromise]).then(result => result[0]);\n }\n // remember promise\n ConfigCustom.runningLoads[`${url}!${fileToLoad}`] = setPromise;\n } catch (error) {\n console.error(error);\n this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });\n }\n }\n\n try {\n const component: Record<string, React.FC<ConfigGenericProps>> = (await setPromise).default;\n\n if (!component?.[componentName]) {\n const keys = Object.keys(component || {});\n console.error('URL is empty. Cannot load custom component!');\n this.setState({\n error: `Component ${this.props.schema.name} not found in ${this.props.schema.url}. Found: ${keys.join(', ')}`,\n });\n } else {\n const _Component = component[componentName];\n setTimeout(() => this.setState({ Component: _Component }), 2000);\n }\n } catch (error) {\n console.error(error);\n this.setState({ error: `Cannot import from ${this.props.schema.url}: ${error}` });\n }\n }\n\n render(): JSX.Element {\n const CustomComponent: React.FC<ConfigGenericProps> = this.state.Component;\n const schema = this.props.schema || ({} as ConfigItemCustom);\n\n let item = CustomComponent ? (\n <CustomComponent\n {...this.props}\n // @ts-expect-error BF (2024-12-18) Remove after the 7.4 will be mainstream. All following lines\n socket={this.props.oContext.socket}\n theme={this.props.oContext.theme}\n themeType={this.props.oContext.themeType}\n instance={this.props.oContext.instance}\n adapterName={this.props.oContext.adapterName}\n systemConfig={this.props.oContext.systemConfig}\n forceUpdate={this.props.oContext.forceUpdate}\n />\n ) : this.state.error ? (\n <div>{this.state.error}</div>\n ) : (\n <LinearProgress />\n );\n\n if (schema.newLine) {\n return (\n <>\n <div style={{ flexBasis: '100%', height: 0 }} />\n {item}\n </>\n );\n }\n\n return item;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigDatePicker.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigDatePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,aAA0C,MAAM,iBAAiB,CAAC;AAMzE,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,aAAoC;IAC9E,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,MAAe,EAAE,QAAiB,CAAC,oBAAoB;QAC9D,OAAO,CACH,oBAAC,UAAU,IACP,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;gBACV,KAAK,EAAE,MAAM;gBACb,YAAY,EAAE,aAAa,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE;gBACvD,YAAY,EAAE;oBACV,OAAO,EAAE,MAAM;iBAClB;gBACD,SAAS,EAAE;oBACP,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU;iBAC3C;gBACD,2BAA2B,EAAE;oBACzB,UAAU,EAAE,CAAC;oBACb,SAAS,EAAE,CAAC,EAAE,0BAA0B;iBAC3C;gBACD,SAAS,EAAE;oBACP,SAAS,EAAE,kCAAkC;iBAChD;aACJ,CAAC,EACF,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EACrF,QAAQ,EAAE,CAAC,CAAC,QAAQ,EACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAc,EAChC,QAAQ,EAAE,KAAK,CAAC,EAAE;gBACd,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YACrF,CAAC,EACD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAC9C,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { DatePicker } from '@mui/x-date-pickers';\n\nimport type { ConfigItemDatePicker } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps } from './ConfigGeneric';\n\ninterface ConfigDatePickerProps extends ConfigGenericProps {\n schema: ConfigItemDatePicker;\n}\n\nexport default class ConfigDatePicker extends ConfigGeneric<ConfigDatePickerProps> {\n componentDidMount(): void {\n super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.setState({ value });\n }\n\n renderItem(_error: unknown, disabled: boolean /* , defaultValue */): JSX.Element {\n return (\n <DatePicker\n sx={theme => ({\n width: '100%',\n borderBottom: `1px solid ${theme.palette.text.primary}`,\n '& fieldset': {\n display: 'none',\n },\n '& input': {\n padding: `${theme.spacing(1.5)} 0 4px 0`,\n },\n '& .MuiInputAdornment-root': {\n marginLeft: 0,\n marginTop: 1, // it is already in spaces\n },\n '& label': {\n transform: 'translate(0px, -9px) scale(0.75)',\n },\n })}\n format={this.props.oContext.systemConfig.dateFormat.toLowerCase().replace('mm', 'MM')}\n disabled={!!disabled}\n value={this.state.value as never}\n onChange={value => {\n this.setState({ value }, () => this.onChange(this.props.attr, this.state.value));\n }}\n label={this.getText(this.props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,EAAE,CAAC,CAAC,QAAQ,EACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAc,EAChC,QAAQ,EAAE,KAAK,CAAC,EAAE;gBACd,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YACrF,CAAC,EACD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAC9C,CACL,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { DatePicker } from '@mui/x-date-pickers';\n\nimport type { ConfigItemDatePicker } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps } from './ConfigGeneric';\n\ninterface ConfigDatePickerProps extends ConfigGenericProps {\n schema: ConfigItemDatePicker;\n}\n\nexport default class ConfigDatePicker extends ConfigGeneric<ConfigDatePickerProps> {\n componentDidMount(): void {\n super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.setState({ value });\n }\n\n renderItem(_error: unknown, disabled: boolean /* , defaultValue */): JSX.Element {\n return (\n <DatePicker\n sx={theme => ({\n width: '100%',\n borderBottom: `1px solid ${theme.palette.text.primary}`,\n '& fieldset': {\n display: 'none',\n },\n '& input': {\n padding: `${theme.spacing(1.5)} 0 4px 0`,\n },\n '& .MuiInputAdornment-root': {\n marginLeft: 0,\n marginTop: 1, // it is already in spaces\n },\n '& label': {\n transform: 'translate(0px, -9px) scale(0.75)',\n },\n })}\n format={this.props.oContext.systemConfig.dateFormat.toLowerCase().replace('mm', 'MM')}\n disabled={!!disabled}\n value={this.state.value as never}\n onChange={value => {\n this.setState({ value }, () => this.onChange(this.props.attr, this.state.value));\n }}\n label={this.getText(this.props.schema.label)}\n />\n );\n }\n}\n"]}
@@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U,GAC5C,CACL,CAAC;QACN,CAAC;QAED,OAAO,2DAAkC,CAAC;IAC9C,CAAC;CACJ;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport type { ConfigItemDeviceManager } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigDeviceManagerProps extends ConfigGenericProps {\n schema: ConfigItemDeviceManager;\n}\n\nclass ConfigDeviceManager extends ConfigGeneric<ConfigDeviceManagerProps, ConfigGenericState> {\n renderItem(): JSX.Element | null {\n const schema = this.props.schema;\n\n if (!schema) {\n return null;\n }\n\n if (this.props.oContext.DeviceManager) {\n const DeviceManager = this.props.oContext.DeviceManager;\n return (\n <DeviceManager\n uploadImagesToInstance={`${this.props.oContext.adapterName}.${this.props.oContext.instance}`}\n title={this.getText(this.props.schema.label)}\n socket={this.props.oContext.socket}\n selectedInstance={`${this.props.oContext.adapterName}.${this.props.oContext.instance}`}\n themeName={this.props.themeName}\n theme={this.props.oContext.theme}\n themeType={this.props.oContext.themeType}\n isFloatComma={this.props.oContext.isFloatComma}\n dateFormat={this.props.oContext.dateFormat}\n />\n );\n }\n\n return <div>DeviceManager not found</div>;\n }\n}\n\nexport default ConfigDeviceManager;\n"]}
1
+ {"version":3,"file":"ConfigDeviceManager.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigDeviceManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAGxC,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAMlG,MAAM,mBAAoB,SAAQ,aAA2D;IACzF,UAAU;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAEjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;YACpC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;YACxD,OAAO,CACH,oBAAC,aAAa,IACV,sBAAsB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAC5F,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAC5C,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAClC,gBAAgB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EACtF,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EACxC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,EAC9C,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,GAC5C,CACL,CAAC;QACN,CAAC;QAED,OAAO,2DAAkC,CAAC;IAC9C,CAAC;CACJ;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport type { ConfigItemDeviceManager } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\n\ninterface ConfigDeviceManagerProps extends ConfigGenericProps {\n schema: ConfigItemDeviceManager;\n}\n\nclass ConfigDeviceManager extends ConfigGeneric<ConfigDeviceManagerProps, ConfigGenericState> {\n renderItem(): JSX.Element | null {\n const schema = this.props.schema;\n\n if (!schema) {\n return null;\n }\n\n if (this.props.oContext.DeviceManager) {\n const DeviceManager = this.props.oContext.DeviceManager;\n return (\n <DeviceManager\n uploadImagesToInstance={`${this.props.oContext.adapterName}.${this.props.oContext.instance}`}\n title={this.getText(this.props.schema.label)}\n socket={this.props.oContext.socket}\n selectedInstance={`${this.props.oContext.adapterName}.${this.props.oContext.instance}`}\n themeName={this.props.themeName}\n theme={this.props.oContext.theme}\n themeType={this.props.oContext.themeType}\n isFloatComma={this.props.oContext.isFloatComma}\n dateFormat={this.props.oContext.dateFormat}\n />\n );\n }\n\n return <div>DeviceManager not found</div>;\n }\n}\n\nexport default ConfigDeviceManager;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigFile.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigFile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EACH,OAAO,IAAI,QAAQ,EACnB,IAAI,IAAI,QAAQ,EAChB,SAAS,IAAI,QAAQ,EACrB,QAAQ,IAAI,SAAS,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,MAAM,MAAM,GAAwC;IAChD,SAAS,EAAE;QACP,KAAK,EAAE,MAAM;KAChB;IACD,kBAAkB,EAAE;QAChB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,CAAC;KACjB;IACD,aAAa,EAAE;QACX,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,CAAC;KACjB;IACD,aAAa,EAAE;QACX,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,cAAc;QACvB,WAAW,EAAE,CAAC;KACjB;CACJ,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,M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,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAC1B,IAAI,CAAC,QAAQ,CACT,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAClE,CACJ,CAAC;gBACN,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,EAAE,IAAI,CAAC,UAAU,CACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,GACH;YACF,oBAAC,MAAM,IACH,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAC,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,UAGlD;YACR,IAAI,CAAC,iBAAiB,EAAE,CACvB,CACT,CAAC;IACN,CAAC;CACJ;AAED,eAAe,UAAU,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Button, TextField, IconButton } from '@mui/material';\n\nimport {\n Article as IconText,\n Code as IconCode,\n PlayArrow as IconPlay,\n Videocam as IconVideo,\n} from '@mui/icons-material';\n\nimport { DialogSelectFile } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemFile } from '#JC/types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport ConfigFileSelector from './ConfigFileSelector';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n fullWidthOneButton: {\n width: 'calc(100% - 69px)',\n marginRight: 4,\n },\n fullWidthIcon: {\n width: 'calc(100% - 119px)',\n marginRight: 4,\n },\n selectedImage: {\n height: 40,\n width: 40,\n display: 'inline-block',\n marginRight: 8,\n },\n};\n\nconst IMAGE_EXT = ['jpg', 'jpeg', 'svg', 'png', 'webp', 'gif', 'apng', 'avif', 'webp'];\nconst AUDIO_EXT = ['mp3', 'ogg', 'wav', 'aac'];\nconst VIDEO_EXT = ['avi', 'mp4', 'mov'];\nconst DOC_EXT = ['txt', 'log', 'html', 'htm'];\nconst JS_EXT = ['json', 'js', 'ts'];\n\ninterface ConfigFileProps extends ConfigGenericProps {\n schema: ConfigItemFile;\n}\n\ninterface ConfigFileState extends ConfigGenericState {\n showFileBrowser?: boolean;\n}\n\nclass ConfigFile extends ConfigGeneric<ConfigFileProps, ConfigFileState> {\n private imagePrefix = '../..';\n\n componentDidMount(): void {\n super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.imagePrefix = this.props.oContext.imagePrefix === undefined ? './files' : this.props.oContext.imagePrefix;\n this.setState({ value: value ?? '' });\n }\n\n static getDerivedStateFromProps(props: ConfigFileProps, state: ConfigFileState): Partial<ConfigFileState> | null {\n const value = ConfigGeneric.getValue(props.data, props.attr);\n if (\n value === null ||\n value === undefined ||\n value.toString().trim() !== (state.value || '').toString().trim()\n ) {\n return { value: value ?? '' };\n }\n return null;\n }\n\n loadFile(): Promise<{ file: string; mimeType: string } | null> {\n const pos = this.state.value.indexOf('/');\n if (pos !== -1) {\n const adapter = this.state.value.substring(0, pos);\n const path = this.state.value.substring(pos + 1);\n return this.props.oContext.socket.readFile(adapter, path, true);\n }\n\n return Promise.resolve(null);\n }\n\n play(): void {\n void this.loadFile().then(data => {\n if (typeof AudioContext !== 'undefined' && data?.file) {\n const oContext = new AudioContext();\n const buf = ConfigFileSelector.base64ToArrayBuffer(data.file);\n void oContext.decodeAudioData(\n buf,\n (buffer: AudioBuffer): void => {\n const source = oContext.createBufferSource(); // creates a sound source\n source.buffer = buffer; // tell the source which sounds to play\n source.connect(oContext.destination); // connect the source to the oContext's destination (the speakers)\n source.start(0);\n },\n (err: DOMException): void => window.alert(`Cannot play: ${err.message}`),\n );\n }\n });\n }\n\n getIcon(): JSX.Element | null {\n const extension = this.state.value.split('.').pop().toLowerCase();\n if (IMAGE_EXT.includes(extension)) {\n return (\n <div\n style={{\n ...styles.selectedImage,\n backgroundImage: `url(${this.imagePrefix}/${this.state.value})`,\n backgroundSize: 'contain',\n backgroundRepeat: 'no-repeat',\n }}\n />\n );\n }\n if (AUDIO_EXT.includes(extension)) {\n return (\n <IconButton\n style={{ color: '#00FF00' }}\n onClick={() => this.play()}\n >\n <IconPlay />\n </IconButton>\n );\n }\n if (DOC_EXT.includes(extension)) {\n return <IconText />;\n }\n if (VIDEO_EXT.includes(extension)) {\n return <IconVideo />;\n }\n if (JS_EXT.includes(extension)) {\n return <IconCode />;\n }\n return null;\n }\n\n renderFileBrowser(): JSX.Element | null {\n if (!this.state.showFileBrowser) {\n return null;\n }\n return (\n <DialogSelectFile\n imagePrefix={this.props.oContext.imagePrefix}\n socket={this.props.oContext.socket}\n selected={this.state.value}\n onClose={() => this.setState({ showFileBrowser: false })}\n onOk={_value => {\n const value = Array.isArray(_value) ? _value[0] : _value;\n this.setState({ value }, () =>\n this.onChange(this.props.attr, this.props.schema.trim === false ? value : (value || '').trim()),\n );\n }}\n selectOnlyFolders={this.props.schema.selectOnlyFolders}\n allowUpload={this.props.schema.allowUpload}\n allowDownload={this.props.schema.allowDownload}\n allowCreateFolder={this.props.schema.allowCreateFolder}\n allowView={this.props.schema.allowView}\n showToolbar={this.props.schema.showToolbar}\n limitPath={this.props.schema.limitPath}\n theme={this.props.oContext.theme}\n />\n );\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n const icon = this.getIcon();\n\n return (\n <div style={styles.fullWidth}>\n {icon}\n <TextField\n variant=\"standard\"\n style={icon ? styles.fullWidthIcon : styles.fullWidthOneButton}\n value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}\n error={!!error}\n disabled={!!disabled}\n slotProps={{\n htmlInput: {\n maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,\n readOnly: !!this.props.schema.disableEdit,\n },\n }}\n onChange={e => {\n const value = e.target.value;\n this.setState({ value }, () =>\n this.onChange(\n this.props.attr,\n this.props.schema.trim === false ? value : (value || '').trim(),\n ),\n );\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n />\n <Button\n disabled={disabled}\n variant=\"outlined\"\n onClick={() => this.setState({ showFileBrowser: true })}\n >\n ...\n </Button>\n {this.renderFileBrowser()}\n </div>\n );\n }\n}\n\nexport default ConfigFile;\n"]}
1
+ {"version":3,"file":"ConfigFile.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigFile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EACH,OAAO,IAAI,QAAQ,EACnB,IAAI,IAAI,QAAQ,EAChB,SAAS,IAAI,QAAQ,EACrB,QAAQ,IAAI,SAAS,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,MAAM,MAAM,GAAwC;IAChD,SAAS,EAAE;QACP,KAAK,EAAE,MAAM;KAChB;IACD,kBAAkB,EAAE;QAChB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,CAAC;KACjB;IACD,aAAa,EA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AAG,IAAI,SAAS;wBAC5E,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW;qBAC5C;iBACJ,EACD,QAAQ,EAAE,CAAC,CAAC,EAAE;oBACV,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBAC7B,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAC1B,IAAI,CAAC,QAAQ,CACT,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAClE,CACJ,CAAC;gBACN,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,EAAE,IAAI,CAAC,UAAU,CACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAClC,GACH;YACF,oBAAC,MAAM,IACH,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAC,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,UAGlD;YACR,IAAI,CAAC,iBAAiB,EAAE,CACvB,CACT,CAAC;IACN,CAAC;CACJ;AAED,eAAe,UAAU,CAAC","sourcesContent":["import React, { type JSX } from 'react';\n\nimport { Button, TextField, IconButton } from '@mui/material';\n\nimport {\n Article as IconText,\n Code as IconCode,\n PlayArrow as IconPlay,\n Videocam as IconVideo,\n} from '@mui/icons-material';\n\nimport { DialogSelectFile } from '@iobroker/adapter-react-v5';\n\nimport type { ConfigItemFile } from '../types';\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport ConfigFileSelector from './ConfigFileSelector';\n\nconst styles: Record<string, React.CSSProperties> = {\n fullWidth: {\n width: '100%',\n },\n fullWidthOneButton: {\n width: 'calc(100% - 69px)',\n marginRight: 4,\n },\n fullWidthIcon: {\n width: 'calc(100% - 119px)',\n marginRight: 4,\n },\n selectedImage: {\n height: 40,\n width: 40,\n display: 'inline-block',\n marginRight: 8,\n },\n};\n\nconst IMAGE_EXT = ['jpg', 'jpeg', 'svg', 'png', 'webp', 'gif', 'apng', 'avif', 'webp'];\nconst AUDIO_EXT = ['mp3', 'ogg', 'wav', 'aac'];\nconst VIDEO_EXT = ['avi', 'mp4', 'mov'];\nconst DOC_EXT = ['txt', 'log', 'html', 'htm'];\nconst JS_EXT = ['json', 'js', 'ts'];\n\ninterface ConfigFileProps extends ConfigGenericProps {\n schema: ConfigItemFile;\n}\n\ninterface ConfigFileState extends ConfigGenericState {\n showFileBrowser?: boolean;\n}\n\nclass ConfigFile extends ConfigGeneric<ConfigFileProps, ConfigFileState> {\n private imagePrefix = '../..';\n\n componentDidMount(): void {\n super.componentDidMount();\n const value = ConfigGeneric.getValue(this.props.data, this.props.attr);\n this.imagePrefix = this.props.oContext.imagePrefix === undefined ? './files' : this.props.oContext.imagePrefix;\n this.setState({ value: value ?? '' });\n }\n\n static getDerivedStateFromProps(props: ConfigFileProps, state: ConfigFileState): Partial<ConfigFileState> | null {\n const value = ConfigGeneric.getValue(props.data, props.attr);\n if (\n value === null ||\n value === undefined ||\n value.toString().trim() !== (state.value || '').toString().trim()\n ) {\n return { value: value ?? '' };\n }\n return null;\n }\n\n loadFile(): Promise<{ file: string; mimeType: string } | null> {\n const pos = this.state.value.indexOf('/');\n if (pos !== -1) {\n const adapter = this.state.value.substring(0, pos);\n const path = this.state.value.substring(pos + 1);\n return this.props.oContext.socket.readFile(adapter, path, true);\n }\n\n return Promise.resolve(null);\n }\n\n play(): void {\n void this.loadFile().then(data => {\n if (typeof AudioContext !== 'undefined' && data?.file) {\n const oContext = new AudioContext();\n const buf = ConfigFileSelector.base64ToArrayBuffer(data.file);\n void oContext.decodeAudioData(\n buf,\n (buffer: AudioBuffer): void => {\n const source = oContext.createBufferSource(); // creates a sound source\n source.buffer = buffer; // tell the source which sounds to play\n source.connect(oContext.destination); // connect the source to the oContext's destination (the speakers)\n source.start(0);\n },\n (err: DOMException): void => window.alert(`Cannot play: ${err.message}`),\n );\n }\n });\n }\n\n getIcon(): JSX.Element | null {\n const extension = this.state.value.split('.').pop().toLowerCase();\n if (IMAGE_EXT.includes(extension)) {\n return (\n <div\n style={{\n ...styles.selectedImage,\n backgroundImage: `url(${this.imagePrefix}/${this.state.value})`,\n backgroundSize: 'contain',\n backgroundRepeat: 'no-repeat',\n }}\n />\n );\n }\n if (AUDIO_EXT.includes(extension)) {\n return (\n <IconButton\n style={{ color: '#00FF00' }}\n onClick={() => this.play()}\n >\n <IconPlay />\n </IconButton>\n );\n }\n if (DOC_EXT.includes(extension)) {\n return <IconText />;\n }\n if (VIDEO_EXT.includes(extension)) {\n return <IconVideo />;\n }\n if (JS_EXT.includes(extension)) {\n return <IconCode />;\n }\n return null;\n }\n\n renderFileBrowser(): JSX.Element | null {\n if (!this.state.showFileBrowser) {\n return null;\n }\n return (\n <DialogSelectFile\n imagePrefix={this.props.oContext.imagePrefix}\n socket={this.props.oContext.socket}\n selected={this.state.value}\n onClose={() => this.setState({ showFileBrowser: false })}\n onOk={_value => {\n const value = Array.isArray(_value) ? _value[0] : _value;\n this.setState({ value }, () =>\n this.onChange(this.props.attr, this.props.schema.trim === false ? value : (value || '').trim()),\n );\n }}\n selectOnlyFolders={this.props.schema.selectOnlyFolders}\n allowUpload={this.props.schema.allowUpload}\n allowDownload={this.props.schema.allowDownload}\n allowCreateFolder={this.props.schema.allowCreateFolder}\n allowView={this.props.schema.allowView}\n showToolbar={this.props.schema.showToolbar}\n limitPath={this.props.schema.limitPath}\n theme={this.props.oContext.theme}\n />\n );\n }\n\n renderItem(error: string, disabled: boolean /* , defaultValue */): JSX.Element {\n const icon = this.getIcon();\n\n return (\n <div style={styles.fullWidth}>\n {icon}\n <TextField\n variant=\"standard\"\n style={icon ? styles.fullWidthIcon : styles.fullWidthOneButton}\n value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}\n error={!!error}\n disabled={!!disabled}\n slotProps={{\n htmlInput: {\n maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,\n readOnly: !!this.props.schema.disableEdit,\n },\n }}\n onChange={e => {\n const value = e.target.value;\n this.setState({ value }, () =>\n this.onChange(\n this.props.attr,\n this.props.schema.trim === false ? value : (value || '').trim(),\n ),\n );\n }}\n placeholder={this.getText(this.props.schema.placeholder)}\n label={this.getText(this.props.schema.label)}\n helperText={this.renderHelp(\n this.props.schema.help,\n this.props.schema.helpLink,\n this.props.schema.noTranslation,\n )}\n />\n <Button\n disabled={disabled}\n variant=\"outlined\"\n onClick={() => this.setState({ showFileBrowser: true })}\n >\n ...\n </Button>\n {this.renderFileBrowser()}\n </div>\n );\n }\n}\n\nexport default ConfigFile;\n"]}