Skip to content

Commit

Permalink
fix: image disappears when applying an empty cropzone (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
lja1018 committed Dec 9, 2020
1 parent 72d32a2 commit b396cb8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/js/action.js
@@ -1,5 +1,5 @@
import { extend } from 'tui-code-snippet';
import { isSupportFileApi, base64ToBlob, toInteger } from './util';
import { isSupportFileApi, base64ToBlob, toInteger, isEmptyCropzone } from './util';
import Imagetracer from './helper/imagetracer';

export default {
Expand Down Expand Up @@ -304,7 +304,7 @@ export default {
{
crop: () => {
const cropRect = this.getCropzoneRect();
if (cropRect) {
if (cropRect && !isEmptyCropzone(cropRect)) {
this.crop(cropRect)
.then(() => {
this.stopDrawingMode();
Expand Down
7 changes: 7 additions & 0 deletions src/js/consts.js
Expand Up @@ -291,3 +291,10 @@ export const defaultFilterRangeValus = {
value: 0.1,
},
};

export const emptyCropRectValues = {
LEFT: 0,
TOP: 0,
WIDTH: 0.5,
HEIGHT: 0.5,
};
18 changes: 17 additions & 1 deletion src/js/util.js
Expand Up @@ -4,7 +4,7 @@
*/
import { forEach, sendHostname, extend, isString, pick, inArray } from 'tui-code-snippet';
import Promise from 'core-js-pure/features/promise';
import { SHAPE_FILL_TYPE, SHAPE_TYPE } from './consts';
import { SHAPE_FILL_TYPE, SHAPE_TYPE, emptyCropRectValues } from './consts';
const FLOATING_POINT_DIGIT = 2;
const CSS_PREFIX = 'tui-image-editor-';
const { min, max } = Math;
Expand Down Expand Up @@ -343,3 +343,19 @@ export function getFillTypeFromObject(shapeObj) {
export function isShape(obj) {
return inArray(obj.get('type'), SHAPE_TYPE) >= 0;
}

/**
* Check if cropRect is Empty.
* @param {Object} cropRect - cropRect object
* @param {Number} cropRect.left - cropRect left position value
* @param {Number} cropRect.top - cropRect top position value
* @param {Number} cropRect.width - cropRect width value
* @param {Number} cropRect.height - cropRect height value
* @returns {boolean}
*/
export function isEmptyCropzone(cropRect) {
const { left, top, width, height } = cropRect;
const { LEFT, TOP, WIDTH, HEIGHT } = emptyCropRectValues;

return left === LEFT && top === TOP && width === WIDTH && height === HEIGHT;
}

0 comments on commit b396cb8

Please sign in to comment.