@searpent/react-image-annotate 2.0.46 → 2.0.48

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.
@@ -686,55 +686,20 @@ var examplePhotos = [{
686
686
  "text": "[{\"label\":\"author\",\"text\":\"MET\"}]",
687
687
  "groupId": "5",
688
688
  "id": "346807506053365764"
689
- }, {
690
- "label": "title",
691
- "score": 0.99,
692
- "box": {
693
- "X1": 0.7056229,
694
- "X2": 0.9718065,
695
- "Y1": 0.049599823,
696
- "Y2": 0.18825386
697
- },
698
- "text": "[{\"label\":\"title\",\"text\":\"Za lidská práva! Vadí Čína i Katar\"}]",
699
- "groupId": "6",
700
- "id": "346807506909003776"
701
- }, {
702
- "label": "text",
703
- "score": 0.99,
704
- "box": {
705
- "X1": 0.70483536,
706
- "X2": 0.7946133,
707
- "Y1": 0.1657085,
708
- "Y2": 0.53319806
709
- },
710
- "text": "[{\"label\":\"text\",\"text\":\"\"}]",
711
- "groupId": "6",
712
- "id": "346807506909003777"
713
- }, {
714
- "label": "text",
715
- "score": 0.99,
716
- "box": {
717
- "X1": 0.7985509,
718
- "X2": 0.8875413,
719
- "Y1": 0.33028972,
720
- "Y2": 0.53432536
721
- },
722
- "text": "[{\"label\":\"text\",\"text\":\"\"}]",
723
- "groupId": "6",
724
- "id": "346807506909003778"
725
- }, {
726
- "label": "text",
727
- "score": 0.99,
728
- "box": {
729
- "X1": 0.89147896,
730
- "X2": 0.98046935,
731
- "Y1": 0.33028972,
732
- "Y2": 0.53432536
733
- },
734
- "text": "[{\"label\":\"text\",\"text\":\"\"}]",
735
- "groupId": "6",
736
- "id": "346807506913198080"
737
- }, {
689
+ }, // {
690
+ // "label": "title",
691
+ // "score": 0.99,
692
+ // "box": {
693
+ // "X1": 0.7056229,
694
+ // "X2": 0.9718065,
695
+ // "Y1": 0.049599823,
696
+ // "Y2": 0.18825386
697
+ // },
698
+ // "text": "[{\"label\":\"title\",\"text\":\"Za lidská práva! Vadí Čína i Katar\"}]",
699
+ // "groupId": "6",
700
+ // "id": "346807506909003776"
701
+ // },
702
+ {
738
703
  "label": "photo_caption",
739
704
  "score": 0.99,
740
705
  "box": {
@@ -743,33 +708,35 @@ var examplePhotos = [{
743
708
  "Y1": 0.25025365,
744
709
  "Y2": 0.3415624
745
710
  },
746
- "text": "[{\"label\":\"photo_caption\",\"text\":\"Protest z února v Indii proti konání ZOH v Pekingu\"}]",
747
- "groupId": "6",
748
- "id": "346807506913198081"
749
- }, {
750
- "label": "photo_caption",
751
- "score": 0.99,
752
- "box": {
753
- "X1": 0.80248857,
754
- "X2": 0.95999366,
755
- "Y1": 0.32127157,
756
- "Y2": 0.34381694
757
- },
758
- "text": "[{\"label\":\"photo_caption\",\"text\":\"Protest z února v Indii proti konání ZOH v Pekingu\"}]",
759
- "groupId": "6",
760
- "id": "346807506913198082"
761
- }, {
762
- "label": "author",
763
- "score": 0.99,
764
- "box": {
765
- "X1": 0.9584186,
766
- "X2": 0.9733816,
767
- "Y1": 0.51628906,
768
- "Y2": 0.53319806
769
- },
770
- "text": "[{\"label\":\"author\",\"text\":\"PUR\"}]",
711
+ "text": "[{\"label\":\"photo_caption\",\"text\":\"Protest n z února v Indii,\\n\\tpred proti v Pekingu.\"}]",
771
712
  "groupId": "6",
772
- "id": "346807506913198083"
713
+ "id": "346807506913198081" // {
714
+ // "label": "photo_caption",
715
+ // "score": 0.99,
716
+ // "box": {
717
+ // "X1": 0.80248857,
718
+ // "X2": 0.95999366,
719
+ // "Y1": 0.32127157,
720
+ // "Y2": 0.34381694
721
+ // },
722
+ // "text": "[{\"label\":\"photo_caption\",\"text\":\"Protest z února v Indii proti konání ZOH v Pekingu\"}]",
723
+ // "groupId": "6",
724
+ // "id": "346807506913198082"
725
+ // },
726
+ // {
727
+ // "label": "author",
728
+ // "score": 0.99,
729
+ // "box": {
730
+ // "X1": 0.9584186,
731
+ // "X2": 0.9733816,
732
+ // "Y1": 0.51628906,
733
+ // "Y2": 0.53319806
734
+ // },
735
+ // "text": "[{\"label\":\"author\",\"text\":\"PUR\"}]",
736
+ // "groupId": "6",
737
+ // "id": "346807506913198083"
738
+ // }
739
+
773
740
  }]
774
741
  }, {
775
742
  "modelFamily": "metadata-engine",
@@ -76,6 +76,7 @@ export var Annotator = function Annotator(_ref) {
76
76
  groupColors = _ref.groupColors,
77
77
  onRecalc = _ref.onRecalc,
78
78
  onSave = _ref.onSave,
79
+ onSelectedImageChange = _ref.onSelectedImageChange,
79
80
  albumMetadata = _ref.albumMetadata,
80
81
  metadataConfigs = _ref.metadataConfigs,
81
82
  _ref$lockedImages = _ref.lockedImages,
@@ -254,9 +255,25 @@ export var Annotator = function Annotator(_ref) {
254
255
  type: "ADD_GROUP",
255
256
  group: group
256
257
  });
257
- }; // trigger this on every BBox manipulation (there is currently no way to detect adding of new box!)
258
+ }; // trigger onSelectedImageChange() hook when image changed
258
259
 
