labellife-design-tool 2.2.1 → 2.2.3

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
@@ -52,6 +52,7 @@ var ZoomOutIcon = require('@mui/icons-material/ZoomOut');
52
52
  var FitScreenIcon = require('@mui/icons-material/FitScreen');
53
53
  var reactKonva = require('react-konva');
54
54
  var Konva = require('konva');
55
+ var ArrowBackIcon = require('@mui/icons-material/ArrowBack');
55
56
 
56
57
  function _arrayLikeToArray(r, a) {
57
58
  (null == a || a > r.length) && (a = r.length);
@@ -1680,6 +1681,15 @@ var Store = mobxStateTree.types.model('Store', {
1680
1681
  return el.id !== id;
1681
1682
  });
1682
1683
  },
1684
+ _unresolveInputField: function _unresolveInputField(el) {
1685
+ // Re-insert at the front so it becomes the next field shown (back navigation)
1686
+ var alreadyPending = self._pendingInputFields.some(function (f) {
1687
+ return f.id === el.id;
1688
+ });
1689
+ if (!alreadyPending) {
1690
+ self._pendingInputFields.unshift(el);
1691
+ }
1692
+ },
1683
1693
  clearPendingInputFields: function clearPendingInputFields() {
1684
1694
  self._pendingInputFields = [];
1685
1695
  }
@@ -10253,6 +10263,8 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
10253
10263
  var field = _ref.field,
10254
10264
  onSubmit = _ref.onSubmit,
10255
10265
  onSkip = _ref.onSkip,
10266
+ onBack = _ref.onBack,
10267
+ canGoBack = _ref.canGoBack,
10256
10268
  currentIndex = _ref.currentIndex,
10257
10269
  totalCount = _ref.totalCount;
10258
10270
  var _useState = React.useState(''),
@@ -10561,7 +10573,26 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
10561
10573
  gap: 2,
10562
10574
  mt: 4.5
10563
10575
  },
