|
@@ -25,10 +25,6 @@ module.exports = class ImageEditor extends Plugin {
|
|
|
this.opts = { ...defaultOptions, ...opts }
|
|
|
|
|
|
// this.i18nInit()
|
|
|
-
|
|
|
- this.initEditor = this.initEditor.bind(this)
|
|
|
- this.setCurrentImage = this.setCurrentImage.bind(this)
|
|
|
- this.render = this.render.bind(this)
|
|
|
}
|
|
|
|
|
|
// setOptions (newOpts) {
|
|
@@ -43,41 +39,49 @@ module.exports = class ImageEditor extends Plugin {
|
|
|
// this.setPluginState() // so that UI re-renders and we see the updated locale
|
|
|
// }
|
|
|
|
|
|
- initEditor () {
|
|
|
+ edit = () => {
|
|
|
const { currentImage } = this.getPluginState()
|
|
|
|
|
|
- if (currentImage.preview) {
|
|
|
- const cropper = new Cropper(this.imgElement, {
|
|
|
- aspectRatio: 16 / 9,
|
|
|
- crop (event) {
|
|
|
- console.log(event.detail.x)
|
|
|
- console.log(event.detail.y)
|
|
|
- console.log(event.detail.width)
|
|
|
- console.log(event.detail.height)
|
|
|
- console.log(event.detail.rotate)
|
|
|
- console.log(event.detail.scaleX)
|
|
|
- console.log(event.detail.scaleY)
|
|
|
- }
|
|
|
+ this.cropper.rotate(90)
|
|
|
+ this.cropper.getCroppedCanvas().toBlob((blob) => {
|
|
|
+ this.uppy.setFileState(currentImage.id, {
|
|
|
+ data: blob,
|
|
|
+ size: blob.size,
|
|
|
+ preview: null
|
|
|
+ })
|
|
|
+ const updatedFile = this.uppy.getFile(currentImage.id)
|
|
|
+ this.uppy.emit('thumbnail:request', updatedFile)
|
|
|
+ this.setPluginState({
|
|
|
+ currentImage: updatedFile
|
|
|
})
|
|
|
+ this.cropper.destroy()
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
- cropper.getCroppedCanvas().toBlob((blob) => {
|
|
|
- console.log(blob)
|
|
|
- this.uppy.setFileState(currentImage.id, {
|
|
|
- data: blob,
|
|
|
- preview: null
|
|
|
- })
|
|
|
- const updatedFile = this.uppy.getFile(currentImage.id)
|
|
|
- this.uppy.emit('thumbnail:request', updatedFile)
|
|
|
- })
|
|
|
- }, 5000)
|
|
|
+ initEditor = () => {
|
|
|
+ console.log(this.imgElement)
|
|
|
+ const { currentImage } = this.getPluginState()
|
|
|
+
|
|
|
+ if (currentImage.preview) {
|
|
|
+ this.cropper = new Cropper(this.imgElement, {
|
|
|
+ aspectRatio: 16 / 9
|
|
|
+ // crop (event) {
|
|
|
+ // console.log(event.detail.x)
|
|
|
+ // console.log(event.detail.y)
|
|
|
+ // console.log(event.detail.width)
|
|
|
+ // console.log(event.detail.height)
|
|
|
+ // console.log(event.detail.rotate)
|
|
|
+ // console.log(event.detail.scaleX)
|
|
|
+ // console.log(event.detail.scaleY)
|
|
|
+ // }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- setCurrentImage (file) {
|
|
|
- const firstFile = this.uppy.getFiles()[0]
|
|
|
+ selectFile = (file) => {
|
|
|
+ console.log('set current image!', file)
|
|
|
this.setPluginState({
|
|
|
- currentImage: firstFile
|
|
|
+ currentImage: file
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -96,19 +100,19 @@ module.exports = class ImageEditor extends Plugin {
|
|
|
this.unmount()
|
|
|
}
|
|
|
|
|
|
- render (state) {
|
|
|
+ render () {
|
|
|
const { currentImage } = this.getPluginState()
|
|
|
-
|
|
|
if (currentImage === null) {
|
|
|
return
|
|
|
}
|
|
|
+ const imageURL = URL.createObjectURL(currentImage.data)
|
|
|
|
|
|
return (
|
|
|
<div class="uppy-ImageCropper">
|
|
|
<img
|
|
|
class="uppy-ImageCropper-image"
|
|
|
alt={currentImage.name}
|
|
|
- src={currentImage.preview}
|
|
|
+ src={imageURL}
|
|
|
ref={(ref) => { this.imgElement = ref }}
|
|
|
/>
|
|
|
</div>
|