@searpent/react-image-annotate 2.3.3 → 2.3.4
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/Annotator/examplePhotos.js +2 -2
- package/Annotator/index.js +31 -1
- package/package.json +1 -1
|
@@ -750,7 +750,7 @@ var examplePhotos = [{
|
|
|
750
750
|
"Y1": 0,
|
|
751
751
|
"Y2": 1
|
|
752
752
|
},
|
|
753
|
-
"text": "[{\"key\":\"articleType\",\"value\":\"news\"}, {\"key\":\"section\",\"value\":\"editorial\"}]",
|
|
753
|
+
"text": "[{\"key\":\"articleType\",\"value\":\"news\"}, {\"key\":\"previousArticleId\",\"value\":\"prev-article-1\"}, {\"key\":\"section\",\"value\":\"editorial\"}]",
|
|
754
754
|
"groupId": "42ba09e0-b2f5-439d-bdae-201e7c37787b",
|
|
755
755
|
"id": "aba453dd-f870-4510-ae40-a19eb52eb7d6"
|
|
756
756
|
}, {
|
|
@@ -762,7 +762,7 @@ var examplePhotos = [{
|
|
|
762
762
|
"Y1": 0,
|
|
763
763
|
"Y2": 1
|
|
764
764
|
},
|
|
765
|
-
"text": "[{\"key\":\"articleType\",\"value\":\"ads\"}, {\"key\":\"section\",\"value\":\"last page\"}]",
|
|
765
|
+
"text": "[{\"key\":\"articleType\",\"value\":\"ads\"}, {\"key\":\"previousArticleId\",\"value\":\"prev-article-2\"}, {\"key\":\"section\",\"value\":\"last page\"}]",
|
|
766
766
|
"groupId": "1",
|
|
767
767
|
"id": "2615bf87-7247-4bde-a0f9-45413034a6a6"
|
|
768
768
|
}]
|
package/Annotator/index.js
CHANGED
|
@@ -213,7 +213,37 @@ export var Annotator = function Annotator(_ref) {
|
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
-
}, [state.previouslySelectedImage, state.selectedImage, state.images, state, save]); //
|
|
216
|
+
}, [state.previouslySelectedImage, state.selectedImage, state.images, state, save]); // Automatically save image shortly after specific metadata fields change
|
|
217
|
+
// (ArticleType, PreviousArticleId), but debounce so we don't save on every keystroke.
|
|
218
|
+
|
|
219
|
+
useEffect(function () {
|
|
220
|
+
var _state$images;
|
|
221
|
+
|
|
222
|
+
var lastAction = state.lastAction;
|
|
223
|
+
|
|
224
|
+
if (!lastAction || lastAction.type !== "UPDATE_METADATA" || lastAction.name !== "articleType" && lastAction.name !== "previousArticleId" || isNaN(lastAction.imageIndex)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var imageIndex = lastAction.imageIndex;
|
|
229
|
+
var image = (_state$images = state.images) === null || _state$images === void 0 ? void 0 : _state$images[imageIndex];
|
|
230
|
+
if (!image) return;
|
|
231
|
+
var timeoutId = setTimeout(function () {
|
|
232
|
+
var _state$images2;
|
|
233
|
+
|
|
234
|
+
var latestImage = (_state$images2 = state.images) === null || _state$images2 === void 0 ? void 0 : _state$images2[imageIndex];
|
|
235
|
+
if (!latestImage) return;
|
|
236
|
+
dispatchToReducer({
|
|
237
|
+
type: "SAVE_IMAGE",
|
|
238
|
+
image: _objectSpread({}, latestImage),
|
|
239
|
+
triggerRecalc: false,
|
|
240
|
+
toSaveMetadata: []
|
|
241
|
+
});
|
|
242
|
+
}, 800);
|
|
243
|
+
return function () {
|
|
244
|
+
clearTimeout(timeoutId);
|
|
245
|
+
};
|
|
246
|
+
}, [state.lastAction, state.images]); // handle save of image
|
|
217
247
|
|
|
218
248
|
useEffect(function () {
|
|
219
249
|
if (state.toSaveImage !== null) {
|