grommet 2.57.0 → 2.58.0

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.
Files changed (124) hide show
  1. package/components/Box/StyledBox.js +1 -1
  2. package/components/Box/stories/ColorContrast.stories.js +36 -0
  3. package/components/Button/BusyAnimation.js +7 -1
  4. package/components/Button/Button.js +12 -3
  5. package/components/DataTable/StyledDataTable.js +1 -1
  6. package/components/DateInput/DateInput.js +3 -3
  7. package/components/DateTimeInput/DateTimeInput.js +17 -11
  8. package/components/FocusedContainer.js +2 -1
  9. package/components/FormField/FormField.js +31 -10
  10. package/components/FormField/FormFieldContext.js +12 -0
  11. package/components/Grommet/Grommet.js +4 -1
  12. package/components/Grommet/StyledGrommet.js +3 -3
  13. package/components/Grommet/index.d.ts +6 -0
  14. package/components/Grommet/propTypes.js +2 -0
  15. package/components/Menu/Menu.js +1 -1
  16. package/components/Select/SelectContainer.js +2 -2
  17. package/components/Select/StyledSelect.js +3 -1
  18. package/components/TextArea/StyledTextArea.js +3 -1
  19. package/components/TextInput/CopyButton.js +23 -6
  20. package/components/TextInput/StyledTextInput.js +19 -25
  21. package/components/TextInput/TextInput.js +75 -28
  22. package/components/TextInput/index.d.ts +12 -3
  23. package/components/TextInput/propTypes.js +2 -0
  24. package/components/TextInput/stories/Copy.stories.tsx +42 -0
  25. package/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  26. package/components/TimeInput/README.md +24 -1
  27. package/components/TimeInput/StyledTimeInput.js +91 -27
  28. package/components/TimeInput/TimeInput.js +185 -120
  29. package/components/TimeInput/TimeInputPopup.js +114 -117
  30. package/components/TimeInput/index.d.ts +2 -0
  31. package/components/TimeInput/propTypes.js +2 -0
  32. package/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  33. package/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  34. package/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  35. package/components/TimeInput/stories/Form.stories.tsx +1 -0
  36. package/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  37. package/components/TimeInput/useSectionedTimeField.js +2 -2
  38. package/components/TimeInput/utils.js +13 -62
  39. package/components/Wizard/Wizard.js +396 -210
  40. package/components/Wizard/WizardContent.js +61 -35
  41. package/components/Wizard/WizardContext.js +3 -0
  42. package/components/Wizard/WizardFooter.js +14 -15
  43. package/components/Wizard/WizardHeader.js +12 -7
  44. package/components/Wizard/WizardProgress.js +27 -2
  45. package/components/Wizard/index.d.ts +35 -4
  46. package/components/Wizard/propTypes.js +6 -1
  47. package/components/Wizard/stories/BasicLinear.stories.js +12 -10
  48. package/components/Wizard/stories/ClickableSteps.stories.js +104 -0
  49. package/components/Wizard/stories/ExternalForm.stories.js +114 -0
  50. package/components/Wizard/stories/NonClosableHeader.stories.js +68 -0
  51. package/components/Wizard/stories/Validation.stories.js +18 -8
  52. package/es6/components/Box/StyledBox.js +1 -1
  53. package/es6/components/Box/stories/ColorContrast.stories.js +31 -0
  54. package/es6/components/Button/BusyAnimation.js +7 -1
  55. package/es6/components/Button/Button.js +12 -3
  56. package/es6/components/DataTable/StyledDataTable.js +2 -2
  57. package/es6/components/DateInput/DateInput.js +3 -3
  58. package/es6/components/DateTimeInput/DateTimeInput.js +17 -11
  59. package/es6/components/FocusedContainer.js +2 -1
  60. package/es6/components/FormField/FormField.js +31 -10
  61. package/es6/components/FormField/FormFieldContext.js +7 -0
  62. package/es6/components/Grommet/Grommet.js +4 -1
  63. package/es6/components/Grommet/StyledGrommet.js +4 -4
  64. package/es6/components/Grommet/index.d.ts +6 -0
  65. package/es6/components/Grommet/propTypes.js +2 -0
  66. package/es6/components/Menu/Menu.js +1 -1
  67. package/es6/components/Select/SelectContainer.js +2 -2
  68. package/es6/components/Select/StyledSelect.js +4 -2
  69. package/es6/components/TextArea/StyledTextArea.js +4 -2
  70. package/es6/components/TextInput/CopyButton.js +22 -6
  71. package/es6/components/TextInput/StyledTextInput.js +20 -26
  72. package/es6/components/TextInput/TextInput.js +76 -29
  73. package/es6/components/TextInput/index.d.ts +12 -3
  74. package/es6/components/TextInput/propTypes.js +2 -0
  75. package/es6/components/TextInput/stories/Copy.stories.tsx +42 -0
  76. package/es6/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  77. package/es6/components/TimeInput/README.md +24 -1
  78. package/es6/components/TimeInput/StyledTimeInput.js +92 -28
  79. package/es6/components/TimeInput/TimeInput.js +187 -122
  80. package/es6/components/TimeInput/TimeInputPopup.js +115 -118
  81. package/es6/components/TimeInput/index.d.ts +2 -0
  82. package/es6/components/TimeInput/propTypes.js +2 -0
  83. package/es6/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  84. package/es6/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  85. package/es6/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  86. package/es6/components/TimeInput/stories/Form.stories.tsx +1 -0
  87. package/es6/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  88. package/es6/components/TimeInput/useSectionedTimeField.js +2 -2
  89. package/es6/components/TimeInput/utils.js +12 -61
  90. package/es6/components/Wizard/Wizard.js +397 -211
  91. package/es6/components/Wizard/WizardContent.js +62 -36
  92. package/es6/components/Wizard/WizardContext.js +3 -0
  93. package/es6/components/Wizard/WizardFooter.js +14 -15
  94. package/es6/components/Wizard/WizardHeader.js +12 -7
  95. package/es6/components/Wizard/WizardProgress.js +27 -2
  96. package/es6/components/Wizard/index.d.ts +35 -4
  97. package/es6/components/Wizard/propTypes.js +6 -1
  98. package/es6/components/Wizard/stories/BasicLinear.stories.js +11 -11
  99. package/es6/components/Wizard/stories/ClickableSteps.stories.js +99 -0
  100. package/es6/components/Wizard/stories/ExternalForm.stories.js +111 -0
  101. package/es6/components/Wizard/stories/NonClosableHeader.stories.js +63 -0
  102. package/es6/components/Wizard/stories/Validation.stories.js +18 -9
  103. package/es6/languages/default.json +2 -0
  104. package/es6/themes/base.d.ts +79 -59
  105. package/es6/themes/base.js +65 -34
  106. package/es6/utils/DOM.js +10 -7
  107. package/es6/utils/background.js +9 -7
  108. package/es6/utils/colors.js +84 -12
  109. package/es6/utils/legacyColorIsDark.js +17 -0
  110. package/es6/utils/styles.js +13 -5
  111. package/grommet.min.js +1 -1
  112. package/grommet.min.js.map +1 -1
  113. package/languages/default.json +2 -0
  114. package/package.json +3 -3
  115. package/themes/base.d.ts +79 -59
  116. package/themes/base.js +65 -34
  117. package/tools/draft-release-version-pr.js +1 -0
  118. package/tools/generate-release-notes.js +1 -1
  119. package/tools/release-notes-utils.js +1 -0
  120. package/utils/DOM.js +10 -7
  121. package/utils/background.js +9 -7
  122. package/utils/colors.js +84 -12
  123. package/utils/legacyColorIsDark.js +21 -0
  124. package/utils/styles.js +14 -6
