refactor ManifestWithLoader
This commit is contained in:
@@ -4,5 +4,5 @@ import { isManifestClassConstructorType } from './is-manifest-class-instance-typ
|
||||
import type { ManifestBase, ManifestClass } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
|
||||
export function isManifestClassableType(manifest: ManifestBase): manifest is ManifestClass {
|
||||
return isManifestClassConstructorType(manifest) || isManifestLoaderType(manifest) || isManifestJSType(manifest);
|
||||
return isManifestClassConstructorType(manifest) || isManifestLoaderType<object>(manifest) || isManifestJSType<object>(manifest);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ import { isManifestJSType } from './is-manifest-js-type.function';
|
||||
import { isManifestLoaderType } from './is-manifest-loader-type.function';
|
||||
import type { ManifestElement, ManifestBase } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
|
||||
export function isManifestElementableType(manifest: ManifestBase): manifest is ManifestElement {
|
||||
return isManifestElementNameType(manifest) || isManifestLoaderType(manifest) || isManifestJSType(manifest);
|
||||
export function isManifestElementableType<ElementType extends HTMLElement = HTMLElement>(manifest: ManifestBase): manifest is ManifestElement {
|
||||
return (
|
||||
isManifestElementNameType(manifest) ||
|
||||
isManifestLoaderType<ElementType>(manifest) ||
|
||||
isManifestJSType<ElementType>(manifest)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ManifestJSType } from './load-extension.function';
|
||||
import type { ManifestBase } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
import type { ManifestBase, ManifestWithLoader } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
|
||||
export function isManifestJSType(manifest: ManifestBase | unknown): manifest is ManifestJSType {
|
||||
return (manifest as ManifestJSType).js !== undefined;
|
||||
export type ManifestJSType<T> = ManifestWithLoader<T> & { js: string };
|
||||
export function isManifestJSType<T>(manifest: ManifestBase | unknown): manifest is ManifestJSType<T> {
|
||||
return (manifest as ManifestJSType<T>).js !== undefined;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ManifestLoaderType } from './load-extension.function';
|
||||
import type { ManifestBase } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
|
||||
export function isManifestLoaderType(manifest: ManifestBase): manifest is ManifestLoaderType {
|
||||
return typeof (manifest as ManifestLoaderType).loader === 'function';
|
||||
import type { ManifestBase, ManifestWithLoader } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
export type ManifestLoaderType<T> = ManifestWithLoader<T> & {
|
||||
loader: () => Promise<T>;
|
||||
};
|
||||
export function isManifestLoaderType<T>(manifest: ManifestBase): manifest is ManifestLoaderType<T> {
|
||||
return typeof (manifest as ManifestLoaderType<T>).loader === 'function';
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import { isManifestJSType } from './is-manifest-js-type.function';
|
||||
import { isManifestLoaderType } from './is-manifest-loader-type.function';
|
||||
import type { ManifestElement } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
import type { ManifestWithLoader } from '@umbraco-cms/backoffice/extensions-registry';
|
||||
|
||||
export type ManifestLoaderType = ManifestElement & { loader: () => Promise<object | HTMLElement> };
|
||||
export type ManifestJSType = ManifestElement & { js: string };
|
||||
|
||||
export async function loadExtension(manifest: ManifestElement): Promise<object | HTMLElement | null> {
|
||||
export async function loadExtension<T = unknown>(manifest: ManifestWithLoader<T>): Promise<T | null> {
|
||||
try {
|
||||
if (isManifestLoaderType(manifest)) {
|
||||
if (isManifestLoaderType<T>(manifest)) {
|
||||
return manifest.loader();
|
||||
}
|
||||
|
||||
if (isManifestJSType(manifest) && manifest.js) {
|
||||
if (isManifestJSType<T>(manifest) && manifest.js) {
|
||||
return await import(/* @vite-ignore */ manifest.js);
|
||||
}
|
||||
} catch (err: any) {
|
||||
|
||||
@@ -180,7 +180,8 @@ export interface ManifestClassWithClassConstructor extends ManifestClass {
|
||||
class: ClassConstructor<unknown>;
|
||||
}
|
||||
|
||||
export interface ManifestElement extends ManifestWithLoader<object | HTMLElement> {
|
||||
export interface ManifestElement<ElementType extends HTMLElement = HTMLElement>
|
||||
extends ManifestWithLoader<{ default: ClassConstructor<ElementType> } | Omit<object, 'default'>> {
|
||||
//type: ManifestStandardTypes;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { UmbPropertyEditorElement } from '../property-editor';
|
||||
import type { ManifestElement, ManifestBase } from './models';
|
||||
|
||||
// UI
|
||||
export interface ManifestPropertyEditorUI extends ManifestElement {
|
||||
export interface ManifestPropertyEditorUI extends ManifestElement<UmbPropertyEditorElement> {
|
||||
type: 'propertyEditorUI';
|
||||
meta: MetaPropertyEditorUI;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import { customElement } from 'lit/decorators.js';
|
||||
|
||||
@customElement('umb-collection-view-media-test')
|
||||
export class UmbCollectionViewMediaTestElement extends LitElement {
|
||||
|
||||
|
||||
|
||||
render() {
|
||||
return html`umb-collection-view-media-test`;
|
||||
}
|
||||
|
||||
|
||||
static styles = [UUITextStyles, css``];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user