@searpent/react-image-annotate 2.1.0 → 2.1.2

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.
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
5
5
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
- import React, { useCallback, useEffect, useReducer, useRef } from "react";
6
+ import React, { useCallback, useEffect, useReducer } from "react";
7
7
  import makeImmutable, { without } from "seamless-immutable";
8
8
  import intersection from "lodash/intersection";
9
9
  import MainLayout from "../MainLayout";
@@ -145,28 +145,6 @@ export var Annotator = function Annotator(_ref) {
145
145
  var dispatch = useEventCallback(function (action) {
146
146
  if (action.type === "HEADER_BUTTON_CLICKED") {
147
147
  if (["Exit", "Done", "Save", "Complete"].includes(action.buttonName)) {
148
- var _state$images$state$s, _state$images$state$s2;
149
-
150
- // Before exiting, save current image if there are unsaved changes
151
- if (state.selectedImage !== undefined && ((_state$images$state$s = state.images[state.selectedImage]) === null || _state$images$state$s === void 0 ? void 0 : (_state$images$state$s2 = _state$images$state$s.saveableActions) === null || _state$images$state$s2 === void 0 ? void 0 : _state$images$state$s2.length) > 0) {
152
- var _currentImage$saveabl;
153
-
154
- var currentImage = state.images[state.selectedImage];
155
- var triggerRecalc = intersection(reacalcActionsEnum, currentImage.saveableActions).length > 0;
156
- var toSaveMetadata = [];
157
-
158
- if ((_currentImage$saveabl = currentImage.saveableActions) === null || _currentImage$saveabl === void 0 ? void 0 : _currentImage$saveabl.includes("UPDATE_ALBUM_METADATA")) {
159
- toSaveMetadata = state.albumMetadata;
160
- }
161
-
162
- dispatchToReducer({
163
- type: "SAVE_IMAGE",
164
- image: _objectSpread({}, currentImage),
165
- triggerRecalc: triggerRecalc,
166
- toSaveMetadata: toSaveMetadata
167
- });
168
- }
169
-
170
148
  return onExit(without(state, "history"));
171
149
  } else if (action.buttonName === "Next" && onNextImage) {
172
150
  return onNextImage(without(state, "history"));
@@ -299,77 +277,7 @@ export var Annotator = function Annotator(_ref) {
299
277
  toSaveMetadata = _state$toSaveImage.toSaveMetadata;
300
278
  saveHandler(image, triggerRecalc, toSaveMetadata);
301
279
  }
302
- }, [save, state.toSaveImage]); // Auto-save article metadata changes after a delay (debounced)
303
-
304
- var autoSaveTimeoutRef = useRef(null);
305
- var stateRef = useRef(state); // Keep stateRef in sync with state
306
-
307
- useEffect(function () {
308
- stateRef.current = state;
309
- }, [state]);
310
- useEffect(function () {
311
- var _state$lastAction, _state$lastAction2;
312
-
313
- // Only trigger on UPDATE_METADATA actions for article metadata (with groupId)
314
- if (((_state$lastAction = state.lastAction) === null || _state$lastAction === void 0 ? void 0 : _state$lastAction.type) === 'UPDATE_METADATA' && ((_state$lastAction2 = state.lastAction) === null || _state$lastAction2 === void 0 ? void 0 : _state$lastAction2.groupId)) {
315
- var _state$lastAction3 = state.lastAction,
316
- name = _state$lastAction3.name,
317
- value = _state$lastAction3.value,
318
- imageIndex = _state$lastAction3.imageIndex,
319
- groupId = _state$lastAction3.groupId; // Log the change
320
-
321
- if (name === 'articleType') {
322
- console.log("\u23F1\uFE0F [AUTO-SAVE] ArticleType changed to \"".concat(value, "\" for group ").concat(groupId, ". Auto-save will trigger in 1 second..."));
323
- } else {
324
- console.log("\u23F1\uFE0F [AUTO-SAVE] ".concat(name, " changed to \"").concat(value, "\" for group ").concat(groupId, ". Auto-save will trigger in 1 second..."));
325
- } // Clear any existing timeout
326
-
327
-
328
- if (autoSaveTimeoutRef.current) {
329
- clearTimeout(autoSaveTimeoutRef.current);
330
- console.log("\u23F1\uFE0F [AUTO-SAVE] Previous auto-save cancelled, restarting timer...");
331
- }
332
-
333
- if (imageIndex !== undefined) {
334
- // Debounce: wait 1 second after last change before saving
335
- autoSaveTimeoutRef.current = setTimeout(function () {
336
- var _latestState$images, _imageToSave$saveable;
337
-
338
- // Read latest state from ref
339
- var latestState = stateRef.current;
340
- var imageToSave = latestState === null || latestState === void 0 ? void 0 : (_latestState$images = latestState.images) === null || _latestState$images === void 0 ? void 0 : _latestState$images[imageIndex]; // Double-check that there are still unsaved changes and image exists
341
-
342
- if (imageToSave === null || imageToSave === void 0 ? void 0 : (_imageToSave$saveable = imageToSave.saveableActions) === null || _imageToSave$saveable === void 0 ? void 0 : _imageToSave$saveable.includes("UPDATE_METADATA")) {
343
- var _imageToSave$saveable2;
344
-
345
- console.log("\uD83D\uDCBE [AUTO-SAVE] Triggering auto-save for image ".concat(imageToSave.id, " (group ").concat(groupId, ")..."));
346
- var triggerRecalc = intersection(reacalcActionsEnum, imageToSave.saveableActions).length > 0;
347
- var toSaveMetadata = [];
348
-
349
- if ((_imageToSave$saveable2 = imageToSave.saveableActions) === null || _imageToSave$saveable2 === void 0 ? void 0 : _imageToSave$saveable2.includes("UPDATE_ALBUM_METADATA")) {
350
- toSaveMetadata = latestState.albumMetadata || [];
351
- }
352
-
353
- dispatchToReducer({
354
- type: "SAVE_IMAGE",
355
- image: _objectSpread({}, imageToSave),
356
- triggerRecalc: triggerRecalc,
357
- toSaveMetadata: toSaveMetadata
358
- });
359
- } else {
360
- console.log("\u26A0\uFE0F [AUTO-SAVE] Skipping auto-save - no unsaved changes for image ".concat(imageIndex));
361
- }
362
- }, 1000); // 1 second delay
363
- }
364
- } // Cleanup timeout on unmount or when dependencies change
365
-
366
-
367
- return function () {
368
- if (autoSaveTimeoutRef.current) {
369
- clearTimeout(autoSaveTimeoutRef.current);
370
- }
371
- };
372
- }, [state.lastAction, dispatchToReducer]); // polling of images
280
+ }, [save, state.toSaveImage]); // polling of images
373
281
 
374
282
  useEffect(function () {
375
283
  if (state.toPollImages.length > 0) {