@@ -17,13 +17,14 @@ var _WizardStepHeader = require("./WizardStepHeader");
17
17
  var _WizardContent = require("./WizardContent");
18
18
  var _WizardFooter = require("./WizardFooter");
19
19
  var _propTypes = require("./propTypes");
20
- var _excluded = ["steps", "currentStep", "defaultStep", "showProgress", "onStepChange", "onComplete", "onCancel", "renderStep", "title", "footer", "scrollToTop", "value", "defaultValue", "onChange", "id", "aria-label", "messages", "children"];
20
+ var _excluded = ["children"],
21
+ _excluded2 = ["steps", "clickableSteps", "closable", "currentStep", "defaultStep", "form", "showProgress", "onStepChange", "onComplete", "onCancel", "renderStep", "title", "footer", "scrollToTop", "value", "defaultValue", "onChange", "id", "aria-label", "messages", "children"];
21
22
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
22
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
23
23
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
24
24
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
25
25
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
26
26
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
27
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
27
28
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
28
29
  function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
29
30
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -46,20 +47,74 @@ var flattenLeaves = function flattenLeaves(steps) {
46
47
  };
47
48
 
48
49
  // Find step by id in the tree or leaf list.
49
- var findStepById = function findStepById(steps, id) {
50
+ var _findStepById = function findStepById(steps, id) {
50
51
  // eslint-disable-next-line no-restricted-syntax
51
52
  for (var _iterator = _createForOfIteratorHelperLoose(steps), _step; !(_step = _iterator()).done;) {
52
53
  var step = _step.value;
53
54
  if (step.id === id) return step;
54
55
  if (step.children) {
55
- var match = step.children.find(function (child) {
56
- return child.id === id;
57
- });
56
+ var match = _findStepById(step.children, id);
58
57
  if (match) return match;
59
58
  }
60
59
  }
61
60
  return undefined;
62
61
  };
62
+ var formHasErrors = function formHasErrors(result) {
63
+ var _result$form, _result$form2;
64
+ return (result == null || (_result$form = result.form) == null ? void 0 : _result$form.ok) === false || Object.keys((result == null || (_result$form2 = result.form) == null ? void 0 : _result$form2.errors) || {}).length > 0;
65
+ };
66
+ var statusFromStep = function statusFromStep(step, validation, completed) {
67
+ var _validation$step$id;
68
+ if (!step) return 'pending';
69
+ if (step.disabled) return 'disabled';
70
+ if (step.status) return step.status;
71
+ if (formHasErrors(validation[step.id]) || ((_validation$step$id = validation[step.id]) == null || (_validation$step$id = _validation$step$id.callback) == null ? void 0 : _validation$step$id.ok) === false) return 'error';
72
+ if (completed.has(step.id)) return 'completed';
73
+ return 'pending';
74
+ };
75
+ var getStepStatus = function getStepStatus(step, validation, completed) {
76
+ var _step$children;
77
+ if (step != null && step.disabled || step != null && step.status || !(step != null && (_step$children = step.children) != null && _step$children.length)) return statusFromStep(step, validation, completed);
78
+ var childStatuses = step.children.map(function (child) {
79
+ return statusFromStep(child, validation, completed);
80
+ });
81
+ if (childStatuses.some(function (status) {
82
+ return status === 'error';
83
+ })) return 'error';
84
+ if (childStatuses.every(function (status) {
85
+ return status === 'completed';
86
+ })) return 'completed';
87
+ if (childStatuses.every(function (status) {
88
+ return status === 'disabled';
89
+ })) return 'disabled';
90
+ return 'pending';
91
+ };
92
+ var filterCompletedSteps = function filterCompletedSteps(steps, validation, completed) {
93
+ var remaining = Array.from(completed).filter(function (stepId) {
94
+ var step = _findStepById(steps, stepId);
95
+ return step && getStepStatus(step, validation, completed) !== 'error';
96
+ });
97
+ return remaining.length === completed.size ? completed : new Set(remaining);
98
+ };
99
+ var resolveStepResults = function resolveStepResults(steps, validation, completed) {
100
+ var results = [];
101
+ var _walk = function walk(nodes) {
102
+ return nodes.forEach(function (step) {
103
+ var _step$errorMessage, _validation$step$id2;
104
+ var childSteps = step.children,
105
+ details = _objectWithoutPropertiesLoose(step, _excluded);
106
+ var status = getStepStatus(step, validation, completed);
107
+ var errorMessage = status === 'error' ? (_step$errorMessage = step.errorMessage) != null ? _step$errorMessage : formHasErrors(validation[step.id]) ? undefined : (_validation$step$id2 = validation[step.id]) == null || (_validation$step$id2 = _validation$step$id2.callback) == null ? void 0 : _validation$step$id2.error : undefined;
108
+ results.push(_extends({}, details, {
109
+ status: status,
110
+ errorMessage: errorMessage
111
+ }));
112
+ if (childSteps != null && childSteps.length) _walk(childSteps);
113
+ });
114
+ };
115
+ _walk(steps);
116
+ return results;
117
+ };
63
118
 
64
119
  // Nearest scrollable ancestor for scrollToTop.
65
120
  var findScrollableAncestor = function findScrollableAncestor(node) {
@@ -75,9 +130,16 @@ var findScrollableAncestor = function findScrollableAncestor(node) {
75
130
  return undefined;
76
131
  };
77
132
  var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
133
+ var _currentValidation$ca, _currentValidation$fo, _currentValidation$ca2;
78
134
  var steps = _ref.steps,
135
+ _ref$clickableSteps = _ref.clickableSteps,
136
+ clickableSteps = _ref$clickableSteps === void 0 ? false : _ref$clickableSteps,
137
+ _ref$closable = _ref.closable,
138
+ closable = _ref$closable === void 0 ? true : _ref$closable,
79
139
  currentStepProp = _ref.currentStep,
80
140
  defaultStep = _ref.defaultStep,
141
+ _ref$form = _ref.form,
142
+ form = _ref$form === void 0 ? true : _ref$form,
81
143
  _ref$showProgress = _ref.showProgress,
82
144
  showProgress = _ref$showProgress === void 0 ? false : _ref$showProgress,
83
145
  onStepChange = _ref.onStepChange,
@@ -95,7 +157,7 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
95
157
  ariaLabel = _ref['aria-label'],
96
158
  messages = _ref.messages,
97
159
  children = _ref.children,
98
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
160
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded2);
99
161
  var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
100
162
  theme = _useThemeValue.theme;
101
163
  var _React$useContext = _react["default"].useContext(_MessageContext.MessageContext),
@@ -111,8 +173,8 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
111
173
 
112
174
  // Only two levels supported (step > child); warn on deeper nesting.
113
175
  var hasDeepNesting = steps.some(function (step) {
114
- var _step$children;
115
- return (_step$children = step.children) == null ? void 0 : _step$children.some(function (child) {
176
+ var _step$children2;
177
+ return (_step$children2 = step.children) == null ? void 0 : _step$children2.some(function (child) {
116
178
  return child.children && child.children.length > 0;
117
179
  });
118
180
  });
@@ -141,6 +203,33 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
141
203
  uncontrolledStep = _useState[0],
142
204
  setUncontrolledStep = _useState[1];
143
205
  var currentStep = isControlled ? currentStepProp : uncontrolledStep;
206
+ var latest = (0, _react.useRef)({
207
+ currentStep: currentStep,
208
+ steps: steps
209
+ });
210
+ latest.current = {
211
+ currentStep: currentStep,
212
+ steps: steps
213
+ };
214
+ var mounted = (0, _react.useRef)(false);
215
+ var navigationVersion = (0, _react.useRef)(0);
216
+ var validationInFlight = (0, _react.useRef)();
217
+ var formValidators = (0, _react.useRef)(new Map());
218
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
219
+ mounted.current = true;
220
+ return function () {
221
+ mounted.current = false;
222
+ };
223
+ }, []);
224
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
225
+ navigationVersion.current += 1;
226
+ }, [currentStep]);
227
+ var registerForm = (0, _react.useCallback)(function (stepId, validateForm) {
228
+ formValidators.current.set(stepId, validateForm);
229
+ return function () {
230
+ if (formValidators.current.get(stepId) === validateForm) formValidators.current["delete"](stepId);
231
+ };
232
+ }, []);
144
233
  var isValueControlled = valueProp !== undefined;
