@@ -8,7 +8,6 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
8
8
import { UmbModalRouteRegistrationController , UMB_WORKSPACE_MODAL } from '@umbraco-cms/backoffice/modal' ;
9
9
import { UmbSorterController } from '@umbraco-cms/backoffice/sorter' ;
10
10
import { UUIFormControlMixin } from '@umbraco-cms/backoffice/external/uui' ;
11
- import type { UmbUploadableFileModel } from '@umbraco-cms/backoffice/media' ;
12
11
13
12
@customElement ( 'umb-input-media' )
14
13
export class UmbInputMediaElement extends UUIFormControlMixin ( UmbLitElement , '' ) {
@@ -22,9 +21,10 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
22
21
identifier : 'Umb.SorterIdentifier.InputMedia' ,
23
22
itemSelector : 'uui-card-media' ,
24
23
containerSelector : '.container' ,
24
+ /** TODO: This component probably needs some grid-like logic for resolve placement... [LI] */
25
+ resolvePlacement : ( ) => false ,
25
26
onChange : ( { model } ) => {
26
27
this . selection = model ;
27
-
28
28
this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
29
29
} ,
30
30
} ) ;
@@ -89,6 +89,12 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
89
89
@property ( { type : Boolean } )
90
90
showOpenButton ?: boolean ;
91
91
92
+ @property ( { type : String } )
93
+ startNode = '' ;
94
+
95
+ @property ( { type : Boolean } )
96
+ multiple = false ;
97
+
92
98
@property ( )
93
99
public set value ( idsString : string ) {
94
100
// Its with full purpose we don't call super.value, as thats being handled by the observation of the context selection.
@@ -99,10 +105,10 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
99
105
}
100
106
101
107
@state ( )
102
- private _editMediaPath = '' ;
108
+ protected editMediaPath = '' ;
103
109
104
110
@state ( )
105
- private _items ?: Array < UmbMediaCardItemModel > ;
111
+ protected items ?: Array < UmbMediaCardItemModel > ;
106
112
107
113
#pickerContext = new UmbMediaPickerContext ( this ) ;
108
114
@@ -115,12 +121,12 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
115
121
return { data : { entityType : 'media' , preset : { } } } ;
116
122
} )
117
123
. observeRouteBuilder ( ( routeBuilder ) => {
118
- this . _editMediaPath = routeBuilder ( { } ) ;
124
+ this . editMediaPath = routeBuilder ( { } ) ;
119
125
} ) ;
120
126
121
127
this . observe ( this . #pickerContext. selection , ( selection ) => ( this . value = selection . join ( ',' ) ) ) ;
122
128
this . observe ( this . #pickerContext. cardItems , ( cardItems ) => {
123
- this . _items = cardItems ;
129
+ this . items = cardItems ;
124
130
} ) ;
125
131
126
132
this . addValidator (
@@ -149,43 +155,31 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
149
155
150
156
#openPicker( ) {
151
157
this . #pickerContext. openPicker ( {
152
- hideTreeRoot : true ,
158
+ multiple : this . multiple ,
159
+ startNode : this . startNode ,
153
160
pickableFilter : this . #pickableFilter,
154
161
} ) ;
155
162
}
156
163
157
- async #onUploadCompleted( e : CustomEvent ) {
158
- const completed = e . detail ?. completed as Array < UmbUploadableFileModel > ;
159
- const uploaded = completed . map ( ( file ) => file . unique ) ;
160
-
161
- this . selection = [ ...this . selection , ...uploaded ] ;
162
- this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
164
+ protected onRemove ( item : UmbMediaCardItemModel ) {
165
+ this . #pickerContext. requestRemoveItem ( item . unique ) ;
163
166
}
164
167
165
168
render ( ) {
166
- return html `${ this . #renderDropzone( ) }
167
- <div class= "container" > ${ this . #renderItems( ) } ${ this . #renderAddButton( ) } </ div> ` ;
168
- }
169
-
170
- #renderDropzone( ) {
171
- if ( this . _items && this . _items . length >= this . max ) return ;
172
- return html `<umb- dropzone
173
- id= "dropzone"
174
- ?multiple= ${ this . max === 1 }
175
- @change = ${ this . #onUploadCompleted} > </ umb- dropzone> ` ;
169
+ return html `<div class= "container" > ${ this . #renderItems( ) } ${ this . #renderAddButton( ) } </ div> ` ;
176
170
}
177
171
178
172
#renderItems( ) {
179
- if ( ! this . _items ?. length ) return ;
173
+ if ( ! this . items ?. length ) return ;
180
174
return html `${ repeat (
181
- this . _items ,
175
+ this . items ,
182
176
( item ) => item . unique ,
183
- ( item ) => this . # renderItem( item ) ,
177
+ ( item ) => this . renderItem ( item ) ,
184
178
) } `;
185
179
}
186
180
187
181
#renderAddButton( ) {
188
- if ( this . _items && this . max && this . _items . length >= this . max ) return ;
182
+ if ( ( this . items && this . max && this . items . length >= this . max ) || ( this . items ?. length && ! this . multiple ) ) return ;
189
183
return html `
190
184
<uui- butto n
191
185
id= "btn-add"
@@ -198,30 +192,29 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
198
192
` ;
199
193
}
200
194
201
- # renderItem( item : UmbMediaCardItemModel ) {
195
+ protected renderItem ( item : UmbMediaCardItemModel ) {
202
196
return html `
203
- <uui- card- media name= ${ ifDefined ( item . name === null ? undefined : item . name ) } detail= ${ ifDefined ( item . unique ) } >
197
+ <uui- card- media
198
+ name= ${ ifDefined ( item . name === null ? undefined : item . name ) }
199
+ detail= ${ ifDefined ( item . unique ) }
200
+ href= "${ this . editMediaPath } edit/${ item . unique } " >
204
201
${ item . url
205
202
? html `<img src= ${ item . url } alt= ${ item . name } / > `
206
- : html `<umb- icon name= ${ ifDefined ( item . icon ) } > </ umb- icon> ` }
207
- ${ this . # renderIsTrashed( item ) }
203
+ : html `<umb- icon name= ${ ifDefined ( item . mediaType . icon ) } > </ umb- icon> ` }
204
+ ${ this . renderIsTrashed ( item ) }
208
205
<uui- action- bar slot= "actions" >
209
- ${ this . #renderOpenButton( item ) }
210
- <uui- butto n label= "Copy media" look = "secondary">
211
- <uui- icon name= "icon-documents" > </ uui- icon>
212
- </ uui- butto n>
213
206
<uui- butto n
207
+ label= ${ this . localize . term ( 'general_remove' ) }
214
208
look= "secondary"
215
- @click = ${ ( ) => this . #pickerContext. requestRemoveItem ( item . unique ) }
216
- label= "Remove media ${ item . name } " >
209
+ @click = ${ ( ) => this . onRemove ( item ) } >
217
210
<uui- icon name= "icon-trash" > </ uui- icon>
218
211
</ uui- butto n>
219
212
</ uui- action- bar>
220
213
</ uui- card- media>
221
214
` ;
222
215
}
223
216
224
- # renderIsTrashed( item : UmbMediaCardItemModel ) {
217
+ protected renderIsTrashed ( item : UmbMediaCardItemModel ) {
225
218
if ( ! item . isTrashed ) return ;
226
219
return html `
227
220
<uui- tag size= "s" slot = "tag" color = "danger">
@@ -230,18 +223,6 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
230
223
` ;
231
224
}
232
225
233
- #renderOpenButton( item : UmbMediaCardItemModel ) {
234
- if ( ! this . showOpenButton ) return ;
235
- return html `
236
- <uui- butto n
237
- compact
238
- href= "${ this . _editMediaPath } edit/${ item . unique } "
239
- label = ${ this . localize . term ( 'general_edit' ) + ` ${ item . name } ` } >
240
- <uui- icon name= "icon-edit" > </ uui- icon>
241
- </ uui- butto n>
242
- ` ;
243
- }
244
-
245
226
static styles = [
246
227
css `
247
228
: host {
@@ -250,8 +231,8 @@ export class UmbInputMediaElement extends UUIFormControlMixin(UmbLitElement, '')
250
231
.container {
251
232
display : grid;
252
233
gap : var (--uui-size-space-3 );
253
- grid-template-columns : repeat (auto-fill, minmax (160 px , 1fr ));
254
- grid-template -rows : repeat (auto-fill , minmax ( 160 px , 1 fr )) ;
234
+ grid-template-columns : repeat (auto-fill, minmax (150 px , 1fr ));
235
+ grid-auto -rows : 150 px ;
255
236
}
256
237
257
238
# btn-add {
0 commit comments