check that returned js might potentially be a new element

This commit is contained in:
Jacob Overgaard
2022-08-25 15:13:00 +02:00
parent b5ca93d0a2
commit d9552ce04a

View File

@@ -1,13 +1,11 @@
import { ManifestCore } from '../models';
import { ManifestTypes } from '../models';
import { hasDefaultExport } from './has-default-export.function';
import { isManifestElementType } from './is-extension.function';
import { loadExtension } from './load-extension.function';
export async function createExtensionElement(manifest: ManifestCore): Promise<HTMLElement | undefined> {
console.log('🚀 ~ file: create-extension-element.function.ts ~ line 7 ~ createExtensionElement ~ manifest', manifest);
export async function createExtensionElement(manifest: ManifestTypes): Promise<HTMLElement | undefined> {
//TODO: Write tests for these extension options:
const js = await loadExtension(manifest);
console.log('🚀 ~ file: create-extension-element.function.ts ~ line 9 ~ createExtensionElement ~ js', js);
if (isManifestElementType(manifest) && manifest.elementName) {
// created by manifest method providing HTMLElement
return document.createElement(manifest.elementName);
@@ -17,9 +15,9 @@ export async function createExtensionElement(manifest: ManifestCore): Promise<HT
console.log('-- created by manifest method providing HTMLElement', js);
return js;
}
if ('elementName' in js) {
if (isManifestElementType(js) && js.elementName) {
// created by js export elementName
return document.createElement((js as any).elementName);
return document.createElement(js.elementName);
}
if (hasDefaultExport(js)) {