import type { Body, Meta } from '@uppy/core' import type { I18n, LocalUppyFile } from '@uppy/utils' import { Component } from 'preact' import type ImageEditor from './ImageEditor.js' import type { AspectRatio } from './ImageEditor.js' type Props = { currentImage: LocalUppyFile objectUrl: string initCropper: (imgElement: HTMLImageElement) => void opts: ImageEditor['opts'] i18n: I18n save: () => void angleGranular: number rotateBy: (degrees: number) => void rotateGranular: (degrees: number) => void flipHorizontal: () => void zoom: (ratio: number) => void setAspectRatio: (ratio: AspectRatio) => void reset: () => void } export default class Editor extends Component< Props > { imgElement!: HTMLImageElement componentDidMount(): void { const { initCropper } = this.props if (this.imgElement) { initCropper(this.imgElement) } } onRotate90Deg = (): void => { this.props.rotateBy(-90) } onRotateGranular = (ev: Event): void => { const newGranularAngle = Number((ev.target as HTMLInputElement).value) this.props.rotateGranular(newGranularAngle) } renderGranularRotate() { const { i18n } = this.props const { angleGranular } = this.props return ( ) } renderRevert() { const { i18n } = this.props return ( ) } renderRotate() { const { i18n } = this.props return ( ) } renderFlip() { const { i18n } = this.props return ( ) } renderZoomIn() { const { i18n } = this.props return ( ) } renderZoomOut() { const { i18n } = this.props return ( ) } renderCropSquare() { const { i18n } = this.props return ( ) } renderCropWidescreen() { const { i18n } = this.props return ( ) } renderCropWidescreenVertical() { const { i18n } = this.props return ( ) } render() { const { currentImage, objectUrl, opts } = this.props const { actions } = opts return (
{currentImage.name} { this.imgElement = ref as HTMLImageElement }} />
{actions.revert && this.renderRevert()} {actions.rotate && this.renderRotate()} {actions.granularRotate && this.renderGranularRotate()} {actions.flip && this.renderFlip()} {actions.zoomIn && this.renderZoomIn()} {actions.zoomOut && this.renderZoomOut()} {actions.cropSquare && this.renderCropSquare()} {actions.cropWidescreen && this.renderCropWidescreen()} {actions.cropWidescreenVertical && this.renderCropWidescreenVertical()}
) } }