145
234
  var _useState2 = (0, _react.useState)(defaultValue || {}),
146
235
  uncontrolledValue = _useState2[0],
@@ -153,34 +242,56 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
153
242
  value: resolved
154
243
  });
155
244
  }, [formValue, isValueControlled, onChange]);
156
- var _useState3 = (0, _react.useState)([currentStep]),
157
- visitedSteps = _useState3[0],
158
- setVisitedSteps = _useState3[1];
159
- var _useState4 = (0, _react.useState)(function () {
245
+ var _useState3 = (0, _react.useState)(function () {
160
246
  return new Set();
161
247
  }),
162
- completedSteps = _useState4[0],
163
- setCompletedSteps = _useState4[1];
164
- var _useState5 = (0, _react.useState)(undefined),
165
- validationError = _useState5[0],
166
- setValidationError = _useState5[1];
167
- var _useState6 = (0, _react.useState)(false),
168
- isValidating = _useState6[0],
169
- setIsValidating = _useState6[1];
248
+ completedSteps = _useState3[0],
249
+ setCompletedSteps = _useState3[1];
250
+ var stepValidationRef = (0, _react.useRef)({});
251
+ var _useState4 = (0, _react.useState)(stepValidationRef.current),
252
+ stepValidation = _useState4[0],
253
+ setStepValidation = _useState4[1];
254
+ var updateValidation = (0, _react.useCallback)(function (stepId, source, result) {
255
+ var _extends2, _extends3;
256
+ if (!mounted.current || !_findStepById(latest.current.steps, stepId)) return;
257
+ var nextResults = _extends({}, stepValidationRef.current, (_extends3 = {}, _extends3[stepId] = _extends({}, stepValidationRef.current[stepId], (_extends2 = {}, _extends2[source] = result, _extends2)), _extends3));
258
+ stepValidationRef.current = nextResults;
259
+ setStepValidation(nextResults);
260
+ if (result.ok === false) {
261
+ setCompletedSteps(function (previousCompleted) {
262
+ if (!previousCompleted.has(stepId)) return previousCompleted;
263
+ var nextCompleted = new Set(previousCompleted);
264
+ nextCompleted["delete"](stepId);
265
+ return nextCompleted;
266
+ });
267
+ }
268
+ }, []);
269
+ var currentValidation = stepValidation[currentStep];
270
+ var validationError = !formHasErrors(currentValidation) && (currentValidation == null || (_currentValidation$ca = currentValidation.callback) == null ? void 0 : _currentValidation$ca.ok) === false ? currentValidation.callback.error : undefined;
271
+ var _useState5 = (0, _react.useState)(false),
272
+ isValidating = _useState5[0],
273
+ setIsValidating = _useState5[1];
170
274
  // Without `onCancel`, cancel self-closes the wizard.
171
- var _useState7 = (0, _react.useState)(true),
172
- isOpen = _useState7[0],
173
- setIsOpen = _useState7[1];
275
+ var _useState6 = (0, _react.useState)(true),
276
+ isOpen = _useState6[0],
277
+ setIsOpen = _useState6[1];
174
278
  var hasCancelHandler = onCancel !== undefined;
175
-
176
- // Keep visited history in sync when currentStep is externally set.
177
279
  (0, _react.useEffect)(function () {
178
- setVisitedSteps(function (prev) {
179
- return prev[prev.length - 1] === currentStep ? prev : [].concat(prev, [currentStep]);
280
+ if (validationInFlight.current && !_findStepById(steps, validationInFlight.current.stepId)) validationInFlight.current.removed = true;
281
+ var entries = Object.entries(stepValidationRef.current).filter(function (_ref2) {
282
+ var stepId = _ref2[0];
283
+ return _findStepById(steps, stepId);
180
284
  });
181
- }, [currentStep]);
285
+ if (entries.length !== Object.keys(stepValidationRef.current).length) {
286
+ stepValidationRef.current = Object.fromEntries(entries);
287
+ setStepValidation(stepValidationRef.current);
288
+ }
289
+ setCompletedSteps(function (previousCompleted) {
290
+ return filterCompletedSteps(steps, stepValidationRef.current, previousCompleted);
291
+ });
292
+ }, [steps]);
182
293
  var currentStepObj = (0, _react.useMemo)(function () {
183
- return findStepById(steps, currentStep);
294
+ return _findStepById(steps, currentStep);
184
295
  }, [steps, currentStep]);
185
296
  var currentStepIndex = (0, _react.useMemo)(function () {
186
297
  return flatSteps.findIndex(function (step) {
@@ -188,51 +299,21 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
188
299
  });
189
300
  }, [flatSteps, currentStep]);
190
301
  var totalSteps = flatSteps.length;
191
-
192
- // Derive step status; parents aggregate from their children.
193
- var getStepStatus = (0, _react.useCallback)(function (stepId) {
194
- // Parent-with-children aggregate
195
- var parent = steps.find(function (step) {
196
- return step.id === stepId && step.children && step.children.length;
197
- });
198
- if (parent) {
199
- var childStatuses = parent.children.map(function (child) {
200
- if (child.disabled) return 'disabled';
201
- if (child.id === currentStep && validationError) return 'error';
202
- if (completedSteps.has(child.id)) return 'completed';
203
- return 'pending';
204
- });
205
- if (childStatuses.some(function (status) {
206
- return status === 'error';
207
- })) return 'error';
208
- if (childStatuses.every(function (status) {
209
- return status === 'completed';
210
- })) return 'completed';
211
- if (childStatuses.every(function (status) {
212
- return status === 'disabled';
213
- })) return 'disabled';
214
- return 'pending';
215
- }
216
- var step = findStepById(steps, stepId);
217
- if (!step) return 'pending';
218
- if (step.disabled) return 'disabled';
219
- if (stepId === currentStep && validationError) return 'error';
220
- if (completedSteps.has(stepId)) return 'completed';
221
- return 'pending';
222
- }, [steps, currentStep, completedSteps, validationError]);
302
+ var stepResults = (0, _react.useMemo)(function () {
303
+ return resolveStepResults(steps, stepValidation, completedSteps);
304
+ }, [steps, stepValidation, completedSteps]);
223
305
 
224
306
  // Record<id, status> for every step (top-level + children).
225
307
  var stepStates = (0, _react.useMemo)(function () {
226
- var record = {};
227
- var _walk = function walk(nodes) {
228
- nodes.forEach(function (node) {
229
- record[node.id] = getStepStatus(node.id);
230
- if (node.children && node.children.length) _walk(node.children);
231
- });
232
- };
233
- _walk(steps);
234
- return record;
235
- }, [steps, getStepStatus]);
308
+ return Object.fromEntries(stepResults.map(function (step) {
309
+ return [step.id, step.status];
310
+ }));
311
+ }, [stepResults]);
312
+ var stepErrorMessages = (0, _react.useMemo)(function () {
313
+ return Object.fromEntries(stepResults.map(function (step) {
314
+ return [step.id, step.errorMessage];
315
+ }));
316
+ }, [stepResults]);
236
317
 
