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