Regression: setPosition now triggered when element moves (OpenSeadragon)

This commit is contained in:
Rainer Simon 2021-07-14 21:11:40 +02:00
parent 707c2db717
commit 16297d0e29
1 changed files with 20 additions and 4 deletions

View File

@ -5,6 +5,12 @@ import { TrashIcon } from '../Icons';
import setPosition from './setPosition'; import setPosition from './setPosition';
import i18n from '../i18n'; import i18n from '../i18n';
/** We need to compare bounds by value, not by object ref **/
const bounds = elem => {
const { top, left, width, height } = elem.getBoundingClientRect();
return `${top}, ${left}, ${width}, ${height}`;
}
/** /**
* The popup editor component. * The popup editor component.
* *
@ -22,19 +28,29 @@ export default class Editor extends Component {
this.state = { this.state = {
currentAnnotation: props.annotation, currentAnnotation: props.annotation,
dragged: false dragged: false,
selectionBounds: bounds(props.selectedElement)
} }
} }
componentWillReceiveProps(next) { componentWillReceiveProps(next) {
this.setState({ currentAnnotation: next.annotation }); const { selectionBounds } = this.state;
const nextBounds = bounds(next.selectedElement);
this.setState({
currentAnnotation: next.annotation,
selectionBounds: nextBounds
});
if (this.props.modifiedTarget != next.modifiedTarget) { if (this.props.modifiedTarget != next.modifiedTarget) {
// Update in case target was changed (move, resize) // Update in case target was changed (move, resize)
if (this.state.currentAnnotation) { if (this.state.currentAnnotation)
this.updateCurrentAnnotation({ target: this.props.modifiedTarget }); this.updateCurrentAnnotation({ target: this.props.modifiedTarget });
}
// Change editor position if element has moved // Change editor position if element has moved
if (selectionBounds != nextBounds) {
if (this.element.current) {
this.removeObserver && this.removeObserver(); this.removeObserver && this.removeObserver();
this.removeObserver = this.initResizeObserver(); this.removeObserver = this.initResizeObserver();
} }