237
318
  // Emit a step change event to onStepChange.
238
319
  var emitStepChange = (0, _react.useCallback)(function (event) {
@@ -241,85 +322,86 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
241
322
 
242
323
  // Resolve next step id, honoring step.nextStep(formValue) branching.
243
324
  var resolveNextStepId = (0, _react.useCallback)(function () {
244
- var _flatSteps$nextIndex;
245
325
  if (!currentStepObj) return undefined;
246
326
  if (typeof currentStepObj.nextStep === 'function') {
247
327
  var nextId = currentStepObj.nextStep(formValue);
248
328
  if (!nextId) return undefined;
249
- var match = findStepById(steps, nextId);
329
+ var match = _findStepById(steps, nextId);
250
330
  if (!match) {
251
331
  if (process.env.NODE_ENV !== 'production') {
252
332
  console.warn("Wizard: nextStep(\"" + nextId + "\") does not match any step id. " + 'Staying on current step.');
253
333
  }
254
334
  return undefined;
255
335
  }
256
- return nextId;
336
+ return !match.disabled ? nextId : undefined;
257
337
  }
258
338
  var nextIndex = currentStepIndex + 1;
259
- return (_flatSteps$nextIndex = flatSteps[nextIndex]) == null ? void 0 : _flatSteps$nextIndex.id;
260
- }, [currentStepObj, currentStepIndex, flatSteps, formValue, steps]);
339
+ while (nextIndex < flatSteps.length) {
340
+ var nextStep = flatSteps[nextIndex];
341
+ if (!(nextStep != null && nextStep.disabled)) return nextStep.id;
342
+ if (nextStep != null && nextStep.disabled && (clickableSteps || nextStep != null && nextStep.skippable)) {
343
+ nextIndex += 1;
344
+ } else {
345
+ return undefined;
346
+ }
347
+ }
348
+ return undefined;
349
+ }, [clickableSteps, currentStepObj, currentStepIndex, flatSteps, formValue, steps]);
350
+ var resolvePreviousStepId = (0, _react.useCallback)(function () {
351
+ var prevIndex = currentStepIndex - 1;
352
+ while (prevIndex >= 0) {
353
+ var prevStep = flatSteps[prevIndex];
354
+ if (!(prevStep != null && prevStep.disabled)) return prevStep.id;
355
+ prevIndex -= 1;
356
+ }
357
+ return undefined;
358
+ }, [currentStepIndex, flatSteps]);
261
359
 
