@iobroker/json-config 7.5.0 → 7.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { LinearProgress } from '@mui/material';
|
|
3
3
|
import { I18n } from '@iobroker/adapter-react-v5';
|
|
4
4
|
import ConfigGeneric from '../JsonConfigComponent/ConfigGeneric';
|
|
5
5
|
const getOrLoadRemote = (remote, shareScope, remoteFallbackUrl) => new Promise((resolve, reject) => {
|
|
@@ -190,21 +190,6 @@ export default class ConfigCustom extends ConfigGeneric {
|
|
|
190
190
|
let item = CustomComponent ? (React.createElement(CustomComponent, { ...this.props,
|
|
191
191
|
// @ts-expect-error BF (2024-12-18) Remove after the 7.4 will be mainstream. All following lines
|
|
192
192
|
socket: this.props.oContext.socket, theme: this.props.oContext.theme, themeType: this.props.oContext.themeType, instance: this.props.oContext.instance, adapterName: this.props.oContext.adapterName, systemConfig: this.props.oContext.systemConfig, forceUpdate: this.props.oContext.forceUpdate })) : this.state.error ? (React.createElement("div", null, this.state.error)) : (React.createElement(LinearProgress, null));
|
|
193
|
-
// If any widths are defined
|
|
194
|
-
if (schema.xs || schema.sm || schema.md || schema.lg || schema.xl) {
|
|
195
|
-
item = (React.createElement(Grid2, { size: {
|
|
196
|
-
xs: schema.xs || 12,
|
|
197
|
-
sm: schema.sm || undefined,
|
|
198
|
-
md: schema.md || undefined,
|
|
199
|
-
lg: schema.lg || undefined,
|
|
200
|
-
xl: schema.xl || undefined,
|
|
201
|
-
}, style: {
|
|
202
|
-
marginBottom: 0,
|
|
203
|
-
textAlign: 'left',
|
|
204
|
-
...schema.style,
|
|
205
|
-
...(this.props.oContext.themeType === 'dark' ? schema.darkStyle : {}),
|
|
206
|
-
} }, item));
|
|
207
|
-
}
|
|
208
193
|
if (schema.newLine) {
|
|
209
194
|
return (React.createElement(React.Fragment, null,
|
|
210
195
|
React.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigCustom.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigCustom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,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,GAAG,KAAK,IAAmB,EAAE;YACrC,8BAA8B;YAC9B,IAAK,MAAc,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAE,MAAc,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;oBACzC,gGAAgG;oBAChG,gDAAgD;oBAChD,IAAI,OAAO,wBAAwB,KAAK,WAAW,EAAE,CAAC;wBAClD,sDAAsD;wBACtD,MAAO,MAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACJ,uCAAuC;wBACvC,gDAAgD;wBAChD,MAAO,MAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAE,wBAAgC,CAAC,UAAU,CAAC,CAAC,CAAC;oBACtF,CAAC;oBACD,6BAA6B;oBAC5B,MAAc,CAAC,MAAM,CAAC,CAAC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'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 any widths are defined\n if (schema.xs || schema.sm || schema.md || schema.lg || schema.xl) {\n item = (\n <Grid2\n size={{\n xs: schema.xs || 12,\n sm: schema.sm || undefined,\n md: schema.md || undefined,\n lg: schema.lg || undefined,\n xl: schema.xl || undefined,\n }}\n style={{\n marginBottom: 0,\n textAlign: 'left',\n ...schema.style,\n ...(this.props.oContext.themeType === 'dark' ? schema.darkStyle : {}),\n }}\n >\n {item}\n </Grid2>\n );\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,EAAS,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,C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BACI,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"]}
|
package/package.json
CHANGED