259
260
 
261
+ useEffect(function () {
262
+ var _state$lastAction;
263
+
264
+ var createdAt = new Date();
265
+
266
+ if (typeof onSelectedImageChange === 'function' && ((_state$lastAction = state.lastAction) === null || _state$lastAction === void 0 ? void 0 : _state$lastAction.type) === 'SELECT_IMAGE' && (state === null || state === void 0 ? void 0 : state.selectedImage) !== state.previouslySelectedImage) {
267
+ onSelectedImageChange({
268
+ selectedImage: state === null || state === void 0 ? void 0 : state.selectedImage,
269
+ previouslySelectedImage: state.previouslySelectedImage,
270
+ images: state.images,
271
+ albumMetadata: state.albumMetadata,
272
+ createdAt: createdAt
273
+ });
274
+ }
275
+ }, [state.previouslySelectedImage, state.selectedImage, onSelectedImageChange, state.images, state.albumMetadata, state]); // trigger this on every BBox manipulation (there is currently no way to detect adding of new box!)
276
+
260
277
  useEffect(function () {
261
278
  if (!state.lastAction || !["BEGIN_BOX_TRANSFORM", "CHANGE_REGION", "DELETE_REGION", "DELETE_SELECTED_REGION", "UPDATE_METADATA", "SELECT_CLASSIFICATION"].includes(state.lastAction.type)) {
262
279
  return;
@@ -114,6 +114,7 @@ export default (function (state, action) {
114
114
  src = _ref.src,
115
115
  frameTime = _ref.frameTime;
116
116
 
117
+ state = setIn(state, ["previouslySelectedImage"], state.selectedImage);
117
118
  return setIn(setIn(state, ["selectedImage"], index), ["selectedImageFrameTime"], frameTime);
118
119
  };
119
120
 
@@ -4,9 +4,26 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  /**
5
5
  * Build styles
6
6
  */
7
- import './annotation.css'; // Possible classes
7
+ import './annotation.css';
8
+
9
+ function whitespaceCharactersToHTML() {
10
+ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
11
+ return str // new line whitespace
12
+ .replaceAll(/[ ]\n[ ]/gm, '&nbsp;<br>&nbsp;') // space both sides adds &nbsp;
13
+ .replaceAll(/\n[ ]/gm, '<br>&nbsp;') // space right side adds &nbsp;
14
+ .replaceAll(/[ ]\n/gm, '&nbsp;<br>') // space left side adds &nbsp;
15
+ .replaceAll(/\n/gm, '<br>') // no spaces
16
+ // tab whitespace
17
+ .replaceAll(/\t/gm, '&nbsp;&nbsp;&nbsp;&nbsp;'); // no spaces
18
+ }
19
+
20
+ function HTMLToWhitespaceCharacters() {
21
+ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
22
+ return str.replaceAll(/((&nbsp;|\s){4})/gm, '\t').replaceAll('&nbsp;', ' ').replaceAll('<br>', '\n'); // new line whitespace
23
+ } // Possible classes
8
24
  // ================
9
25
 
26
+
10
27
  var Annotation =
11
28
  /*#__PURE__*/
12
29
  function () {
@@ -92,7 +109,7 @@ function () {
92
109
  data = {};
93
110
  }
94
111
 
95
- newData.text = data.text || '';
112
+ newData.text = whitespaceCharactersToHTML(data.text);
96
113
  newData.labelName = data.labelName || this.defaultLabel.labelName;
97
114
  return newData;
98
115
  }
@@ -234,7 +251,7 @@ function () {
234
251
  key: "save",
235
252
  value: function save(toolsContent) {
236
253
  return {
237
- text: toolsContent.innerHTML,
254
+ text: HTMLToWhitespaceCharacters(toolsContent.innerHTML),
238
255
  labelName: this.currentLabel.labelName
239
256
  };
240
257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searpent/react-image-annotate",
3
- "version": "2.0.46",
3
+ "version": "2.0.48",
4
4
  "dependencies": {
5
5
  "@editorjs/editorjs": "^2.25.0",
6
6
  "@editorjs/paragraph": "^2.8.0",