262
360
  // Apply a navigation transition (id, history, completion, focus).
263
361
  var applyTransition = (0, _react.useCallback)(function (nextId, _temp) {
264
- var _ref2 = _temp === void 0 ? {} : _temp,
265
- markCompleted = _ref2.markCompleted;
362
+ var _ref3 = _temp === void 0 ? {} : _temp,
363
+ markCompleted = _ref3.markCompleted;
266
364
  if (!nextId) return;
365
+ navigationVersion.current += 1;
267
366
  if (markCompleted && currentStep) {
268
367
  setCompletedSteps(function (prev) {
269
368
  var next = new Set(prev);
270
369
  next.add(currentStep);
271
- return next;
370
+ return filterCompletedSteps(latest.current.steps, stepValidationRef.current, next);
272
371
  });
273
372
  }
274
- setValidationError(undefined);
275
- setVisitedSteps(function (prev) {
276
- return [].concat(prev, [nextId]);
277
- });
278
373
  if (!isControlled) setUncontrolledStep(nextId);
279
374
  }, [currentStep, isControlled]);
280
375
 
281
376
  // Run step.validate (sync or async). Returns { ok, error }.
282
- var runValidation = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
283
- var formElement, formIsValid, result, _t;
377
+ var runStepValidation = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
378
+ var result, _t;
284
379
  return _regenerator().w(function (_context) {
285
380
  while (1) switch (_context.p = _context.n) {
286
381
  case 0:
287
- formElement = document.getElementById(currentStep + "-form");
288
- formIsValid = (formElement == null ? void 0 : formElement.getAttribute('data-form-valid')) !== 'false';
289
- if (formIsValid) {
290
- _context.n = 1;
291
- break;
292
- }
293
- return _context.a(2, {
294
- ok: false,
295
- error: undefined
296
- });
297
- case 1:
298
382
  if (!(typeof (currentStepObj == null ? void 0 : currentStepObj.validate) !== 'function')) {
299
- _context.n = 2;
383
+ _context.n = 1;
300
384
  break;
301
385
  }
302
386
  return _context.a(2, {
303
387
  ok: true
304
388
  });
305
- case 2:
306
- setIsValidating(true);
307
- _context.p = 3;
308
- _context.n = 4;
389
+ case 1:
390
+ _context.p = 1;
391
+ _context.n = 2;
309
392
  return currentStepObj.validate(formValue);
310
- case 4:
393
+ case 2:
311
394
  result = _context.v;
312
- setIsValidating(false);
313
395
  if (!(result === true || result === undefined)) {
314
- _context.n = 5;
396
+ _context.n = 3;
315
397
  break;
316
398
  }
317
399
  return _context.a(2, {
318
400
  ok: true
319
401
  });
320
- case 5:
402
+ case 3:
321
403
  if (!(result === false)) {
322
- _context.n = 6;
404
+ _context.n = 4;
323
405
  break;
324
406
  }
325
407
  return _context.a(2, {
@@ -329,32 +411,31 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
329
411
  messages: messages
330
412
  })
331
413
  });
332
- case 6:
414
+ case 4:
333
415
  if (!(typeof result === 'string')) {
334
- _context.n = 7;
416
+ _context.n = 5;
335
417
  break;
336
418
  }
337
419
  return _context.a(2, {
338
420
  ok: false,
339
421
  error: result
340
422
  });
341
- case 7:
342
- if (!(typeof result === 'object' && result.error)) {
343
- _context.n = 8;
423
+ case 5:
424
+ if (!(result && typeof result === 'object' && result.error)) {
425
+ _context.n = 6;
344
426
  break;
345
427
  }
346
428
  return _context.a(2, {
347
429
  ok: false,
348
430
  error: result.error
349
431
  });
350
- case 8:
432
+ case 6:
351
433
  return _context.a(2, {
352
434
  ok: true
353
435
  });
354
- case 9:
355
- _context.p = 9;
436
+ case 7:
437
+ _context.p = 7;
356
438
  _t = _context.v;
357
- setIsValidating(false);
358
439
  return _context.a(2, {
359
440
  ok: false,
360
441
  error: (_t == null ? void 0 : _t.message) || format({
@@ -363,18 +444,93 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
363
444
  })
364
445
  });
365
446
  }
366
- }, _callee, null, [[3, 9]]);
367
- })), [currentStep, currentStepObj, formValue, format, messages]);
368
- var next = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
369
- var _yield$runValidation, ok, error, nextId;
447
+ }, _callee, null, [[1, 7]]);
448
+ })), [currentStepObj, formValue, format, messages]);
449
+ var runValidation = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
450
+ var attempt, isStale, validateForm, _result, result;
370
451
  return _regenerator().w(function (_context2) {
371
- while (1) switch (_context2.n) {
452
+ while (1) switch (_context2.p = _context2.n) {
372
453
  case 0:
373
- if (!isValidating) {
454
+ if (!validationInFlight.current) {
374
455
  _context2.n = 1;
375
456
  break;
376
457
  }
458
+ return _context2.a(2, {
459
+ cancelled: true
460
+ });
461
+ case 1:
462
+ attempt = {
463
+ stepId: currentStep,
464
+ version: navigationVersion.current
465
+ };
466
+ validationInFlight.current = attempt;
467
+ setIsValidating(true);
468
+ isStale = function isStale() {
469
+ return !mounted.current || attempt.removed || latest.current.currentStep !== attempt.stepId || navigationVersion.current !== attempt.version || !_findStepById(latest.current.steps, attempt.stepId);
470
+ };
471
+ _context2.p = 2;
472
+ validateForm = form && formValidators.current.get(currentStep);
473
+ if (!validateForm) {
474
+ _context2.n = 6;
475
+ break;
476
+ }
477
+ _context2.n = 3;
478
+ return validateForm();
479
+ case 3:
480
+ _result = _context2.v;
481
+ if (!_result.cancelled) {
482
+ _context2.n = 4;
483
+ break;
484
+ }
485
+ return _context2.a(2, {
486
+ cancelled: true
487
+ });
488
+ case 4:
489
+ if (_result.ok) {
490
+ _context2.n = 5;
491
+ break;
492
+ }
493
+ return _context2.a(2, {
494
+ ok: false,
495
+ cancelled: isStale()
496
+ });
497
+ case 5:
498
+ if (!isStale()) {
499
+ _context2.n = 6;
500
+ break;
501
+ }
502
+ return _context2.a(2, {
503
+ cancelled: true
504
+ });
505
+ case 6:
506
+ _context2.n = 7;
507
+ return runStepValidation();
508
+ case 7:
509
+ result = _context2.v;
510
+ if (!attempt.removed) updateValidation(attempt.stepId, 'callback', result);
511
+ return _context2.a(2, _extends({}, result, {
512
+ cancelled: isStale()
513
+ }));
514
+ case 8:
515
+ _context2.p = 8;
516
+ validationInFlight.current = undefined;
517
+ if (mounted.current) setIsValidating(false);
518
+ return _context2.f(8);
519
+ case 9:
377
520
  return _context2.a(2);
521
+ }
522
+ }, _callee2, null, [[2,, 8, 9]]);
523
+ })), [currentStep, form, runStepValidation, updateValidation]);
524
+ var next = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
525
+ var _yield$runValidation, ok, error, cancelled, sourceStep, nextId;
526
+ return _regenerator().w(function (_context3) {
527
+ while (1) switch (_context3.n) {
528
+ case 0:
529
+ if (!(validationInFlight.current || currentStepObj != null && currentStepObj.disabled)) {
530
+ _context3.n = 1;
531
+ break;
532
+ }
533
+ return _context3.a(2);
378
534
  case 1:
379
535
  emitStepChange({
380
536
  trigger: 'next',
@@ -386,25 +542,32 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
386
542
  phase: 'validating',
387
543
  from: currentStep
388
544
  });
389
- _context2.n = 2;
545
+ _context3.n = 2;
390
546
  return runValidation();
391
547
  case 2:
392
- _yield$runValidation = _context2.v;
548
+ _yield$runValidation = _context3.v;
393
549
  ok = _yield$runValidation.ok;
394
550
  error = _yield$runValidation.error;
395
- if (ok) {
396
- _context2.n = 3;
551
+ cancelled = _yield$runValidation.cancelled;
552
+ if (!cancelled) {
553
+ _context3.n = 3;
554
+ break;
555
+ }
556
+ return _context3.a(2);
557
+ case 3:
558
+ sourceStep = _findStepById(latest.current.steps, currentStep);
559
+ if (!(!ok || (sourceStep == null ? void 0 : sourceStep.status) === 'error')) {
560
+ _context3.n = 4;
397
561
  break;
398
562
  }
399
- setValidationError(error);
400
563
  emitStepChange({
401
564
  trigger: 'next',
402
565
  phase: 'blocked',
403
566
  from: currentStep,
404
- error: error
567
+ error: error != null ? error : sourceStep == null ? void 0 : sourceStep.errorMessage
405
568
  });
406
- return _context2.a(2);
407
- case 3:
569
+ return _context3.a(2);
570
+ case 4:
408
571
  emitStepChange({
409
572
  trigger: 'next',
410
573
  phase: 'validated',
@@ -412,11 +575,11 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
412
575
  });
413
576
  nextId = resolveNextStepId();
414
577
  if (nextId) {
415
- _context2.n = 4;
578
+ _context3.n = 5;
416
579
  break;
417
580
  }
418
- return _context2.a(2);
419
- case 4:
581
+ return _context3.a(2);
582
+ case 5:
420
583
  applyTransition(nextId, {
421
584
  markCompleted: true
422
585
  });
@@ -430,22 +593,15 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
430
593
  type: 'wizardNext',
431
594
  element: 'Wizard'
432
595
  });
433
- case 5:
434
- return _context2.a(2);
596
+ case 6:
597
+ return _context3.a(2);
435
598
  }
436
- }, _callee2);
437
- })), [sendAnalytics, applyTransition, currentStep, emitStepChange, isValidating, resolveNextStepId, runValidation]);
599
+ }, _callee3);
600
+ })), [sendAnalytics, applyTransition, currentStep, currentStepObj, emitStepChange, resolveNextStepId, runValidation]);
438
601
  var previous = (0, _react.useCallback)(function () {
439
- var _flatSteps;
440
- // History-aware; falls back to the linear predecessor.
441
- var historyDest = visitedSteps.length > 1 ? visitedSteps[visitedSteps.length - 2] : undefined;
442
- var fallbackDest = (_flatSteps = flatSteps[currentStepIndex - 1]) == null ? void 0 : _flatSteps.id;
443
- var dest = historyDest || fallbackDest;
602
+ var dest = resolvePreviousStepId();
444
603
  if (!dest) return;
445
- setVisitedSteps(function (prev) {
446
- return prev.slice(0, -1);
447
- });
448
- setValidationError(undefined);
604
+ navigationVersion.current += 1;
449
605
  if (!isControlled) setUncontrolledStep(dest);
450
606
  emitStepChange({
451
607
  trigger: 'previous',
@@ -457,30 +613,43 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
457
613
  type: 'wizardPrevious',
458
614
  element: 'Wizard'
459
615
  });
460
- }, [sendAnalytics, currentStep, currentStepIndex, emitStepChange, flatSteps, isControlled, visitedSteps]);
616
+ }, [sendAnalytics, currentStep, resolvePreviousStepId, emitStepChange, isControlled]);
461
617
  var goTo = (0, _react.useCallback)(/*#__PURE__*/function () {
462
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(stepId) {
463
- var target, targetIndex, forward, _yield$runValidation2, ok, error;
464
- return _regenerator().w(function (_context3) {
465
- while (1) switch (_context3.n) {
618
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(stepId) {
619
+ var target, targetIndex, forward, markCompleted, navigationError, _yield$runValidation2, ok, error, cancelled;
620
+ return _regenerator().w(function (_context4) {
621
+ while (1) switch (_context4.n) {
466
622
  case 0:
467
623
  if (!(!stepId || stepId === currentStep)) {
468
- _context3.n = 1;
624
+ _context4.n = 1;
469
625
  break;
470
626
  }
471
- return _context3.a(2);
627
+ return _context4.a(2);
472
628
  case 1:
473
- target = findStepById(steps, stepId);
629
+ target = _findStepById(steps, stepId);
474
630
  if (!(!target || target.disabled)) {
475
- _context3.n = 2;
631
+ _context4.n = 2;
476
632
  break;
477
633
  }
478
- return _context3.a(2);
634
+ return _context4.a(2);
479
635
  case 2:
480
636
  targetIndex = flatSteps.findIndex(function (step) {
481
637
  return step.id === stepId;
482
638
  });
639
+ if (!(targetIndex < 0)) {
640
+ _context4.n = 3;
641
+ break;
642
+ }
643
+ return _context4.a(2);
644
+ case 3:
483
645
  forward = targetIndex > currentStepIndex;
646
+ markCompleted = false;
647
+ if (!(forward && validationInFlight.current)) {
648
+ _context4.n = 4;
649
+ break;
650
+ }
651
+ return _context4.a(2);
652
+ case 4:
484
653
  emitStepChange({
485
654
  trigger: 'goTo',
486
655
  phase: 'requested',
@@ -488,7 +657,7 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
488
657
  to: stepId
489
658
  });
490
659
  if (!forward) {
491
- _context3.n = 5;
660
+ _context4.n = 8;
492
661
  break;
493
662
  }
494
663
  emitStepChange({
@@ -497,17 +666,23 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
497
666
  from: currentStep,
498
667
  to: stepId
499
668
  });
500
- _context3.n = 3;
669
+ _context4.n = 5;
501
670
  return runValidation();
502
- case 3:
503
- _yield$runValidation2 = _context3.v;
671
+ case 5:
672
+ _yield$runValidation2 = _context4.v;
504
673
  ok = _yield$runValidation2.ok;
505
674
  error = _yield$runValidation2.error;
506
- if (ok) {
507
- _context3.n = 4;
675
+ cancelled = _yield$runValidation2.cancelled;
676
+ if (!cancelled) {
677
+ _context4.n = 6;
678
+ break;
679
+ }
680
+ return _context4.a(2);
681
+ case 6:
682
+ if (!(!ok && !(currentStepObj != null && currentStepObj.skippable))) {
683
+ _context4.n = 7;
508
684
  break;
509
685
  }
510
- setValidationError(error);
511
686
  emitStepChange({
512
687
  trigger: 'goTo',
513
688
  phase: 'blocked',
@@ -515,42 +690,43 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
515
690
  to: stepId,
516
691
  error: error
517
692
  });
518
- return _context3.a(2);
519
- case 4:
520
- emitStepChange({
693
+ return _context4.a(2);
694
+ case 7:
695
+ markCompleted = ok;
696
+ navigationError = error;
697
+ if (ok) emitStepChange({
521
698
  trigger: 'goTo',
522
699
  phase: 'validated',
523
700
  from: currentStep,
524
701
  to: stepId
525
702
  });
526
- case 5:
703
+ case 8:
527
704
  applyTransition(stepId, {
528
- markCompleted: forward
705
+ markCompleted: markCompleted
529
706
  });
530
- emitStepChange({
707
+ emitStepChange(_extends({
531
708
  trigger: 'goTo',
532
709
  phase: 'navigated',
533
710
  from: currentStep,
534
711
  to: stepId
535
- });
536
- case 6:
537
- return _context3.a(2);
712
+ }, navigationError ? {
713
+ error: navigationError
714
+ } : {}));
715
+ case 9:
716
+ return _context4.a(2);
538
717
  }
539
- }, _callee3);
718
+ }, _callee4);
540
719
  }));
541
720
  return function (_x) {
542
- return _ref5.apply(this, arguments);
721
+ return _ref7.apply(this, arguments);
543
722
  };
544
- }(), [applyTransition, currentStep, currentStepIndex, emitStepChange, flatSteps, runValidation, steps]);
723
+ }(), [applyTransition, currentStep, currentStepIndex, currentStepObj, emitStepChange, flatSteps, runValidation, steps]);
545
724
  var skip = (0, _react.useCallback)(function () {
546
725
  if (!(currentStepObj != null && currentStepObj.skippable)) return;
547
726
  var nextId = resolveNextStepId();
548
727
  if (!nextId) return;
549
728
  // Skip: no validation, no completion.
550
- setValidationError(undefined);
551
- setVisitedSteps(function (prev) {
552
- return [].concat(prev, [nextId]);
553
- });
729
+ navigationVersion.current += 1;
554
730
  if (!isControlled) setUncontrolledStep(nextId);
555
731
  emitStepChange({
556
732
  trigger: 'skip',
@@ -563,16 +739,16 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
563
739
  element: 'Wizard'
564
740
  });
565
741
  }, [sendAnalytics, currentStep, currentStepObj, emitStepChange, isControlled, resolveNextStepId]);
566
- var complete = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
567
- var _yield$runValidation3, ok, error, nextCompleted, completedStepsList;
568
- return _regenerator().w(function (_context4) {
569
- while (1) switch (_context4.n) {
742
+ var complete = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
743
+ var _yield$runValidation3, ok, error, cancelled, completionCandidates, nextCompleted, completedStepsList;
744
+ return _regenerator().w(function (_context5) {
745
+ while (1) switch (_context5.n) {
570
746
  case 0:
571
- if (!isValidating) {
572
- _context4.n = 1;
747
+ if (!(validationInFlight.current || currentStepObj != null && currentStepObj.disabled)) {
748
+ _context5.n = 1;
573
749
  break;
574
750
  }
575
- return _context4.a(2);
751
+ return _context5.a(2);
576
752
  case 1:
577
753
  emitStepChange({
578
754
  trigger: 'complete',
@@ -584,35 +760,40 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
584
760
  phase: 'validating',
585
761
  from: currentStep
586
762
  });
587
- _context4.n = 2;
763
+ _context5.n = 2;
588
764
  return runValidation();
589
765
  case 2:
590
- _yield$runValidation3 = _context4.v;
766
+ _yield$runValidation3 = _context5.v;
591
767
  ok = _yield$runValidation3.ok;
592
768
  error = _yield$runValidation3.error;
593
- if (ok) {
594
- _context4.n = 3;
769
+ cancelled = _yield$runValidation3.cancelled;
770
+ if (!cancelled) {
771
+ _context5.n = 3;
772
+ break;
773
+ }
774
+ return _context5.a(2);
775
+ case 3:
776
+ if (!(!ok && !(currentStepObj != null && currentStepObj.skippable))) {
777
+ _context5.n = 4;
595
778
  break;
596
779
  }
597
- setValidationError(error);
598
780
  emitStepChange({
599
781
  trigger: 'complete',
600
782
  phase: 'blocked',
601
783
  from: currentStep,
602
784
  error: error
603
785
  });
604
- return _context4.a(2);
605
- case 3:
606
- emitStepChange({
786
+ return _context5.a(2);
787
+ case 4:
788
+ if (ok) emitStepChange({
607
789
  trigger: 'complete',
608
790
  phase: 'validated',
609
791
  from: currentStep
610
792
  });
611
- setCompletedSteps(function (prev) {
612
- var nextCompleted = new Set(prev);
613
- nextCompleted.add(currentStep);
614
- return nextCompleted;
615
- });
793
+ completionCandidates = new Set(completedSteps);
794
+ if (ok) completionCandidates.add(currentStep);else completionCandidates["delete"](currentStep);
795
+ nextCompleted = filterCompletedSteps(latest.current.steps, stepValidationRef.current, completionCandidates);
796
+ setCompletedSteps(nextCompleted);
616
797
  // Emit 'completed' before invoking onComplete.
617
798
  emitStepChange({
618
799
  trigger: 'complete',
@@ -620,26 +801,24 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
620
801
  from: currentStep
621
802
  });
622
803
  if (onComplete) {
623
- // setCompletedSteps above is async; include currentStep here so the
624
- // payload reflects the just-completed final step.
625
- nextCompleted = new Set(completedSteps);
626
- nextCompleted.add(currentStep);
627
804
  completedStepsList = Array.from(nextCompleted);
628
805
  onComplete({
629
806
  value: formValue,
630
- completedSteps: completedStepsList
807
+ completedSteps: completedStepsList,
808
+ steps: resolveStepResults(latest.current.steps, stepValidationRef.current, nextCompleted)
631
809
  });
632
810
  }
633
811
  if (sendAnalytics) sendAnalytics({
634
812
  type: 'wizardComplete',
635
813
  element: 'Wizard'
636
814
  });
637
- case 4:
638
- return _context4.a(2);
815
+ case 5:
816
+ return _context5.a(2);
639
817
  }
640
- }, _callee4);
641
- })), [sendAnalytics, completedSteps, currentStep, emitStepChange, formValue, isValidating, onComplete, runValidation]);
818
+ }, _callee5);
819
+ })), [sendAnalytics, completedSteps, currentStep, currentStepObj, emitStepChange, formValue, onComplete, runValidation]);
642
820
  var cancel = (0, _react.useCallback)(function () {
821
+ navigationVersion.current += 1;
643
822
  emitStepChange({
644
823
  trigger: 'cancel',
645
824
  phase: 'cancelled',
@@ -687,17 +866,24 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
687
866
  if (typeof window !== 'undefined') safeScrollTo(window);
688
867
  }, [currentStep, scrollToTop, wizardRef]);
689
868
  var canGoNext = !(currentStepObj != null && currentStepObj.disabled) && !isValidating;
690
- var isBlocked = !!validationError && !(currentStepObj != null && currentStepObj.skippable);
869
+ var isBlocked = (currentValidation == null || (_currentValidation$fo = currentValidation.form) == null ? void 0 : _currentValidation$fo.ok) === false || (currentValidation == null || (_currentValidation$ca2 = currentValidation.callback) == null ? void 0 : _currentValidation$ca2.ok) === false;
691
870
  var isCompleted = completedSteps.has(currentStep);
692
871
  var contextValue = (0, _react.useMemo)(function () {
693
872
  return {
694
873
  steps: steps,
695
874
  flatSteps: flatSteps,
875
+ clickableSteps: clickableSteps,
876
+ closable: closable,
696
877
  currentStep: currentStep,
697
878
  currentStepIndex: currentStepIndex,
698
879
  currentStepObj: currentStepObj,
699
880
  totalSteps: totalSteps,
700
881
  stepStates: stepStates,
882
+ stepErrorMessages: stepErrorMessages,
883
+ stepValidation: stepValidation,
884
+ updateValidation: updateValidation,
885
+ registerForm: registerForm,
886
+ form: form,
701
887
  formValue: formValue,
702
888
  setFormValue: setFormValue,
703
889
  validationError: validationError,
@@ -719,7 +905,7 @@ var Wizard = exports.Wizard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
719
905
  // (same pattern as `hasCancelHandler`).
720
906
  messages: messages
721
907
  };
722
- }, [steps, flatSteps, currentStep, currentStepIndex, currentStepObj, totalSteps, stepStates, formValue, setFormValue, validationError, isValidating, isBlocked, isCompleted, canGoNext, next, previous, goTo, skip, complete, cancel, hasCancelHandler, effectiveShowProgress, renderStep, messages]);
908
+ }, [steps, flatSteps, clickableSteps, closable, currentStep, currentStepIndex, currentStepObj, totalSteps, stepStates, stepErrorMessages, stepValidation, updateValidation, registerForm, form, formValue, setFormValue, validationError, isValidating, isBlocked, isCompleted, canGoNext, next, previous, goTo, skip, complete, cancel, hasCancelHandler, effectiveShowProgress, renderStep, messages]);
723
909
  if (!isOpen) return null;
724
910
 
725
911
  // Custom composition: consumers supply their own tree via `children`.