Skip to content

Commit

Permalink
Set the initialization default aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
lijie committed Nov 27, 2023
1 parent 975db94 commit 85282b3
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/@uppy/image-editor/src/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import limitCropboxMovementOnMove from './utils/limitCropboxMovementOnMove.js'
import limitCropboxMovementOnResize from './utils/limitCropboxMovementOnResize.js'

export default class Editor extends Component {
constructor(props) {
constructor (props) {
super(props)
this.state = {
angle90Deg: 0,
Expand All @@ -18,7 +18,7 @@ export default class Editor extends Component {
this.limitCropboxMovement = this.limitCropboxMovement.bind(this)
}

componentDidMount() {
componentDidMount () {
const { opts, storeCropperInstance } = this.props
this.cropper = new Cropper(
this.imgElement,
Expand All @@ -31,19 +31,19 @@ export default class Editor extends Component {
storeCropperInstance(this.cropper)
}

componentWillUnmount() {
componentWillUnmount () {
this.cropper.destroy()

this.imgElement.removeEventListener('cropstart', this.storePrevCropboxData)
this.imgElement.removeEventListener('cropend', this.limitCropboxMovement)
}

// eslint-disable-next-line react/sort-comp
storePrevCropboxData() {
storePrevCropboxData () {
this.setState({ prevCropboxData: this.cropper.getCropBoxData() })
}

limitCropboxMovement(event) {
limitCropboxMovement (event) {
const canvasData = this.cropper.getCanvasData()
const cropboxData = this.cropper.getCropBoxData()
const { prevCropboxData } = this.state
Expand All @@ -52,7 +52,7 @@ export default class Editor extends Component {
if (event.detail.action === 'all') {
const newCropboxData = limitCropboxMovementOnMove(canvasData, cropboxData, prevCropboxData)
if (newCropboxData) this.cropper.setCropBoxData(newCropboxData)
// When we stretch the cropbox by one of its sides
// When we stretch the cropbox by one of its sides
} else {
const newCropboxData = limitCropboxMovementOnResize(canvasData, cropboxData, prevCropboxData)
if (newCropboxData) this.cropper.setCropBoxData(newCropboxData)
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class Editor extends Component {
this.cropper.scale(scaleFactorX, scaleFactor)
}

renderGranularRotate() {
renderGranularRotate () {
const { i18n } = this.props
const { angleGranular } = this.state

Expand All @@ -126,7 +126,7 @@ export default class Editor extends Component {
)
}

renderRevert() {
renderRevert () {
const { i18n, opts } = this.props

return (
Expand All @@ -153,7 +153,7 @@ export default class Editor extends Component {
)
}

renderRotate() {
renderRotate () {
const { i18n } = this.props

return (
Expand All @@ -176,7 +176,7 @@ export default class Editor extends Component {
)
}

renderFlip() {
renderFlip () {
const { i18n } = this.props

return (
Expand All @@ -199,7 +199,7 @@ export default class Editor extends Component {
)
}

renderZoomIn() {
renderZoomIn () {
const { i18n } = this.props

return (
Expand All @@ -223,7 +223,7 @@ export default class Editor extends Component {
)
}

renderZoomOut() {
renderZoomOut () {
const { i18n } = this.props

return (
Expand All @@ -246,7 +246,7 @@ export default class Editor extends Component {
)
}

renderCropSquare() {
renderCropSquare () {
const { i18n } = this.props

return (
Expand All @@ -269,7 +269,7 @@ export default class Editor extends Component {
)
}

renderCropWidescreen() {
renderCropWidescreen () {
const { i18n } = this.props

return (
Expand All @@ -292,7 +292,7 @@ export default class Editor extends Component {
)
}

renderCropWidescreenVertical() {
renderCropWidescreenVertical () {
const { i18n } = this.props

return (
Expand All @@ -315,7 +315,7 @@ export default class Editor extends Component {
)
}

render() {
render () {
const { currentImage, opts } = this.props
const { actions } = opts
const imageURL = URL.createObjectURL(currentImage.data)
Expand Down

0 comments on commit 85282b3

Please sign in to comment.