10564
- children: [/*#__PURE__*/jsxRuntime.jsx(material.Button, {
10576
+ children: [canGoBack && /*#__PURE__*/jsxRuntime.jsx(material.Button, {
10577
+ variant: "outlined",
10578
+ onClick: onBack,
10579
+ startIcon: /*#__PURE__*/jsxRuntime.jsx(ArrowBackIcon, {}),
10580
+ sx: {
10581
+ textTransform: 'none',
10582
+ fontWeight: 500,
10583
+ fontSize: 21,
10584
+ px: 3,
10585
+ py: 1.65,
10586
+ borderRadius: '10px',
10587
+ color: '#555',
10588
+ borderColor: '#d0d5dd',
10589
+ '&:hover': {
10590
+ borderColor: '#aaa',
10591
+ backgroundColor: 'rgba(0,0,0,0.02)'
10592
+ }
10593
+ },
10594
+ children: t('inputFieldsDialog.back', 'Back')
10595
+ }), /*#__PURE__*/jsxRuntime.jsx(material.Button, {
10565
10596
  variant: "contained",
10566
10597
  onClick: handleSubmit,
10567
10598
  disabled: isRequired && !value,
@@ -10612,7 +10643,9 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10612
10643
  var store = _ref2.store,
10613
10644
  _onComplete = _ref2.onComplete,
10614
10645
  _ref2$enabled = _ref2.enabled,
10615
- 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;
10616
10649
  // displayIndex counts how many fields have been answered (for step indicator only).
10617
10650
  // Navigation always uses fields[0] — the first remaining pending field.
10618
10651
  var _useState5 = React.useState(0),
@@ -10620,6 +10653,9 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10620
10653
  displayIndex = _useState6[0],
10621
10654
  setDisplayIndex = _useState6[1];
10622
10655
  var initialTotalRef = React.useRef(0);
10656
+ var completedHistoryRef = React.useRef([]);
10657
+ var isGoingBackRef = React.useRef(false);
10658
+ var prevBackTriggerRef = React.useRef(backTrigger);
10623
10659
  var config = getInputFieldsConfig();
10624
10660
  var pendingFields = store._pendingInputFields || [];
10625
10661
 
@@ -10636,11 +10672,20 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10636
10672
  // Capture total and reset display counter when a fresh batch appears
10637
10673
  React.useEffect(function () {
10638
10674
  if (fields.length > 0 && initialTotalRef.current === 0) {
10639
- initialTotalRef.current = fields.length;
10640
- setDisplayIndex(0);
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
+ }
10641
10685
  }
10642
10686
  if (fields.length === 0) {
10643
10687
  initialTotalRef.current = 0;
10688
+ // History is intentionally kept so back-from-summary can use it
10644
10689
  }
10645
10690
  }, [fields.length]);
10646
10691
  var totalCount = initialTotalRef.current || fields.length;
@@ -10650,11 +10695,17 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10650
10695
  var currentField = fields[0];
10651
10696
  if (!currentField) return null;
10652
10697
 
10653
- // ── Shared submit / skip helpers ────────────────────────────────────
10698
+ // ── Shared submit / skip / back helpers ─────────────────────────────
10654
10699
  var handleSubmit = function handleSubmit(elementId, value) {
10655
10700
  var el = store.getElementById(elementId);
10701
+ var isImage = el && el.custom && el.custom.inputType === 'image';
10702
+ var previousValue = el ? isImage ? el.src : el.text : '';
10703
+ completedHistoryRef.current.push({
10704
+ el: el,
10705
+ previousValue: previousValue,
10706
+ skipped: false
10707
+ });
10656
10708
  if (el && el.set) {
10657
- var isImage = el.custom && el.custom.inputType === 'image';
10658
10709
  if (isImage) {
10659
10710
  el.set({
10660
10711
  src: String(value)
@@ -10676,6 +10727,14 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10676
10727
  }
10677
10728
  };
10678
10729
  var handleSkip = function handleSkip(elementId) {
10730
+ var el = store.getElementById(elementId);
10731
+ var isImage = el && el.custom && el.custom.inputType === 'image';
10732
+ var previousValue = el ? isImage ? el.src : el.text : '';
10733
+ completedHistoryRef.current.push({
10734
+ el: el,
10735
+ previousValue: previousValue,
10736
+ skipped: true
10737
+ });
10679
10738
  store._resolveInputField(elementId);
10680
10739
  if (fields.length <= 1) {
10681
10740
  if (_onComplete) _onComplete();
@@ -10685,6 +10744,50 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10685
10744
  });
10686
10745
  }
10687
10746
  };
10747
+ var handleBack = function handleBack() {
10748
+ var last = completedHistoryRef.current.pop();
10749
+ if (!last) return;
10750
+ var el = last.el,
10751
+ previousValue = last.previousValue;
10752
+ if (el) {
10753
+ var isImage = el.custom && el.custom.inputType === 'image';
10754
+ el.set(isImage ? {
10755
+ src: previousValue || ''
10756
+ } : {
10757
+ text: previousValue || ''
10758
+ });
10759
+ store._unresolveInputField(el);
10760
+ }
10761
+ setDisplayIndex(function (prev) {
10762
+ return Math.max(0, prev - 1);
10763
+ });
10764
+ };
10765
+ var canGoBack = displayIndex > 0;
10766
+
10767
+ // Back-from-summary: triggered by parent incrementing backTrigger prop
10768
+ var handleBackFromSummary = function handleBackFromSummary() {
10769
+ var last = completedHistoryRef.current.pop();
10770
+ if (!last) return;
10771
+ var el = last.el,
10772
+ previousValue = last.previousValue;
10773
+ if (el) {
10774
+ var isImage = el.custom && el.custom.inputType === 'image';
10775
+ el.set(isImage ? {
10776
+ src: previousValue || ''
10777
+ } : {
10778
+ text: previousValue || ''
10779
+ });
10780
+ isGoingBackRef.current = true;
10781
+ store._unresolveInputField(el);
10782
+ }
10783
+ // displayIndex stays unchanged — it already points to the last step (N-1)
10784
+ };
10785
+ React.useEffect(function () {
10786
+ if (backTrigger !== prevBackTriggerRef.current) {
10787
+ prevBackTriggerRef.current = backTrigger;
10788
+ handleBackFromSummary();
10789
+ }
10790
+ }, [backTrigger]);
10688
10791
 
10689
10792
  // ── Resolve which dialog component to use ───────────────────────────
10690
10793
  // Priority: per-type custom dialog > global CustomDialog > built-in
@@ -10706,6 +10809,8 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10706
10809
  totalCount: totalCount,
10707
10810
  onSubmit: handleSubmit,
10708
10811
  onSkip: handleSkip,
10812
+ onBack: handleBack,
10813
+ canGoBack: canGoBack,
10709
10814
  onComplete: function onComplete() {
10710
10815
  store.history.addUndoState();
10711
10816
  if (_onComplete) _onComplete();
@@ -10716,6 +10821,8 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
10716
10821
  field: currentField,
10717
10822
  onSubmit: handleSubmit,
10718
10823
  onSkip: handleSkip,
10824
+ onBack: handleBack,
10825
+ canGoBack: canGoBack,
10719
10826
  currentIndex: displayIndex,
10720
10827
  totalCount: totalCount
10721
10828
  });
@@ -11035,7 +11142,9 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
11035
11142
  components = _ref6$components === void 0 ? {} : _ref6$components,
11036
11143
  _ref6$showInputFields = _ref6.showInputFieldsPopup,
11037
11144
  showInputFieldsPopup = _ref6$showInputFields === void 0 ? true : _ref6$showInputFields,
11038
- onInputFieldsComplete = _ref6.onInputFieldsComplete;
11145
+ onInputFieldsComplete = _ref6.onInputFieldsComplete,
11146
+ _ref6$backTrigger = _ref6.backTrigger,
11147
+ backTrigger = _ref6$backTrigger === void 0 ? 0 : _ref6$backTrigger;
11039
11148
  var stageRef = React.useRef(null);
11040
11149
  var containerRef = React.useRef(null);
11041
11150
  var _useState5 = React.useState({
@@ -11321,7 +11430,8 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
11321
11430
  }) : null, /*#__PURE__*/jsxRuntime.jsx(InputFieldsDialog, {
11322
11431
  store: store,
11323
11432
  enabled: showInputFieldsPopup,
11324
- onComplete: onInputFieldsComplete
11433
+ onComplete: onInputFieldsComplete,
11434
+ backTrigger: backTrigger
11325
11435
  })]
11326
11436
  });
11327
11437
  });