1
1
import type { UmbImageCropperPropertyEditorValue } from './types.js' ;
2
2
import type { UmbInputImageCropperFieldElement } from './image-cropper-field.element.js' ;
3
- import { html , customElement , property , query , state , css , ifDefined } from '@umbraco-cms/backoffice/external/lit' ;
4
- import type { UUIFileDropzoneElement , UUIFileDropzoneEvent } from '@umbraco-cms/backoffice/external/uui' ;
5
- import { UmbId } from '@umbraco-cms/backoffice/id' ;
3
+ import { css , customElement , html , ifDefined , property , state } from '@umbraco-cms/backoffice/external/lit' ;
4
+ import { assignToFrozenObject } from '@umbraco-cms/backoffice/observable-api' ;
6
5
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event' ;
6
+ import { UmbFileDropzoneItemStatus , UmbInputDropzoneDashedStyles } from '@umbraco-cms/backoffice/dropzone' ;
7
7
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
8
- import { UmbTemporaryFileManager } from '@umbraco-cms/backoffice/temporary-file ' ;
9
- import { assignToFrozenObject } from '@umbraco-cms/backoffice/observable-api ' ;
8
+ import { UmbTextStyles } from '@umbraco-cms/backoffice/style ' ;
9
+ import { UmbTemporaryFileConfigRepository } from '@umbraco-cms/backoffice/temporary-file ' ;
10
10
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY , UmbFormControlMixin } from '@umbraco-cms/backoffice/validation' ;
11
+ import type {
12
+ UmbDropzoneChangeEvent ,
13
+ UmbInputDropzoneElement ,
14
+ UmbUploadableItem ,
15
+ } from '@umbraco-cms/backoffice/dropzone' ;
11
16
12
- import './image-cropper.element.js' ;
17
+ import './image-cropper-field .element.js' ;
13
18
import './image-cropper-focus-setter.element.js' ;
14
19
import './image-cropper-preview.element.js' ;
15
- import './image-cropper-field .element.js' ;
20
+ import './image-cropper.element.js' ;
16
21
17
22
const DefaultFocalPoint = { left : 0.5 , top : 0.5 } ;
18
- const DefaultValue = {
23
+ const DefaultValue : UmbImageCropperPropertyEditorValue = {
19
24
temporaryFileId : null ,
20
25
src : '' ,
21
26
crops : [ ] ,
@@ -28,9 +33,6 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
28
33
typeof UmbLitElement ,
29
34
undefined
30
35
> ( UmbLitElement , undefined ) {
31
- @query ( '#dropzone' )
32
- private _dropzone ?: UUIFileDropzoneElement ;
33
-
34
36
/**
35
37
* Sets the input to required, meaning validation will fail if the value is empty.
36
38
* @type {boolean }
@@ -45,18 +47,15 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
45
47
crops : UmbImageCropperPropertyEditorValue [ 'crops' ] = [ ] ;
46
48
47
49
@state ( )
48
- file ?: File ;
49
-
50
- @state ( )
51
- fileUnique ?: string ;
50
+ private _file ?: UmbUploadableItem ;
52
51
53
52
@state ( )
54
53
private _accept ?: string ;
55
54
56
55
@state ( )
57
56
private _loading = true ;
58
57
59
- #manager = new UmbTemporaryFileManager ( this ) ;
58
+ #config = new UmbTemporaryFileConfigRepository ( this ) ;
60
59
61
60
constructor ( ) {
62
61
super ( ) ;
@@ -76,9 +75,9 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
76
75
}
77
76
78
77
async #observeAcceptedFileTypes( ) {
79
- const config = await this . #manager . getConfiguration ( ) ;
78
+ await this . #config . initialized ;
80
79
this . observe (
81
- config . part ( 'imageFileTypes' ) ,
80
+ this . # config. part ( 'imageFileTypes' ) ,
82
81
( imageFileTypes ) => {
83
82
this . _accept = imageFileTypes . join ( ',' ) ;
84
83
this . _loading = false ;
@@ -87,34 +86,27 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
87
86
) ;
88
87
}
89
88
90
- #onUpload( e : UUIFileDropzoneEvent ) {
91
- const file = e . detail . files [ 0 ] ;
92
- if ( ! file ) return ;
93
- const unique = UmbId . new ( ) ;
89
+ #onUpload( e : UmbDropzoneChangeEvent ) {
90
+ e . stopImmediatePropagation ( ) ;
94
91
95
- this . file = file ;
96
- this . fileUnique = unique ;
92
+ const target = e . target as UmbInputDropzoneElement ;
93
+ const file = target . value ?. [ 0 ] ;
97
94
98
- this . value = assignToFrozenObject ( this . value ?? DefaultValue , { temporaryFileId : unique } ) ;
95
+ if ( file ?. status !== UmbFileDropzoneItemStatus . COMPLETE ) return ;
99
96
100
- this . #manager ?. uploadOne ( { temporaryUnique : unique , file } ) ;
97
+ this . _file = file ;
101
98
102
- this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
103
- }
99
+ this . value = assignToFrozenObject ( this . value ?? DefaultValue , {
100
+ temporaryFileId : file . temporaryFile ?. temporaryUnique ,
101
+ } ) ;
104
102
105
- #onBrowse( e : Event ) {
106
- if ( ! this . _dropzone ) return ;
107
- e . stopImmediatePropagation ( ) ;
108
- this . _dropzone . browse ( ) ;
103
+ this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
109
104
}
110
105
111
106
#onRemove = ( ) => {
112
107
this . value = undefined ;
113
- if ( this . fileUnique ) {
114
- this . #manager?. removeOne ( this . fileUnique ) ;
115
- }
116
- this . fileUnique = undefined ;
117
- this . file = undefined ;
108
+ this . _file ?. temporaryFile ?. abortController ?. abort ( ) ;
109
+ this . _file = undefined ;
118
110
119
111
this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
120
112
} ;
@@ -144,7 +136,7 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
144
136
return html `<div id= "loader" > <uui- loader> </ uui- loader> </ div> ` ;
145
137
}
146
138
147
- if ( this . value ?. src || this . file ) {
139
+ if ( this . value ?. src || this . _file ) {
148
140
return this . #renderImageCropper( ) ;
149
141
}
150
142
@@ -153,14 +145,11 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
153
145
154
146
#renderDropzone( ) {
155
147
return html `
156
- <uui - file -dropzone
148
+ <umb - input - dropzone
157
149
id= "dropzone"
158
- label = "dropzone"
159
150
accept = ${ ifDefined ( this . _accept ) }
160
- @change = "${ this . #onUpload} "
161
- @click = ${ this . #onBrowse} >
162
- <uui- butto n label= ${ this . localize . term ( 'media_clickToUpload' ) } @click = "${ this . #onBrowse} " > </ uui- butto n>
163
- </ uui- file-dropzone>
151
+ dis able-folder- upload
152
+ @change = "${ this . #onUpload} " > </ umb- input- dropzone>
164
153
` ;
165
154
}
166
155
@@ -184,31 +173,24 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
184
173
}
185
174
186
175
#renderImageCropper( ) {
187
- return html `<umb- image-cropper- field .value = ${ this . value } .file = ${ this . file as File } @change = ${ this . #onChange} >
176
+ return html `<umb- image-cropper- field
177
+ .value = ${ this . value }
178
+ .file = ${ this . _file ?. temporaryFile ?. file }
179
+ @change = ${ this . #onChange} >
188
180
<uui- butto n slot= "actions" @click = ${ this . #onRemove} label= ${ this . localize . term ( 'content_uploadClear' ) } >
189
181
<uui- icon name= "icon-trash" > </ uui- icon> ${ this . localize . term ( 'content_uploadClear' ) }
190
182
</ uui- butto n>
191
183
</ umb- image-cropper- field> ` ;
192
184
}
193
185
194
- static override styles = [
186
+ static override readonly styles = [
187
+ UmbTextStyles ,
188
+ UmbInputDropzoneDashedStyles ,
195
189
css `
196
190
# loader {
197
191
display : flex;
198
192
justify-content : center;
199
193
}
200
-
201
- uui-file-dropzone {
202
- position : relative;
203
- display : block;
204
- }
205
- uui-file-dropzone ::after {
206
- content : '' ;
207
- position : absolute;
208
- inset : 0 ;
209
- cursor : pointer;
210
- border : 1px dashed var (--uui-color-divider-emphasis );
211
- }
212
194
` ,
213
195
] ;
214
196
}
0 commit comments