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.
package/dist/cjs/index.js CHANGED
@@ -10643,7 +10643,9 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10643
10643
  var store = _ref2.store,
10644
10644
  _onComplete = _ref2.onComplete,
10645
10645
  _ref2$enabled = _ref2.enabled,
10646
- enabled = _ref2$enabled === void 0 ? true : _ref2$enabled;
10646
+ enabled = _ref2$enabled === void 0 ? true : _ref2$enabled,
10647
+ _ref2$backTrigger = _ref2.backTrigger,
10648
+ backTrigger = _ref2$backTrigger === void 0 ? 0 : _ref2$backTrigger;
10647
10649
  // displayIndex counts how many fields have been answered (for step indicator only).
10648
10650
  // Navigation always uses fields[0] — the first remaining pending field.
10649
10651
  var _useState5 = React.useState(0),
@@ -10652,6 +10654,8 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10652
10654
  setDisplayIndex = _useState6[1];
10653
10655
  var initialTotalRef = React.useRef(0);
10654
10656
  var completedHistoryRef = React.useRef([]);
10657
+ var isGoingBackRef = React.useRef(false);
10658
+ var prevBackTriggerRef = React.useRef(backTrigger);
10655
10659
  var config = getInputFieldsConfig();
10656
10660
  var pendingFields = store._pendingInputFields || [];
10657
10661
 
@@ -10668,16 +10672,49 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10668
10672
  // Capture total and reset display counter when a fresh batch appears
10669
10673
  React.useEffect(function () {
10670
10674
  if (fields.length > 0 && initialTotalRef.current === 0) {
10671
- initialTotalRef.current = fields.length;
10672
- setDisplayIndex(0);
10673
- completedHistoryRef.current = [];
10675
+ if (isGoingBackRef.current) {
10676
+ // Back-from-summary restored a field — recover total from history + pending
10677
+ isGoingBackRef.current = false;
10678
+ initialTotalRef.current = completedHistoryRef.current.length + fields.length;
10679
+ } else {
10680
+ // Genuine fresh batch
10681
+ initialTotalRef.current = fields.length;
10682
+ setDisplayIndex(0);
10683
+ completedHistoryRef.current = [];
10684
+ }
10674
10685
  }
10675
10686
  if (fields.length === 0) {
10676
10687
  initialTotalRef.current = 0;
10677
- completedHistoryRef.current = [];
10688
+ // History is intentionally kept so back-from-summary can use it
10678
10689
  }
10679
10690
  }, [fields.length]);
10680
10691
  var totalCount = initialTotalRef.current || fields.length;
10692
+
10693
+ // Back-from-summary: triggered by parent incrementing backTrigger prop
10694
+ // Must be defined and its useEffect called BEFORE any early returns (Rules of Hooks)
10695
+ var handleBackFromSummary = function handleBackFromSummary() {
10696
+ var last = completedHistoryRef.current.pop();
10697
+ if (!last) return;
10698
+ var el = last.el,
10699
+ previousValue = last.previousValue;
10700
+ if (el) {
10701
+ var isImage = el.custom && el.custom.inputType === 'image';
10702
+ el.set(isImage ? {
10703
+ src: previousValue || ''
10704
+ } : {
10705
+ text: previousValue || ''
10706
+ });
10707
+ isGoingBackRef.current = true;
10708
+ store._unresolveInputField(el);
10709
+ }
10710
+ // displayIndex stays unchanged — it already points to the last step (N-1)
10711
+ };
10712
+ React.useEffect(function () {
10713
+ if (backTrigger !== prevBackTriggerRef.current) {
10714
+ prevBackTriggerRef.current = backTrigger;
10715
+ handleBackFromSummary();
10716
+ }
10717
+ }, [backTrigger]);
10681
10718
  if (!enabled || fields.length === 0) return null;
10682
10719
 
10683
10720
  // Always show the first remaining field — the array shrinks as fields are resolved
@@ -11106,7 +11143,9 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
11106
11143
  components = _ref6$components === void 0 ? {} : _ref6$components,
11107
11144
  _ref6$showInputFields = _ref6.showInputFieldsPopup,
11108
11145
  showInputFieldsPopup = _ref6$showInputFields === void 0 ? true : _ref6$showInputFields,
11109
- onInputFieldsComplete = _ref6.onInputFieldsComplete;
11146
+ onInputFieldsComplete = _ref6.onInputFieldsComplete,
11147
+ _ref6$backTrigger = _ref6.backTrigger,
11148
+ backTrigger = _ref6$backTrigger === void 0 ? 0 : _ref6$backTrigger;
11110
11149
  var stageRef = React.useRef(null);
11111
11150
  var containerRef = React.useRef(null);
11112
11151
  var _useState5 = React.useState({
@@ -11392,7 +11431,8 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
11392
11431
  }) : null, /*#__PURE__*/jsxRuntime.jsx(InputFieldsDialog, {
11393
11432
  store: store,
11394
11433
  enabled: showInputFieldsPopup,
11395
- onComplete: onInputFieldsComplete
11434
+ onComplete: onInputFieldsComplete,
11435
+ backTrigger: backTrigger
11396
11436
  })]
11397
11437
  });
11398
11438
  });