1
1
import { Controller } from "@hotwired/stimulus"
2
2
3
- import Uppy from '@uppy/core'
3
+ import Uppy , { Meta } from '@uppy/core'
4
4
import XHRUpload from '@uppy/xhr-upload'
5
5
import Dashboard from '@uppy/dashboard'
6
6
import ImageEditor from '@uppy/image-editor'
@@ -31,14 +31,12 @@ export default class extends Controller {
31
31
override connect ( ) : void {
32
32
this . uploader
33
33
. use ( Dashboard , {
34
- autoOpenFileEditor : true ,
34
+ autoOpen : 'imageEditor'
35
35
} )
36
36
. use ( Webcam , {
37
- target : Dashboard ,
38
37
modes : [ 'picture' ]
39
38
} )
40
39
. use ( ImageEditor , {
41
- target : Dashboard ,
42
40
quality : 0.8 ,
43
41
cropperOptions : {
44
42
aspectRatio : 1 ,
@@ -58,7 +56,6 @@ export default class extends Controller {
58
56
} )
59
57
. use ( XHRUpload , {
60
58
endpoint : this . endpointValue ,
61
- // @ts -expect-error until https://github.com/transloadit/uppy/pull/5279
62
59
method : 'PATCH' ,
63
60
fieldName : this . fieldNameValue ,
64
61
headers : {
@@ -73,20 +70,21 @@ export default class extends Controller {
73
70
this . uploader . cancelAll ( )
74
71
} )
75
72
this . uploader . on ( 'complete' , result => {
76
- if ( result . successful . length > 0 ) {
73
+ if ( result . successful && result . successful . length > 0 ) {
77
74
let img = document . createElement ( 'img' )
78
- img . setAttribute ( 'src' , result . successful [ 0 ] . uploadURL )
75
+ img . setAttribute ( 'src' , result . successful [ 0 ] . uploadURL ?? '' )
79
76
this . previewTarget . innerHTML = ''
80
77
this . previewTarget . appendChild ( img )
81
78
this . deleteTarget . disabled = false ;
82
- ( this . uploader . getPlugin ( 'Dashboard' ) as Dashboard ) . closeModal ( )
79
+ // FIXME: Should have a stricter type than 'any'
80
+ ( this . uploader . getPlugin ( 'Dashboard' ) as any ) . closeModal ( )
83
81
this . uploader . cancelAll ( )
84
82
}
85
83
} )
86
84
}
87
85
88
86
public start ( ) : void {
89
- ( this . uploader . getPlugin ( 'Dashboard' ) as Dashboard ) . openModal ( )
87
+ ( this . uploader . getPlugin ( 'Dashboard' ) as any ) . openModal ( )
90
88
}
91
89
92
90
}
0 commit comments