@konfuzio/document-validation-ui 0.1.11-dev.3 → 0.1.11-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/app.css +1 -1
- package/dist/index.html +1 -1
- package/dist/js/app.js +1 -1
- package/dist/js/app.js.map +1 -1
- package/package.json +1 -1
- package/src/assets/scss/document_top_bar.scss +0 -4
- package/src/components/DocumentAnnotations/AnnotationContent.vue +22 -31
- package/src/components/DocumentAnnotations/AnnotationRow.vue +23 -13
- package/src/components/DocumentPage/DocumentPage.vue +4 -6
- package/src/components/DocumentTopBar/DocumentTopBar.vue +4 -8
- package/src/store/selection.js +10 -3
- package/src/utils/utils.js +1 -1
package/package.json
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
<script>
|
|
28
28
|
import { mapGetters, mapState } from "vuex";
|
|
29
|
+
import { isElementArray } from "../../utils/utils";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* This component is responsible for managing filled annotations.
|
|
@@ -81,11 +82,7 @@ export default {
|
|
|
81
82
|
return this.isAnnotationInEditMode(this.annotation.id, this.spanIndex);
|
|
82
83
|
},
|
|
83
84
|
annotationText() {
|
|
84
|
-
|
|
85
|
-
return this.$refs.contentEditable.textContent.trim();
|
|
86
|
-
} else {
|
|
87
|
-
return this.span.offset_string;
|
|
88
|
-
}
|
|
85
|
+
return this.$refs.contentEditable.textContent.trim();
|
|
89
86
|
},
|
|
90
87
|
},
|
|
91
88
|
|
|
@@ -95,14 +92,26 @@ export default {
|
|
|
95
92
|
// one was selected before so we set the state to the previous one (like a cancel)
|
|
96
93
|
|
|
97
94
|
if (
|
|
95
|
+
!newAnnotation &&
|
|
98
96
|
oldAnnotation &&
|
|
99
|
-
oldAnnotation.id === this.annotation.id
|
|
100
|
-
oldAnnotation.index === this.spanIndex
|
|
97
|
+
oldAnnotation.id === this.annotation.id
|
|
101
98
|
) {
|
|
102
99
|
this.handleCancel(true);
|
|
100
|
+
} else if (
|
|
101
|
+
newAnnotation &&
|
|
102
|
+
oldAnnotation &&
|
|
103
|
+
newAnnotation.id === this.annotation.id &&
|
|
104
|
+
newAnnotation.id !== oldAnnotation.id
|
|
105
|
+
) {
|
|
106
|
+
this.handleCancel();
|
|
103
107
|
}
|
|
104
108
|
},
|
|
109
|
+
span() {
|
|
110
|
+
// span content changed, ex. from click on entity
|
|
111
|
+
this.setText(this.span.offset_string);
|
|
112
|
+
},
|
|
105
113
|
},
|
|
114
|
+
|
|
106
115
|
methods: {
|
|
107
116
|
setText(text) {
|
|
108
117
|
this.$refs.contentEditable.textContent = text;
|
|
@@ -187,37 +196,19 @@ export default {
|
|
|
187
196
|
event.preventDefault();
|
|
188
197
|
}
|
|
189
198
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
} else {
|
|
194
|
-
index = this.spanIndex;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let spans = [];
|
|
198
|
-
|
|
199
|
-
// Validate if we are deleting an Annotation that it's not multi-lined
|
|
200
|
-
let isToDelete =
|
|
199
|
+
// Validate if we are declining an Annotation that is not multi-lined
|
|
200
|
+
// by deleting the content instead of clicking the 'decline' button
|
|
201
|
+
let isToDecline =
|
|
201
202
|
this.annotationText.length === 0 &&
|
|
202
203
|
(!isElementArray(this.annotation.span) ||
|
|
203
204
|
this.annotation.span.length === 1);
|
|
204
205
|
|
|
205
|
-
if (!isToDelete) {
|
|
206
|
-
const span = this.createSpan();
|
|
207
|
-
|
|
208
|
-
spans = [...annotation.span];
|
|
209
|
-
|
|
210
|
-
spans[index] = span;
|
|
211
|
-
|
|
212
|
-
if (this.annotationText.length === 0) {
|
|
213
|
-
spans.splice(index, 1);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
206
|
// API call handled in parent component - AnnotationRow
|
|
217
|
-
this.$emit("save-annotation-changes",
|
|
207
|
+
this.$emit("save-annotation-changes", isToDecline);
|
|
218
208
|
},
|
|
219
|
-
|
|
220
209
|
createSpan() {
|
|
210
|
+
if (this.annotationText.length === 0) return;
|
|
211
|
+
|
|
221
212
|
return {
|
|
222
213
|
offset_string: this.annotationText,
|
|
223
214
|
page_index: this.span.page_index,
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
:label="label"
|
|
57
57
|
:annotation-set="annotationSet"
|
|
58
58
|
:is-hovered="hoveredAnnotation"
|
|
59
|
-
@save-annotation-changes="
|
|
59
|
+
@save-annotation-changes="handleSaveChanges"
|
|
60
60
|
/>
|
|
61
61
|
</div>
|
|
62
62
|
</div>
|
|
@@ -196,7 +196,6 @@ export default {
|
|
|
196
196
|
this.isAnnotationInEditMode(this.annotationId())
|
|
197
197
|
);
|
|
198
198
|
},
|
|
199
|
-
|
|
200
199
|
isAnnotation() {
|
|
201
200
|
return (
|
|
202
201
|
this.annotation &&
|
|
@@ -286,7 +285,7 @@ export default {
|
|
|
286
285
|
this.isLoading = true;
|
|
287
286
|
}
|
|
288
287
|
},
|
|
289
|
-
spanSelection(newValue
|
|
288
|
+
spanSelection(newValue) {
|
|
290
289
|
// check if spanSelection has new value from entity selection
|
|
291
290
|
// to stop loading after the text appears in the field
|
|
292
291
|
if (newValue) {
|
|
@@ -412,7 +411,7 @@ export default {
|
|
|
412
411
|
}
|
|
413
412
|
},
|
|
414
413
|
showSaveButton() {
|
|
415
|
-
if (!this.editAnnotation || this.isLoading
|
|
414
|
+
if (!this.editAnnotation || this.isLoading) return;
|
|
416
415
|
|
|
417
416
|
// Check if it's an Annotation or Empty Annotation
|
|
418
417
|
if (this.isAnnotation) {
|
|
@@ -445,6 +444,7 @@ export default {
|
|
|
445
444
|
handleSaveChanges(decline) {
|
|
446
445
|
if (this.publicView || this.isDocumentReviewed) return;
|
|
447
446
|
|
|
447
|
+
// Verify if we are editing a filled or empty annotation
|
|
448
448
|
if (
|
|
449
449
|
this.annotation &&
|
|
450
450
|
(this.showAcceptButton() ||
|
|
@@ -454,14 +454,24 @@ export default {
|
|
|
454
454
|
this.editAnnotation.index
|
|
455
455
|
))
|
|
456
456
|
) {
|
|
457
|
-
// retrieve all edited spans from every AnnotationContent component
|
|
458
457
|
let spans = [];
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
458
|
+
|
|
459
|
+
if (!decline) {
|
|
460
|
+
Object.keys(this.$refs).forEach((ref) => {
|
|
461
|
+
if (ref.includes(`span_${this.annotation.id}`)) {
|
|
462
|
+
// call child component createSpan method
|
|
463
|
+
if (!this.$refs[ref][0]) return;
|
|
464
|
+
|
|
465
|
+
const span = this.$refs[ref][0].createSpan();
|
|
466
|
+
|
|
467
|
+
// only add span if it's not null (offset_string not empty)
|
|
468
|
+
if (span) {
|
|
469
|
+
spans.push(span);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
465
475
|
this.saveAnnotationChanges(spans, decline);
|
|
466
476
|
} else if (
|
|
467
477
|
!this.annotation &&
|
|
@@ -494,7 +504,7 @@ export default {
|
|
|
494
504
|
this.closedTag = null;
|
|
495
505
|
});
|
|
496
506
|
},
|
|
497
|
-
saveAnnotationChanges(spans,
|
|
507
|
+
saveAnnotationChanges(spans, isToDecline) {
|
|
498
508
|
// This function deals with declining Annotations
|
|
499
509
|
// or editing an Annotation or a part of it (if multi line)
|
|
500
510
|
this.isLoading = true;
|
|
@@ -503,7 +513,7 @@ export default {
|
|
|
503
513
|
let storeAction; // if it will be 'delete' or 'patch'
|
|
504
514
|
|
|
505
515
|
// Verify if we delete the entire Annotation or a part of the text
|
|
506
|
-
if (
|
|
516
|
+
if (isToDecline || spans.length === 0) {
|
|
507
517
|
storeAction = "document/deleteAnnotation";
|
|
508
518
|
} else {
|
|
509
519
|
// Editing the Annotation
|
|
@@ -246,12 +246,7 @@ export default {
|
|
|
246
246
|
);
|
|
247
247
|
},
|
|
248
248
|
|
|
249
|
-
...mapState("selection", [
|
|
250
|
-
"isSelecting",
|
|
251
|
-
"selectionFromBbox",
|
|
252
|
-
"spanSelection",
|
|
253
|
-
"selectedEntities",
|
|
254
|
-
]),
|
|
249
|
+
...mapState("selection", ["isSelecting", "selectedEntities"]),
|
|
255
250
|
...mapState("display", [
|
|
256
251
|
"scale",
|
|
257
252
|
"optimalScale",
|
|
@@ -416,6 +411,9 @@ export default {
|
|
|
416
411
|
ann.original.offset_string === entityToAdd.original.offset_string
|
|
417
412
|
);
|
|
418
413
|
|
|
414
|
+
// reset the selection so that we don't have a drawn rectangle when editing based on entities
|
|
415
|
+
this.endSelection();
|
|
416
|
+
|
|
419
417
|
if (found) {
|
|
420
418
|
this.newAnnotation = [
|
|
421
419
|
...this.newAnnotation.filter(
|
|
@@ -17,10 +17,8 @@
|
|
|
17
17
|
]"
|
|
18
18
|
>
|
|
19
19
|
<div
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
!previousDocument && 'navigation-disabled',
|
|
23
|
-
]"
|
|
20
|
+
v-if="previousDocument"
|
|
21
|
+
class="left-arrow navigation-arrow"
|
|
24
22
|
type="button"
|
|
25
23
|
@click="navigateToDocument(previousDocument)"
|
|
26
24
|
>
|
|
@@ -30,10 +28,8 @@
|
|
|
30
28
|
<DocumentName :data-file-name="selectedDocument.data_file_name" />
|
|
31
29
|
|
|
32
30
|
<div
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
!nextDocument && 'navigation-disabled',
|
|
36
|
-
]"
|
|
31
|
+
v-if="nextDocument"
|
|
32
|
+
class="right-arrow navigation-arrow"
|
|
37
33
|
type="button"
|
|
38
34
|
@click="navigateToDocument(nextDocument)"
|
|
39
35
|
>
|
package/src/store/selection.js
CHANGED
|
@@ -72,11 +72,18 @@ const actions = {
|
|
|
72
72
|
},
|
|
73
73
|
|
|
74
74
|
endSelection: ({ commit, state }, end) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
let xDiff;
|
|
76
|
+
let yDiff;
|
|
77
|
+
|
|
78
|
+
if (end) {
|
|
79
|
+
xDiff = Math.abs(state.selection.start.x - end.x);
|
|
80
|
+
yDiff = Math.abs(state.selection.start.y - end.y);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// if "end" is not provided, start and end points are the same, or if we have a selection smaller than 5x5,
|
|
78
84
|
// just reset
|
|
79
85
|
if (
|
|
86
|
+
!end ||
|
|
80
87
|
(yDiff <= 5 && xDiff <= 5) ||
|
|
81
88
|
(state.selection.start.x === end.x && state.selection.start.y == end.y)
|
|
82
89
|
) {
|
package/src/utils/utils.js
CHANGED