Add support for JS modules in custom panels. (#1588)

* Added support for JS modules in custom panels.

* Update load-custom-panel.js

* Corrected syntax

* Force push

* Fixed EOL

* Delete index.html

* Fixed tempA href missing module_url name
This commit is contained in:
squidwardy 2018-08-23 11:14:47 +02:00 committed by Paulus Schoutsen
parent 09f238162e
commit 74185f0beb
2 changed files with 4 additions and 2 deletions

View File

@ -47,7 +47,7 @@ class HaPanelCustom extends NavigateMixin(EventsMixin(PolymerElement)) {
const config = panel.config._panel_custom;
const tempA = document.createElement('a');
tempA.href = config.html_url || config.js_url;
tempA.href = config.html_url || config.js_url || config.module_url;
if (!config.trust_external && !['localhost', '127.0.0.1', location.hostname].includes(tempA.hostname)) {
if (!confirm(`Do you trust the external panel "${config.name}" at "${tempA.href}"?

View File

@ -1,4 +1,4 @@
import { loadJS } from '../../common/dom/load_resource.js';
import { loadJS, loadModule } from '../../common/dom/load_resource.js';
// Make sure we only import every JS-based panel once (HTML import has this built-in)
const JS_CACHE = {};
@ -20,6 +20,8 @@ export default function loadCustomPanel(panelConfig) {
JS_CACHE[panelConfig.js_url] = loadJS(panelConfig.js_url);
}
return JS_CACHE[panelConfig.js_url];
} else if (panelConfig.module_url) {
return loadModule(panelConfig.module_url);
}
return Promise.reject('No valid url found in panel config.');
}