@konfuzio/document-validation-ui 0.1.11-dev.4 → 0.1.11-dev.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konfuzio/document-validation-ui",
3
- "version": "0.1.11-dev.4",
3
+ "version": "0.1.11-dev.6",
4
4
  "repository": "git://github.com:konfuzio-ai/document-validation-ui.git",
5
5
  "main": "dist/app.js",
6
6
  "scripts": {
@@ -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.
@@ -80,13 +81,6 @@ export default {
80
81
  isAnnotationBeingEdited() {
81
82
  return this.isAnnotationInEditMode(this.annotation.id, this.spanIndex);
82
83
  },
83
- annotationText() {
84
- if (this.isAnnotationBeingEdited) {
85
- return this.$refs.contentEditable.textContent.trim();
86
- } else {
87
- return this.span.offset_string;
88
- }
89
- },
90
84
  },
91
85
 
92
86
  watch: {
@@ -95,18 +89,33 @@ export default {
95
89
  // one was selected before so we set the state to the previous one (like a cancel)
96
90
 
97
91
  if (
92
+ !newAnnotation &&
98
93
  oldAnnotation &&
99
- oldAnnotation.id === this.annotation.id &&
100
- oldAnnotation.index === this.spanIndex
94
+ oldAnnotation.id === this.annotation.id
101
95
  ) {
102
96
  this.handleCancel(true);
97
+ } else if (
98
+ newAnnotation &&
99
+ oldAnnotation &&
100
+ newAnnotation.id === this.annotation.id &&
101
+ newAnnotation.id !== oldAnnotation.id
102
+ ) {
103
+ this.handleCancel();
103
104
  }
104
105
  },
106
+ span() {
107
+ // span content changed, ex. from click on entity
108
+ this.setText(this.span.offset_string);
109
+ },
105
110
  },
111
+
106
112
  methods: {
107
113
  setText(text) {
108
114
  this.$refs.contentEditable.textContent = text;
109
115
  },
116
+ getAnnotationText() {
117
+ return this.$refs.contentEditable.textContent.trim();
118
+ },
110
119
  handleEditAnnotation(event) {
111
120
  if (this.publicView || this.isDocumentReviewed) return;
112
121
 
@@ -187,39 +196,22 @@ export default {
187
196
  event.preventDefault();
188
197
  }
189
198
 
190
- let index;
191
- if (this.editAnnotation && this.editAnnotation.index) {
192
- index = this.editAnnotation.index;
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 =
201
- this.annotationText.length === 0 &&
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 =
202
+ this.getAnnotationText().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", spans, isToDelete);
207
+ this.$emit("save-annotation-changes", isToDecline);
218
208
  },
219
-
220
209
  createSpan() {
210
+ const annotationText = this.getAnnotationText();
211
+ if (!annotationText) return;
212
+
221
213
  return {
222
- offset_string: this.annotationText,
214
+ offset_string: annotationText,
223
215
  page_index: this.span.page_index,
224
216
  x0: this.span.x0,
225
217
  x1: this.span.x1,
@@ -56,7 +56,7 @@
56
56
  :label="label"
57
57
  :annotation-set="annotationSet"
58
58
  :is-hovered="hoveredAnnotation"
59
- @save-annotation-changes="saveAnnotationChanges"
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, oldValue) {
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 || !this.spanSelection) return;
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,25 @@ 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
- Object.keys(this.$refs).forEach((ref) => {
460
- if (ref.includes(`span_${this.annotation.id}`)) {
461
- // call child component createSpan method
462
- spans.push(this.$refs[ref][0].createSpan());
463
- }
464
- });
458
+
459
+ if (!decline) {
460
+ Object.keys(this.$refs).forEach((ref) => {
461
+ if (ref.includes(`span_${this.annotation.id}`)) {
462
+ const refElement = this.$refs[ref][0];
463
+ // call child component createSpan method
464
+ if (!refElement) return;
465
+
466
+ const span = refElement.createSpan();
467
+
468
+ // only add span if it's not null (offset_string not empty)
469
+ if (span) {
470
+ spans.push(span);
471
+ }
472
+ }
473
+ });
474
+ }
475
+
465
476
  this.saveAnnotationChanges(spans, decline);
466
477
  } else if (
467
478
  !this.annotation &&
@@ -494,7 +505,7 @@ export default {
494
505
  this.closedTag = null;
495
506
  });
496
507
  },
497
- saveAnnotationChanges(spans, isToDeleteOrDecline) {
508
+ saveAnnotationChanges(spans, isToDecline) {
498
509
  // This function deals with declining Annotations
499
510
  // or editing an Annotation or a part of it (if multi line)
500
511
  this.isLoading = true;
@@ -503,7 +514,7 @@ export default {
503
514
  let storeAction; // if it will be 'delete' or 'patch'
504
515
 
505
516
  // Verify if we delete the entire Annotation or a part of the text
506
- if (isToDeleteOrDecline) {
517
+ if (isToDecline || spans.length === 0) {
507
518
  storeAction = "document/deleteAnnotation";
508
519
  } else {
509
520
  // 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(
@@ -72,11 +72,18 @@ const actions = {
72
72
  },
73
73
 
74
74
  endSelection: ({ commit, state }, end) => {
75
- const xDiff = Math.abs(state.selection.start.x - end.x);
76
- const yDiff = Math.abs(state.selection.start.y - end.y);
77
- // if start and end points are the same, or if we have a selection smaller than 5x5,
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
  ) {