11import type { UmbImageCropperPropertyEditorValue } from './types.js' ;
22import 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' ;
65import { UmbChangeEvent } from '@umbraco-cms/backoffice/event' ;
6+ import { UmbFileDropzoneItemStatus , UmbInputDropzoneDashedStyles } from '@umbraco-cms/backoffice/dropzone' ;
77import { 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 ' ;
1010import { 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' ;
1116
12- import './image-cropper.element.js' ;
17+ import './image-cropper-field .element.js' ;
1318import './image-cropper-focus-setter.element.js' ;
1419import './image-cropper-preview.element.js' ;
15- import './image-cropper-field .element.js' ;
20+ import './image-cropper.element.js' ;
1621
1722const DefaultFocalPoint = { left : 0.5 , top : 0.5 } ;
18- const DefaultValue = {
23+ const DefaultValue : UmbImageCropperPropertyEditorValue = {
1924 temporaryFileId : null ,
2025 src : '' ,
2126 crops : [ ] ,
@@ -28,9 +33,6 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
2833 typeof UmbLitElement ,
2934 undefined
3035> ( UmbLitElement , undefined ) {
31- @query ( '#dropzone' )
32- private _dropzone ?: UUIFileDropzoneElement ;
33-
3436 /**
3537 * Sets the input to required, meaning validation will fail if the value is empty.
3638 * @type {boolean }
@@ -45,18 +47,15 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
4547 crops : UmbImageCropperPropertyEditorValue [ 'crops' ] = [ ] ;
4648
4749 @state ( )
48- file ?: File ;
49-
50- @state ( )
51- fileUnique ?: string ;
50+ private _file ?: UmbUploadableItem ;
5251
5352 @state ( )
5453 private _accept ?: string ;
5554
5655 @state ( )
5756 private _loading = true ;
5857
59- #manager = new UmbTemporaryFileManager ( this ) ;
58+ #config = new UmbTemporaryFileConfigRepository ( this ) ;
6059
6160 constructor ( ) {
6261 super ( ) ;
@@ -76,9 +75,9 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
7675 }
7776
7877 async #observeAcceptedFileTypes( ) {
79- const config = await this . #manager . getConfiguration ( ) ;
78+ await this . #config . initialized ;
8079 this . observe (
81- config . part ( 'imageFileTypes' ) ,
80+ this . # config. part ( 'imageFileTypes' ) ,
8281 ( imageFileTypes ) => {
8382 this . _accept = imageFileTypes . join ( ',' ) ;
8483 this . _loading = false ;
@@ -87,34 +86,27 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
8786 ) ;
8887 }
8988
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 ( ) ;
9491
95- this . file = file ;
96- this . fileUnique = unique ;
92+ const target = e . target as UmbInputDropzoneElement ;
93+ const file = target . value ?. [ 0 ] ;
9794
98- this . value = assignToFrozenObject ( this . value ?? DefaultValue , { temporaryFileId : unique } ) ;
95+ if ( file ?. status !== UmbFileDropzoneItemStatus . COMPLETE ) return ;
9996
100- this . #manager ?. uploadOne ( { temporaryUnique : unique , file } ) ;
97+ this . _file = file ;
10198
102- this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
103- }
99+ this . value = assignToFrozenObject ( this . value ?? DefaultValue , {
100+ temporaryFileId : file . temporaryFile ?. temporaryUnique ,
101+ } ) ;
104102
105- #onBrowse( e : Event ) {
106- if ( ! this . _dropzone ) return ;
107- e . stopImmediatePropagation ( ) ;
108- this . _dropzone . browse ( ) ;
103+ this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
109104 }
110105
111106 #onRemove = ( ) => {
112107 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 ;
118110
119111 this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
120112 } ;
@@ -144,7 +136,7 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
144136 return html `<div id= "loader" > <uui- loader> </ uui- loader> </ div> ` ;
145137 }
146138
147- if ( this . value ?. src || this . file ) {
139+ if ( this . value ?. src || this . _file ) {
148140 return this . #renderImageCropper( ) ;
149141 }
150142
@@ -153,14 +145,11 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
153145
154146 #renderDropzone( ) {
155147 return html `
156- <uui - file -dropzone
148+ <umb - input - dropzone
157149 id= "dropzone"
158- label = "dropzone"
159150 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>
164153 ` ;
165154 }
166155
@@ -184,31 +173,24 @@ export class UmbInputImageCropperElement extends UmbFormControlMixin<
184173 }
185174
186175 #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} >
188180 <uui- butto n slot= "actions" @click = ${ this . #onRemove} label= ${ this . localize . term ( 'content_uploadClear' ) } >
189181 <uui- icon name= "icon-trash" > </ uui- icon> ${ this . localize . term ( 'content_uploadClear' ) }
190182 </ uui- butto n>
191183 </ umb- image-cropper- field> ` ;
192184 }
193185
194- static override styles = [
186+ static override readonly styles = [
187+ UmbTextStyles ,
188+ UmbInputDropzoneDashedStyles ,
195189 css `
196190 # loader {
197191 display : flex;
198192 justify-content : center;
199193 }
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- }
212194 ` ,
213195 ] ;
214196}
0 commit comments