@@ -74,9 +74,13 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
7474
7575 constructor ( ) {
7676 super ( ) ;
77- new UmbExtensionsManifestInitializer ( this , umbExtensionsRegistry , 'fileUploadPreview' , null , ( manifests ) => {
78- this . #manifests = manifests . map ( ( manifest ) => manifest . manifest ) ;
79- } ) ;
77+
78+ async #getManifests( ) {
79+ await new UmbExtensionsManifestInitializer ( this , umbExtensionsRegistry , 'fileUploadPreview' , null , ( exts ) => {
80+ this . #manifests = exts . map ( ( exts ) => exts . manifest ) ;
81+ } ) . asPromise ( ) ;
82+
83+ return this . #manifests;
8084 }
8185
8286 #setExtensions( extensions : Array < string > ) {
@@ -88,20 +92,24 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
8892 this . _extensions = extensions ?. map ( ( extension ) => `.${ extension } ` ) ;
8993 }
9094
91- #getPreviewElementAlias( ) {
92- const fallbackAlias = this . #manifests. find ( ( manifest ) => manifest . forMimeTypes . includes ( '*/*' ) ) ?. alias ;
95+ async #getPreviewElementAlias( ) {
96+ if ( ! this . value . src ) return ;
97+ const manifests = await this . #getManifests( ) ;
98+ const fallbackAlias = manifests . find ( ( manifest ) =>
99+ stringOrStringArrayContains ( manifest . forMimeTypes , '*/*' ) ,
100+ ) ?. alias ;
93101
94- const mimeType = this . #getMimeTypeFromPath( this . _src ) ;
102+ const mimeType = this . #getMimeTypeFromPath( this . value . src ) ;
95103 if ( ! mimeType ) return fallbackAlias ;
96104
97105 // Check for an exact match
98- const exactMatch = this . # manifests. find ( ( manifest ) => {
99- return manifest . forMimeTypes . includes ( mimeType ) ;
106+ const exactMatch = manifests . find ( ( manifest ) => {
107+ return stringOrStringArrayContains ( manifest . forMimeTypes , mimeType ) ;
100108 } ) ;
101109 if ( exactMatch ) return exactMatch . alias ;
102110
103111 // Check for wildcard match (e.g. image/*)
104- const wildcardMatch = this . # manifests. find ( ( manifest ) => {
112+ const wildcardMatch = manifests . find ( ( manifest ) => {
105113 const forMimeTypes = Array . isArray ( manifest . forMimeTypes ) ? manifest . forMimeTypes : [ manifest . forMimeTypes ] ;
106114 return forMimeTypes . find ( ( type ) => {
107115 const snippet = type . replace ( / \* / g, '' ) ;
0 commit comments