mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-12 20:06:33 +00:00
Compatibility fix for custom panel (#1321)
* Compatibility fix for custom panel * Lint
This commit is contained in:
parent
8d5c862908
commit
53e698c757
@ -6,5 +6,7 @@ import objAssign from 'es6-object-assign';
|
|||||||
objAssign.polyfill();
|
objAssign.polyfill();
|
||||||
|
|
||||||
if (Object.values === undefined) {
|
if (Object.values === undefined) {
|
||||||
Object.values = target => Object.keys(target).map(key => target[key]);
|
Object.values = function (target) {
|
||||||
|
return Object.keys(target).map(function (key) { return target[key]; });
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,10 @@ let es5Loaded = null;
|
|||||||
|
|
||||||
window.loadES5Adapter = () => {
|
window.loadES5Adapter = () => {
|
||||||
if (!es5Loaded) {
|
if (!es5Loaded) {
|
||||||
es5Loaded = loadJS(`${__PUBLIC_PATH__}custom-elements-es5-adapter.js`).catch();
|
es5Loaded = Promise.all([
|
||||||
|
loadJS(`${__PUBLIC_PATH__}custom-elements-es5-adapter.js`).catch(),
|
||||||
|
loadJS(`${__PUBLIC_PATH__}compatibility.js`),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
return es5Loaded;
|
return es5Loaded;
|
||||||
};
|
};
|
||||||
|
@ -3,18 +3,24 @@ import { loadJS } from '../../common/dom/load_resource.js';
|
|||||||
// Make sure we only import every JS-based panel once (HTML import has this built-in)
|
// Make sure we only import every JS-based panel once (HTML import has this built-in)
|
||||||
const JS_CACHE = {};
|
const JS_CACHE = {};
|
||||||
|
|
||||||
export default function loadCustomPanel(panelConfig) {
|
export default async function loadCustomPanel(panelConfig) {
|
||||||
if ('html_url' in panelConfig) {
|
if (panelConfig.html_url) {
|
||||||
return Promise.all([
|
const toLoad = [
|
||||||
import(/* webpackChunkName: "legacy-support" */ '../legacy-support.js'),
|
|
||||||
import(/* webpackChunkName: "import-href-polyfill" */ '../../resources/html-import/import-href.js'),
|
import(/* webpackChunkName: "import-href-polyfill" */ '../../resources/html-import/import-href.js'),
|
||||||
// eslint-disable-next-line
|
];
|
||||||
]).then(([{}, { importHrefPromise }]) => importHrefPromise(panelConfig.html_url));
|
|
||||||
|
if (!panelConfig.embed_iframe) {
|
||||||
|
toLoad.push(import(/* webpackChunkName: "legacy-support" */ '../legacy-support.js'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const [{ importHrefPromise }] = await Promise.all(toLoad);
|
||||||
|
await importHrefPromise(panelConfig.html_url);
|
||||||
} else if (panelConfig.js_url) {
|
} else if (panelConfig.js_url) {
|
||||||
if (!(panelConfig.js_url in JS_CACHE)) {
|
if (!(panelConfig.js_url in JS_CACHE)) {
|
||||||
JS_CACHE[panelConfig.js_url] = loadJS(panelConfig.js_url);
|
JS_CACHE[panelConfig.js_url] = loadJS(panelConfig.js_url);
|
||||||
}
|
}
|
||||||
return JS_CACHE[panelConfig.js_url];
|
await JS_CACHE[panelConfig.js_url];
|
||||||
|
} else {
|
||||||
|
throw new Error('No valid url found in panel config.');
|
||||||
}
|
}
|
||||||
return Promise.reject('No valid url found in panel config.');
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ function createConfig(isProdBuild, latestBuild) {
|
|||||||
app: './src/entrypoints/app.js',
|
app: './src/entrypoints/app.js',
|
||||||
authorize: './src/entrypoints/authorize.js',
|
authorize: './src/entrypoints/authorize.js',
|
||||||
core: './src/entrypoints/core.js',
|
core: './src/entrypoints/core.js',
|
||||||
|
compatibility: './src/entrypoints/compatibility.js',
|
||||||
'custom-panel': './src/entrypoints/custom-panel.js',
|
'custom-panel': './src/entrypoints/custom-panel.js',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,7 +82,6 @@ function createConfig(isProdBuild, latestBuild) {
|
|||||||
babelOptions.presets = [
|
babelOptions.presets = [
|
||||||
[require('babel-preset-env').default, { modules: false }]
|
[require('babel-preset-env').default, { modules: false }]
|
||||||
];
|
];
|
||||||
entry.compatibility = './src/entrypoints/compatibility.js';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isProdBuild) {
|
if (isProdBuild) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user