labellife-design-tool 2.2.2 → 2.2.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.
@@ -2051,7 +2051,9 @@ var InputFieldsDialog = observer(function (_ref2) {
2051
2051
  var store = _ref2.store,
2052
2052
  _onComplete = _ref2.onComplete,
2053
2053
  _ref2$enabled = _ref2.enabled,
2054
- enabled = _ref2$enabled === void 0 ? true : _ref2$enabled;
2054
+ enabled = _ref2$enabled === void 0 ? true : _ref2$enabled,
2055
+ _ref2$backTrigger = _ref2.backTrigger,
2056
+ backTrigger = _ref2$backTrigger === void 0 ? 0 : _ref2$backTrigger;
2055
2057
  // displayIndex counts how many fields have been answered (for step indicator only).
2056
2058
  // Navigation always uses fields[0] — the first remaining pending field.
2057
2059
  var _useState5 = useState(0),
@@ -2060,6 +2062,8 @@ var InputFieldsDialog = observer(function (_ref2) {
2060
2062
  setDisplayIndex = _useState6[1];
2061
2063
  var initialTotalRef = useRef(0);
2062
2064
  var completedHistoryRef = useRef([]);
2065
+ var isGoingBackRef = useRef(false);
2066
+ var prevBackTriggerRef = useRef(backTrigger);
2063
2067
  var config = getInputFieldsConfig();
2064
2068
  var pendingFields = store._pendingInputFields || [];
2065
2069
 
@@ -2076,16 +2080,49 @@ var InputFieldsDialog = observer(function (_ref2) {
2076
2080
  // Capture total and reset display counter when a fresh batch appears
2077
2081
  useEffect(function () {
2078
2082
  if (fields.length > 0 && initialTotalRef.current === 0) {
2079
- initialTotalRef.current = fields.length;
2080
- setDisplayIndex(0);
2081
- completedHistoryRef.current = [];
2083
+ if (isGoingBackRef.current) {
2084
+ // Back-from-summary restored a field — recover total from history + pending
2085
+ isGoingBackRef.current = false;
2086
+ initialTotalRef.current = completedHistoryRef.current.length + fields.length;
2087
+ } else {
2088
+ // Genuine fresh batch
2089
+ initialTotalRef.current = fields.length;
2090
+ setDisplayIndex(0);
2091
+ completedHistoryRef.current = [];
2092
+ }
2082
2093
  }
2083
2094
  if (fields.length === 0) {
2084
2095
  initialTotalRef.current = 0;
2085
- completedHistoryRef.current = [];
2096
+ // History is intentionally kept so back-from-summary can use it
2086
2097
  }
2087
2098
  }, [fields.length]);
2088
2099
  var totalCount = initialTotalRef.current || fields.length;
2100
+
2101
+ // Back-from-summary: triggered by parent incrementing backTrigger prop
2102
+ // Must be defined and its useEffect called BEFORE any early returns (Rules of Hooks)
2103
+ var handleBackFromSummary = function handleBackFromSummary() {
2104
+ var last = completedHistoryRef.current.pop();
2105
+ if (!last) return;
2106
+ var el = last.el,
2107
+ previousValue = last.previousValue;
2108
+ if (el) {
2109
+ var isImage = el.custom && el.custom.inputType === 'image';
2110
+ el.set(isImage ? {
2111
+ src: previousValue || ''
2112
+ } : {
2113
+ text: previousValue || ''
2114
+ });
2115
+ isGoingBackRef.current = true;
2116
+ store._unresolveInputField(el);
2117
+ }
2118
+ // displayIndex stays unchanged — it already points to the last step (N-1)
2119
+ };
2120
+ useEffect(function () {
2121
+ if (backTrigger !== prevBackTriggerRef.current) {
2122
+ prevBackTriggerRef.current = backTrigger;
2123
+ handleBackFromSummary();
2124
+ }
2125
+ }, [backTrigger]);
2089
2126
  if (!enabled || fields.length === 0) return null;
2090
2127
 
2091
2128
  // Always show the first remaining field — the array shrinks as fields are resolved
@@ -2514,7 +2551,9 @@ var Workspace = observer(function (_ref6) {
2514
2551
  components = _ref6$components === void 0 ? {} : _ref6$components,
2515
2552
  _ref6$showInputFields = _ref6.showInputFieldsPopup,
2516
2553
  showInputFieldsPopup = _ref6$showInputFields === void 0 ? true : _ref6$showInputFields,
2517
- onInputFieldsComplete = _ref6.onInputFieldsComplete;
2554
+ onInputFieldsComplete = _ref6.onInputFieldsComplete,
2555
+ _ref6$backTrigger = _ref6.backTrigger,
2556
+ backTrigger = _ref6$backTrigger === void 0 ? 0 : _ref6$backTrigger;
2518
2557
  var stageRef = useRef(null);
2519
2558
  var containerRef = useRef(null);
2520
2559
  var _useState5 = useState({
@@ -2800,7 +2839,8 @@ var Workspace = observer(function (_ref6) {
2800
2839
  }) : null, /*#__PURE__*/jsx(InputFieldsDialog, {
2801
2840
  store: store,
2802
2841
  enabled: showInputFieldsPopup,
2803
- onComplete: onInputFieldsComplete
2842
+ onComplete: onInputFieldsComplete,
2843
+ backTrigger: backTrigger
2804
2844
  })]
2805
2845
  });
2806
2846
  });