@@ -19,7 +19,6 @@ import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
19
19
20
20
import { UmbExtensionsManifestInitializer } from '@umbraco-cms/backoffice/extension-api' ;
21
21
import { type ManifestFileUploadPreview , umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry' ;
22
- import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api' ;
23
22
24
23
@customElement ( 'umb-input-upload-field' )
25
24
export class UmbInputUploadFieldElement extends UmbLitElement {
@@ -70,14 +69,12 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
70
69
71
70
#manager = new UmbTemporaryFileManager ( this ) ;
72
71
73
- #previewers = new UmbArrayState ( < Array < ManifestFileUploadPreview > > [ ] , ( x ) => x . alias ) ;
72
+ #previewers: Array < ManifestFileUploadPreview > = [ ] ;
74
73
75
74
constructor ( ) {
76
75
super ( ) ;
77
76
new UmbExtensionsManifestInitializer ( this , umbExtensionsRegistry , 'fileUploadPreview' , null , ( previews ) => {
78
- previews . forEach ( ( preview ) => {
79
- this . #previewers. appendOne ( preview . manifest ) ;
80
- } ) ;
77
+ this . #previewers = previews . map ( ( preview ) => preview . manifest ) ;
81
78
} ) ;
82
79
}
83
80
@@ -91,25 +88,29 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
91
88
}
92
89
93
90
#getPreviewElementAlias( ) {
94
- const previews = this . #previewers. getValue ( ) ;
95
- const fallbackAlias = previews . find ( ( preview ) => preview . forMimeTypes . includes ( '*/*' ) ) ?. alias ;
91
+ const fallbackAlias = this . #previewers. find ( ( preview ) => preview . forMimeTypes . includes ( '*/*' ) ) ?. alias ;
96
92
97
93
const mimeType = this . #getMimeTypeFromPath( this . _src ) ;
98
94
if ( ! mimeType ) return fallbackAlias ;
99
95
100
- const manifest = previews . find ( ( preview ) => {
101
- return preview . forMimeTypes ?. find ( ( type ) => {
102
- if ( mimeType === type ) preview . alias ;
96
+ // Check for an exact match
97
+ const exactMatch = this . #previewers. find ( ( preview ) => {
98
+ return preview . forMimeTypes . find ( ( type ) => type === mimeType ) ;
99
+ } ) ;
100
+ if ( exactMatch ) return exactMatch . alias ;
103
101
102
+ // Check for wildcard match (e.g. image/*)
103
+ const wildcardMatch = this . #previewers. find ( ( preview ) => {
104
+ return preview . forMimeTypes . find ( ( type ) => {
104
105
const snippet = type . replace ( / \* / g, '' ) ;
105
-
106
106
if ( mimeType . startsWith ( snippet ) ) return preview . alias ;
107
107
if ( mimeType . endsWith ( snippet ) ) return preview . alias ;
108
108
return undefined ;
109
109
} ) ;
110
110
} ) ;
111
+ if ( wildcardMatch ) return wildcardMatch . alias ;
111
112
112
- if ( manifest ) return manifest . alias ;
113
+ // Use fallbackAlias.
113
114
return fallbackAlias ;
114
115
}
115
116
0 commit comments