Updated WebAnnotation/Selection equals method
This commit is contained in:
parent
ffee4858d3
commit
103e89673c
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@recogito/recogito-client-core",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -3304,6 +3304,11 @@
|
|||
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=",
|
||||
"dev": true
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
|
||||
},
|
||||
"fast-json-stable-stringify": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
"dependencies": {
|
||||
"axios": "^0.19.0",
|
||||
"downshift": "^5.4.6",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"node-polyglot": "^2.4.0",
|
||||
"preact": "^10.4.1",
|
||||
"react-autosize-textarea": "^7.1.0",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { v4 as uuid } from 'uuid';
|
||||
import * as equals from 'fast-deep-equal';
|
||||
|
||||
export default class WebAnnotation {
|
||||
|
||||
|
@ -24,7 +25,7 @@ export default class WebAnnotation {
|
|||
return new WebAnnotation({ ...this.underlying, ...opt_props}, this.opts);
|
||||
}
|
||||
|
||||
/** An equality check based on the underlying object or (if given) ID **/
|
||||
/** An equality check based on the underlying object **/
|
||||
isEqual(other) {
|
||||
if (other?.type !== 'Annotation') {
|
||||
return false;
|
||||
|
@ -32,8 +33,9 @@ export default class WebAnnotation {
|
|||
return true;
|
||||
} else if (!this.underlying.id || !other.underlying.id) {
|
||||
return false;
|
||||
} else {
|
||||
return equals(this.underlying, other.underlying);
|
||||
}
|
||||
return this.underlying.id === other.underlying.id
|
||||
}
|
||||
|
||||
get readOnly() {
|
||||
|
|
|
@ -41,9 +41,8 @@ const Editor = props => {
|
|||
// on move. Therefore, don't update if a) props.annotation equals
|
||||
// the currentAnnotation, or props.annotation and currentAnnotations are
|
||||
// a selection, just created by the user.
|
||||
const preventUpdate = currentAnnotation?.isEqual(annotation) ||
|
||||
(currentAnnotation?.isSelection && annotation?.isSelection);
|
||||
|
||||
const preventUpdate = currentAnnotation?.isEqual(annotation);
|
||||
|
||||
if (!preventUpdate)
|
||||
setCurrentAnnotation(annotation);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import WebAnnotation from '../WebAnnotation';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as equals from 'fast-deep-equal';
|
||||
|
||||
/**
|
||||
* An "annotation in draft mode". Really the same
|
||||
|
@ -8,10 +9,10 @@ import { v4 as uuid } from 'uuid';
|
|||
*/
|
||||
export default class Selection {
|
||||
|
||||
constructor(target) {
|
||||
constructor(target, body) {
|
||||
this.underlying = {
|
||||
type: 'Selection',
|
||||
body: [],
|
||||
body: body || [],
|
||||
target
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ export default class Selection {
|
|||
if (!other) {
|
||||
return false;
|
||||
} else {
|
||||
return this.underlying === other.underlying;
|
||||
return equals(this.underlying, other.underlying);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue