From b78c36c322f38ff8245cde419e0b262462dbebd4 Mon Sep 17 00:00:00 2001 From: Dominic Tobias Date: Wed, 11 May 2022 22:51:26 +0100 Subject: [PATCH] Allow document to be overwritten for iframes #482 --- package.json | 2 +- src/ReactCrop.tsx | 13 +++++++------ test/index.tsx | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index d2442b4..bec5450 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-image-crop", - "version": "10.0.0", + "version": "10.0.1", "description": "A responsive image cropping tool for React", "repository": "https://github.com/DominicTobias/react-image-crop", "main": "dist/ReactCrop.min.js", diff --git a/src/ReactCrop.tsx b/src/ReactCrop.tsx index b7d7d53..a581fa2 100644 --- a/src/ReactCrop.tsx +++ b/src/ReactCrop.tsx @@ -108,6 +108,7 @@ class ReactCrop extends PureComponent { }, } + document = document keysDown = new Set() docMoveBound = false mouseDownOnCrop = false @@ -167,9 +168,9 @@ class ReactCrop extends PureComponent { return } - document.addEventListener('pointermove', this.onDocPointerMove, DOC_MOVE_OPTS) - document.addEventListener('pointerup', this.onDocPointerDone, DOC_MOVE_OPTS) - document.addEventListener('pointercancel', this.onDocPointerDone, DOC_MOVE_OPTS) + this.document.addEventListener('pointermove', this.onDocPointerMove, DOC_MOVE_OPTS) + this.document.addEventListener('pointerup', this.onDocPointerDone, DOC_MOVE_OPTS) + this.document.addEventListener('pointercancel', this.onDocPointerDone, DOC_MOVE_OPTS) this.docMoveBound = true } @@ -179,9 +180,9 @@ class ReactCrop extends PureComponent { return } - document.removeEventListener('pointermove', this.onDocPointerMove, DOC_MOVE_OPTS) - document.removeEventListener('pointerup', this.onDocPointerDone, DOC_MOVE_OPTS) - document.removeEventListener('pointercancel', this.onDocPointerDone, DOC_MOVE_OPTS) + this.document.removeEventListener('pointermove', this.onDocPointerMove, DOC_MOVE_OPTS) + this.document.removeEventListener('pointerup', this.onDocPointerDone, DOC_MOVE_OPTS) + this.document.removeEventListener('pointercancel', this.onDocPointerDone, DOC_MOVE_OPTS) this.docMoveBound = false } diff --git a/test/index.tsx b/test/index.tsx index 6a53580..476dbf6 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -1,5 +1,5 @@ import ReactDOM from 'react-dom' -import React, { useState, useRef, useEffect, useCallback } from 'react' +import React, { useState, useRef } from 'react' import ReactCrop, { centerCrop, makeAspectCrop, Crop, PixelCrop } from '../src' import { cropPreview } from './cropPreview' import { useDebounceEffect } from './useDebounceEffect'