<commit_before>import Webiny from 'Webiny';

class FileCropper extends Webiny.Ui.Component {

    constructor(props) {
        super(props);
        this.initialData = null;
        this.bindMethods('initCropper,getCacheBust,applyCropping,destroyCropper');
    }

    initCropper() {
        const data = this.props.config;
        this.cropper = $('.img-cropper');
        this.cropper.cropper(data);
        if (data.width && data.height) {
            this.cropper.cropper('setCropBoxData', {
                width: data.width,
                heigt: data.height
            });
        }
        this.initialData = this.cropper.cropper('getData');
    }

    destroyCropper() {
        this.cropper.cropper('destroy');
        this.cropper = null;
    }

    getCacheBust() {
        let cacheBust = '';
        if (this.props.image && this.props.image.modifiedOn && this.props.image.src.indexOf('data:') === -1) {
            cacheBust = '?ts=' + moment(this.props.image.modifiedOn).format('X');
        }
        return cacheBust;
    }

    applyCropping() {
        const model = _.clone(this.props.image);
        let options = {};

        if (this.props.config.width && this.props.config.height) {
            options = {
                width: this.props.config.width,
                height: this.props.config.height
            };
        }

        if (!_.isEqual(this.initialData, this.cropper.cropper('getData'))) {
            model.src = this.cropper.cropper('getCroppedCanvas', options).toDataURL();
        }

        this.props.onCrop(model);
    }
}

FileCropper.defaultProps = {
    config: {},
    onCrop: _.noop
};

/* eslint-disable */
/**
 * Config options
 * @see https://github.com/fengyuanchen/cropper
 */
const options = {
    aspectRatio: React.PropTypes.number,
    crop: React.PropTypes.func,
    preview: React.PropTypes.string,
    strict: React.PropTypes.bool,
    responsive: React.PropTypes.bool,
    checkImageOrigin: React.PropTypes.bool,
    background: React.PropTypes.bool,
    modal: React.PropTypes.bool,
    guides: React.PropTypes.bool,
    highlight: React.PropTypes.bool,
    autoCrop: React.PropTypes.bool,
    autoCropArea: React.PropTypes.number,
    dragCrop: React.PropTypes.bool,
    movable: React.PropTypes.bool,<commit_msg>Always crop, no matter the data in cropper<commit_after>import Webiny from 'Webiny';

class FileCropper extends Webiny.Ui.Component {

    constructor(props) {
        super(props);
        this.bindMethods('initCropper,getCacheBust,applyCropping,destroyCropper');
    }

    initCropper() {
        const data = this.props.config;
        this.cropper = $('.img-cropper');
        this.cropper.cropper(data);
        if (data.width && data.height) {
            this.cropper.cropper('setCropBoxData', {
                width: data.width,
                heigt: data.height
            });
        }
    }

    destroyCropper() {
        this.cropper.cropper('destroy');
        this.cropper = null;
    }

    getCacheBust() {
        let cacheBust = '';
        if (this.props.image && this.props.image.modifiedOn && this.props.image.src.indexOf('data:') === -1) {
            cacheBust = '?ts=' + moment(this.props.image.modifiedOn).format('X');
        }
        return cacheBust;
    }

    applyCropping() {
        const model = _.clone(this.props.image);
        let options = {};

        if (this.props.config.width && this.props.config.height) {
            options = {
                width: this.props.config.width,
                height: this.props.config.height
            };
        }

        model.src = this.cropper.cropper('getCroppedCanvas', options).toDataURL();
        this.props.onCrop(model);
    }
}

FileCropper.defaultProps = {
    config: {},
    onCrop: _.noop
};

/* eslint-disable */
/**
 * Config options
 * @see https://github.com/fengyuanchen/cropper
 */
const options = {
    aspectRatio: React.PropTypes.number,
    crop: React.PropTypes.func,
    preview: React.PropTypes.string,
    strict: React.PropTypes.bool,
    responsive: React.PropTypes.bool,
    checkImageOrigin: React.PropTypes.bool,
    background: React.PropTypes.bool,
    modal: React.PropTypes.bool,
    guides: React.PropTypes.bool,
    highlight: React.PropTypes.bool,
    autoCrop: React.PropTypes.bool,
    autoCropArea: React.PropTypes.number,
    dragCrop: React.PropTypes.bool,
    movable: React.PropTypes.bool,
{'fraction_non_alphanumeric': 0.13537414965986394, 'fraction_numerical': 0.00045351473922902497, 'mean_word_length': 2.296711509715994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303281', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1365, 'n_words': 213}