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