grommet 2.56.0 → 2.56.1

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 (118) hide show
  1. package/COPYRIGHT.md +3 -1
  2. package/components/Calendar/Calendar.js +2 -1
  3. package/components/Cards/Cards.js +1 -2
  4. package/components/DateTimeInput/DateTimeInput.js +1093 -0
  5. package/components/DateTimeInput/README.md +2 -0
  6. package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
  7. package/components/DateTimeInput/index.d.ts +47 -0
  8. package/components/DateTimeInput/index.js +6 -0
  9. package/components/DateTimeInput/propTypes.js +42 -0
  10. package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  11. package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  12. package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  13. package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  14. package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  15. package/components/Form/Form.js +7 -4
  16. package/components/Form/index.d.ts +3 -0
  17. package/components/Form/stories/AggregateValidation.stories.js +6 -8
  18. package/components/FormField/FormField.js +164 -91
  19. package/components/Stepper/StepConnector.js +19 -49
  20. package/components/Stepper/Stepper.js +5 -11
  21. package/components/Stepper/StepperStep.js +14 -4
  22. package/components/Stepper/StyledStepper.js +59 -21
  23. package/components/TimeInput/TimeInput.js +50 -47
  24. package/components/TimeInput/TimeInputPopup.js +172 -76
  25. package/components/TimeInput/index.d.ts +3 -0
  26. package/components/TimeInput/propTypes.js +4 -0
  27. package/components/TimeInput/useSectionedTimeField.js +33 -34
  28. package/components/TimeInput/utils.js +31 -26
  29. package/components/Wizard/StyledWizard.js +16 -0
  30. package/components/Wizard/Wizard.js +770 -0
  31. package/components/Wizard/WizardContent.js +90 -0
  32. package/components/Wizard/WizardContext.js +35 -0
  33. package/components/Wizard/WizardFooter.js +123 -0
  34. package/components/Wizard/WizardHeader.js +63 -0
  35. package/components/Wizard/WizardProgress.js +84 -0
  36. package/components/Wizard/WizardStepHeader.js +55 -0
  37. package/components/Wizard/index.d.ts +171 -0
  38. package/components/Wizard/index.js +19 -0
  39. package/components/Wizard/propTypes.js +56 -0
  40. package/components/Wizard/stories/BasicLinear.stories.js +71 -0
  41. package/components/Wizard/stories/Branching.stories.js +96 -0
  42. package/components/Wizard/stories/Composable.stories.js +75 -0
  43. package/components/Wizard/stories/Controlled.stories.js +136 -0
  44. package/components/Wizard/stories/LongContent.stories.js +118 -0
  45. package/components/Wizard/stories/Modal.stories.js +143 -0
  46. package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
  47. package/components/Wizard/stories/Validation.stories.js +123 -0
  48. package/components/index.d.ts +4 -0
  49. package/components/index.js +12 -0
  50. package/es6/components/Calendar/Calendar.js +2 -0
  51. package/es6/components/Cards/Cards.js +1 -2
  52. package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
  53. package/es6/components/DateTimeInput/README.md +2 -0
  54. package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
  55. package/es6/components/DateTimeInput/index.d.ts +47 -0
  56. package/es6/components/DateTimeInput/index.js +3 -0
  57. package/es6/components/DateTimeInput/propTypes.js +36 -0
  58. package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  59. package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  60. package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  61. package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  62. package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  63. package/es6/components/Form/Form.js +7 -3
  64. package/es6/components/Form/index.d.ts +3 -0
  65. package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
  66. package/es6/components/FormField/FormField.js +165 -91
  67. package/es6/components/Stepper/StepConnector.js +18 -48
  68. package/es6/components/Stepper/Stepper.js +5 -10
  69. package/es6/components/Stepper/StepperStep.js +15 -4
  70. package/es6/components/Stepper/StyledStepper.js +57 -21
  71. package/es6/components/TimeInput/TimeInput.js +50 -46
  72. package/es6/components/TimeInput/TimeInputPopup.js +172 -76
  73. package/es6/components/TimeInput/index.d.ts +3 -0
  74. package/es6/components/TimeInput/propTypes.js +3 -0
  75. package/es6/components/TimeInput/useSectionedTimeField.js +34 -35
  76. package/es6/components/TimeInput/utils.js +25 -21
  77. package/es6/components/Wizard/StyledWizard.js +11 -0
  78. package/es6/components/Wizard/Wizard.js +768 -0
  79. package/es6/components/Wizard/WizardContent.js +87 -0
  80. package/es6/components/Wizard/WizardContext.js +31 -0
  81. package/es6/components/Wizard/WizardFooter.js +120 -0
  82. package/es6/components/Wizard/WizardHeader.js +60 -0
  83. package/es6/components/Wizard/WizardProgress.js +80 -0
  84. package/es6/components/Wizard/WizardStepHeader.js +51 -0
  85. package/es6/components/Wizard/index.d.ts +171 -0
  86. package/es6/components/Wizard/index.js +7 -0
  87. package/es6/components/Wizard/propTypes.js +51 -0
  88. package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
  89. package/es6/components/Wizard/stories/Branching.stories.js +93 -0
  90. package/es6/components/Wizard/stories/Composable.stories.js +72 -0
  91. package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
  92. package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
  93. package/es6/components/Wizard/stories/Modal.stories.js +141 -0
  94. package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
  95. package/es6/components/Wizard/stories/Validation.stories.js +118 -0
  96. package/es6/components/index.d.ts +4 -0
  97. package/es6/components/index.js +4 -0
  98. package/es6/index.d.ts +4 -0
  99. package/es6/languages/default.json +28 -0
  100. package/es6/themes/base.d.ts +115 -0
  101. package/es6/themes/base.js +158 -0
  102. package/es6/utils/DOM.js +11 -2
  103. package/es6/utils/dates.js +10 -0
  104. package/es6/utils/sectionHelpers.js +57 -0
  105. package/es6/utils/useSectionedField.js +45 -0
  106. package/grommet.min.js +2 -1
  107. package/grommet.min.js.LICENSE.txt +1 -0
  108. package/grommet.min.js.map +1 -1
  109. package/index.d.ts +4 -0
  110. package/languages/default.json +28 -0
  111. package/package.json +35 -31
  112. package/themes/base.d.ts +115 -0
  113. package/themes/base.js +158 -1
  114. package/tools/license-header.js +2 -0
  115. package/utils/DOM.js +11 -2
  116. package/utils/dates.js +11 -1
  117. package/utils/sectionHelpers.js +61 -0
  118. package/utils/useSectionedField.js +50 -0
@@ -0,0 +1,768 @@
1
+ var _excluded = ["steps", "currentStep", "defaultStep", "showProgress", "onStepChange", "onComplete", "onCancel", "renderStep", "title", "footer", "scrollToTop", "value", "defaultValue", "onChange", "id", "aria-label", "messages", "children"];
2
+ 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); }
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
+ 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
+ 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
+ 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 _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
+ 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
+ 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
+ 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
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
12
+ // SPDX-License-Identifier: Apache-2.0
13
+ import React, { forwardRef, useCallback, useEffect, useMemo, useState } from 'react';
14
+ import { useAnalytics } from '../../contexts';
15
+ import { MessageContext } from '../../contexts/MessageContext';
16
+ import { ResponsiveContext } from '../../contexts/ResponsiveContext';
17
+ import { useForwardedRef } from '../../utils';
18
+ import { useThemeValue } from '../../utils/useThemeValue';
19
+ import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
20
+ import { Box } from '../Box';
21
+ import { WizardContext } from './WizardContext';
22
+ import { WizardHeader } from './WizardHeader';
23
+ import { WizardProgress } from './WizardProgress';
24
+ import { WizardStepHeader } from './WizardStepHeader';
25
+ import { WizardContent } from './WizardContent';
26
+ import { WizardFooter } from './WizardFooter';
27
+ import { WizardPropTypes } from './propTypes';
28
+
29
+ // Flatten step tree into ordered leaves; parents with children are
30
+ // aggregate-only, never nav targets.
31
+ var flattenLeaves = function flattenLeaves(steps) {
32
+ var leaves = [];
33
+ steps.forEach(function (step) {
34
+ if (step.children && step.children.length) {
35
+ step.children.forEach(function (child) {
36
+ return leaves.push(child);
37
+ });
38
+ } else {
39
+ leaves.push(step);
40
+ }
41
+ });
42
+ return leaves;
43
+ };
44
+
45
+ // Find step by id in the tree or leaf list.
46
+ var findStepById = function findStepById(steps, id) {
47
+ // eslint-disable-next-line no-restricted-syntax
48
+ for (var _iterator = _createForOfIteratorHelperLoose(steps), _step; !(_step = _iterator()).done;) {
49
+ var step = _step.value;
50
+ if (step.id === id) return step;
51
+ if (step.children) {
52
+ var match = step.children.find(function (child) {
53
+ return child.id === id;
54
+ });
55
+ if (match) return match;
56
+ }
57
+ }
58
+ return undefined;
59
+ };
60
+
61
+ // Nearest scrollable ancestor for scrollToTop.
62
+ var findScrollableAncestor = function findScrollableAncestor(node) {
63
+ var element = node == null ? void 0 : node.parentElement;
64
+ while (element && element !== document.body) {
65
+ var _window$getComputedSt = window.getComputedStyle(element),
66
+ overflowY = _window$getComputedSt.overflowY;
67
+ if ((overflowY === 'auto' || overflowY === 'scroll') && element.scrollHeight > element.clientHeight) {
68
+ return element;
69
+ }
70
+ element = element.parentElement;
71
+ }
72
+ return undefined;
73
+ };
74
+ var Wizard = /*#__PURE__*/forwardRef(function (_ref, ref) {
75
+ var steps = _ref.steps,
76
+ currentStepProp = _ref.currentStep,
77
+ defaultStep = _ref.defaultStep,
78
+ _ref$showProgress = _ref.showProgress,
79
+ showProgress = _ref$showProgress === void 0 ? false : _ref$showProgress,
80
+ onStepChange = _ref.onStepChange,
81
+ onComplete = _ref.onComplete,
82
+ onCancel = _ref.onCancel,
83
+ renderStep = _ref.renderStep,
84
+ title = _ref.title,
85
+ footer = _ref.footer,
86
+ _ref$scrollToTop = _ref.scrollToTop,
87
+ scrollToTop = _ref$scrollToTop === void 0 ? true : _ref$scrollToTop,
88
+ valueProp = _ref.value,
89
+ defaultValue = _ref.defaultValue,
90
+ onChange = _ref.onChange,
91
+ id = _ref.id,
92
+ ariaLabel = _ref['aria-label'],
93
+ messages = _ref.messages,
94
+ children = _ref.children,
95
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
96
+ var _useThemeValue = useThemeValue(),
97
+ theme = _useThemeValue.theme;
98
+ var _React$useContext = React.useContext(MessageContext),
99
+ format = _React$useContext.format;
100
+ var responsiveSize = React.useContext(ResponsiveContext);
101
+ var sendAnalytics = useAnalytics();
102
+
103
+ // Horizontal progress + sub-steps: fall back to vertical.
104
+ var hasSubSteps = steps.some(function (step) {
105
+ return step.children && step.children.length > 0;
106
+ });
107
+ var effectiveShowProgress = hasSubSteps && showProgress === 'horizontal' ? 'vertical' : showProgress;
108
+
109
+ // Only two levels supported (step > child); warn on deeper nesting.
110
+ var hasDeepNesting = steps.some(function (step) {
111
+ var _step$children;
112
+ return (_step$children = step.children) == null ? void 0 : _step$children.some(function (child) {
113
+ return child.children && child.children.length > 0;
114
+ });
115
+ });
116
+ useEffect(function () {
117
+ if (process.env.NODE_ENV !== 'production') {
118
+ console.warn('Warning: Wizard is currently in beta. The API is subject ' + 'to change in future releases.');
119
+ }
120
+ }, []);
121
+ if (process.env.NODE_ENV !== 'production') {
122
+ if (hasSubSteps && showProgress === 'horizontal') {
123
+ console.warn('Wizard: horizontal showProgress with sub-steps is not supported. ' + 'Falling back to vertical.');
124
+ }
125
+ if (hasDeepNesting) {
126
+ console.warn('Wizard: nesting deeper than one level (step > child) is not ' + 'supported. Descendants beyond the child level are ignored ' + 'by default.');
127
+ }
128
+ }
129
+ var wizardRef = useForwardedRef(ref);
130
+ var flatSteps = useMemo(function () {
131
+ return flattenLeaves(steps);
132
+ }, [steps]);
133
+ var firstEnabled = flatSteps.find(function (step) {
134
+ return !step.disabled;
135
+ }) || flatSteps[0];
136
+ var isControlled = currentStepProp !== undefined;
137
+ var _useState = useState(defaultStep || (firstEnabled == null ? void 0 : firstEnabled.id)),
138
+ uncontrolledStep = _useState[0],
139
+ setUncontrolledStep = _useState[1];
140
+ var currentStep = isControlled ? currentStepProp : uncontrolledStep;
141
+ var isValueControlled = valueProp !== undefined;
142
+ var _useState2 = useState(defaultValue || {}),
143
+ uncontrolledValue = _useState2[0],
144
+ setUncontrolledValue = _useState2[1];
145
+ var formValue = isValueControlled ? valueProp : uncontrolledValue;
146
+ var setFormValue = useCallback(function (nextValueOrFn) {
147
+ var resolved = typeof nextValueOrFn === 'function' ? nextValueOrFn(formValue) : nextValueOrFn;
148
+ if (!isValueControlled) setUncontrolledValue(resolved);
149
+ if (onChange) onChange({
150
+ value: resolved
151
+ });
152
+ }, [formValue, isValueControlled, onChange]);
153
+ var _useState3 = useState([currentStep]),
154
+ visitedSteps = _useState3[0],
155
+ setVisitedSteps = _useState3[1];
156
+ var _useState4 = useState(function () {
157
+ return new Set();
158
+ }),
159
+ completedSteps = _useState4[0],
160
+ setCompletedSteps = _useState4[1];
161
+ var _useState5 = useState(undefined),
162
+ validationError = _useState5[0],
163
+ setValidationError = _useState5[1];
164
+ var _useState6 = useState(false),
165
+ isValidating = _useState6[0],
166
+ setIsValidating = _useState6[1];
167
+ // Without `onCancel`, cancel self-closes the wizard.
168
+ var _useState7 = useState(true),
169
+ isOpen = _useState7[0],
170
+ setIsOpen = _useState7[1];
171
+ var hasCancelHandler = onCancel !== undefined;
172
+
173
+ // Keep visited history in sync when currentStep is externally set.
174
+ useEffect(function () {
175
+ setVisitedSteps(function (prev) {
176
+ return prev[prev.length - 1] === currentStep ? prev : [].concat(prev, [currentStep]);
177
+ });
178
+ }, [currentStep]);
179
+ var currentStepObj = useMemo(function () {
180
+ return findStepById(steps, currentStep);
181
+ }, [steps, currentStep]);
182
+ var currentStepIndex = useMemo(function () {
183
+ return flatSteps.findIndex(function (step) {
184
+ return step.id === currentStep;
185
+ });
186
+ }, [flatSteps, currentStep]);
187
+ var totalSteps = flatSteps.length;
188
+
189
+ // Derive step status; parents aggregate from their children.
190
+ var getStepStatus = useCallback(function (stepId) {
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]);
220
+
221
+ // Record<id, status> for every step (top-level + children).
222
+ var stepStates = useMemo(function () {
223
+ var record = {};
224
+ var _walk = function walk(nodes) {
225
+ nodes.forEach(function (node) {
226
+ record[node.id] = getStepStatus(node.id);
227
+ if (node.children && node.children.length) _walk(node.children);
228
+ });
229
+ };
230
+ _walk(steps);
231
+ return record;
232
+ }, [steps, getStepStatus]);
233
+
234
+ // Emit a step change event to onStepChange.
235
+ var emitStepChange = useCallback(function (event) {
236
+ if (onStepChange) onStepChange(event);
237
+ }, [onStepChange]);
238
+
239
+ // Resolve next step id, honoring step.nextStep(formValue) branching.
240
+ var resolveNextStepId = useCallback(function () {
241
+ var _flatSteps$nextIndex;
242
+ if (!currentStepObj) return undefined;
243
+ if (typeof currentStepObj.nextStep === 'function') {
244
+ var nextId = currentStepObj.nextStep(formValue);
245
+ if (!nextId) return undefined;
246
+ var match = findStepById(steps, nextId);
247
+ if (!match) {
248
+ if (process.env.NODE_ENV !== 'production') {
249
+ console.warn("Wizard: nextStep(\"" + nextId + "\") does not match any step id. " + 'Staying on current step.');
250
+ }
251
+ return undefined;
252
+ }
253
+ return nextId;
254
+ }
255
+ var nextIndex = currentStepIndex + 1;
256
+ return (_flatSteps$nextIndex = flatSteps[nextIndex]) == null ? void 0 : _flatSteps$nextIndex.id;
257
+ }, [currentStepObj, currentStepIndex, flatSteps, formValue, steps]);
258
+
259
+ // Apply a navigation transition (id, history, completion, focus).
260
+ var applyTransition = useCallback(function (nextId, _temp) {
261
+ var _ref2 = _temp === void 0 ? {} : _temp,
262
+ markCompleted = _ref2.markCompleted;
263
+ if (!nextId) return;
264
+ if (markCompleted && currentStep) {
265
+ setCompletedSteps(function (prev) {
266
+ var next = new Set(prev);
267
+ next.add(currentStep);
268
+ return next;
269
+ });
270
+ }
271
+ setValidationError(undefined);
272
+ setVisitedSteps(function (prev) {
273
+ return [].concat(prev, [nextId]);
274
+ });
275
+ if (!isControlled) setUncontrolledStep(nextId);
276
+ }, [currentStep, isControlled]);
277
+
278
+ // Run step.validate (sync or async). Returns { ok, error }.
279
+ var runValidation = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
280
+ var formElement, formIsValid, result, _t;
281
+ return _regenerator().w(function (_context) {
282
+ while (1) switch (_context.p = _context.n) {
283
+ 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
+ if (!(typeof (currentStepObj == null ? void 0 : currentStepObj.validate) !== 'function')) {
296
+ _context.n = 2;
297
+ break;
298
+ }
299
+ return _context.a(2, {
300
+ ok: true
301
+ });
302
+ case 2:
303
+ setIsValidating(true);
304
+ _context.p = 3;
305
+ _context.n = 4;
306
+ return currentStepObj.validate(formValue);
307
+ case 4:
308
+ result = _context.v;
309
+ setIsValidating(false);
310
+ if (!(result === true || result === undefined)) {
311
+ _context.n = 5;
312
+ break;
313
+ }
314
+ return _context.a(2, {
315
+ ok: true
316
+ });
317
+ case 5:
318
+ if (!(result === false)) {
319
+ _context.n = 6;
320
+ break;
321
+ }
322
+ return _context.a(2, {
323
+ ok: false,
324
+ error: format({
325
+ id: 'wizard.validationError',
326
+ messages: messages
327
+ })
328
+ });
329
+ case 6:
330
+ if (!(typeof result === 'string')) {
331
+ _context.n = 7;
332
+ break;
333
+ }
334
+ return _context.a(2, {
335
+ ok: false,
336
+ error: result
337
+ });
338
+ case 7:
339
+ if (!(typeof result === 'object' && result.error)) {
340
+ _context.n = 8;
341
+ break;
342
+ }
343
+ return _context.a(2, {
344
+ ok: false,
345
+ error: result.error
346
+ });
347
+ case 8:
348
+ return _context.a(2, {
349
+ ok: true
350
+ });
351
+ case 9:
352
+ _context.p = 9;
353
+ _t = _context.v;
354
+ setIsValidating(false);
355
+ return _context.a(2, {
356
+ ok: false,
357
+ error: (_t == null ? void 0 : _t.message) || format({
358
+ id: 'wizard.validationError',
359
+ messages: messages
360
+ })
361
+ });
362
+ }
363
+ }, _callee, null, [[3, 9]]);
364
+ })), [currentStep, currentStepObj, formValue, format, messages]);
365
+ var next = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
366
+ var _yield$runValidation, ok, error, nextId;
367
+ return _regenerator().w(function (_context2) {
368
+ while (1) switch (_context2.n) {
369
+ case 0:
370
+ if (!isValidating) {
371
+ _context2.n = 1;
372
+ break;
373
+ }
374
+ return _context2.a(2);
375
+ case 1:
376
+ emitStepChange({
377
+ trigger: 'next',
378
+ phase: 'requested',
379
+ from: currentStep
380
+ });
381
+ emitStepChange({
382
+ trigger: 'next',
383
+ phase: 'validating',
384
+ from: currentStep
385
+ });
386
+ _context2.n = 2;
387
+ return runValidation();
388
+ case 2:
389
+ _yield$runValidation = _context2.v;
390
+ ok = _yield$runValidation.ok;
391
+ error = _yield$runValidation.error;
392
+ if (ok) {
393
+ _context2.n = 3;
394
+ break;
395
+ }
396
+ setValidationError(error);
397
+ emitStepChange({
398
+ trigger: 'next',
399
+ phase: 'blocked',
400
+ from: currentStep,
401
+ error: error
402
+ });
403
+ return _context2.a(2);
404
+ case 3:
405
+ emitStepChange({
406
+ trigger: 'next',
407
+ phase: 'validated',
408
+ from: currentStep
409
+ });
410
+ nextId = resolveNextStepId();
411
+ if (nextId) {
412
+ _context2.n = 4;
413
+ break;
414
+ }
415
+ return _context2.a(2);
416
+ case 4:
417
+ applyTransition(nextId, {
418
+ markCompleted: true
419
+ });
420
+ emitStepChange({
421
+ trigger: 'next',
422
+ phase: 'navigated',
423
+ from: currentStep,
424
+ to: nextId
425
+ });
426
+ if (sendAnalytics) sendAnalytics({
427
+ type: 'wizardNext',
428
+ element: 'Wizard'
429
+ });
430
+ case 5:
431
+ return _context2.a(2);
432
+ }
433
+ }, _callee2);
434
+ })), [sendAnalytics, applyTransition, currentStep, emitStepChange, isValidating, resolveNextStepId, runValidation]);
435
+ var previous = useCallback(function () {
436
+ var _flatSteps;
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;
441
+ if (!dest) return;
442
+ setVisitedSteps(function (prev) {
443
+ return prev.slice(0, -1);
444
+ });
445
+ setValidationError(undefined);
446
+ if (!isControlled) setUncontrolledStep(dest);
447
+ emitStepChange({
448
+ trigger: 'previous',
449
+ phase: 'navigated',
450
+ from: currentStep,
451
+ to: dest
452
+ });
453
+ if (sendAnalytics) sendAnalytics({
454
+ type: 'wizardPrevious',
455
+ element: 'Wizard'
456
+ });
457
+ }, [sendAnalytics, currentStep, currentStepIndex, emitStepChange, flatSteps, isControlled, visitedSteps]);
458
+ var goTo = useCallback(/*#__PURE__*/function () {
459
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(stepId) {
460
+ var target, targetIndex, forward, _yield$runValidation2, ok, error;
461
+ return _regenerator().w(function (_context3) {
462
+ while (1) switch (_context3.n) {
463
+ case 0:
464
+ if (!(!stepId || stepId === currentStep)) {
465
+ _context3.n = 1;
466
+ break;
467
+ }
468
+ return _context3.a(2);
469
+ case 1:
470
+ target = findStepById(steps, stepId);
471
+ if (!(!target || target.disabled)) {
472
+ _context3.n = 2;
473
+ break;
474
+ }
475
+ return _context3.a(2);
476
+ case 2:
477
+ targetIndex = flatSteps.findIndex(function (step) {
478
+ return step.id === stepId;
479
+ });
480
+ forward = targetIndex > currentStepIndex;
481
+ emitStepChange({
482
+ trigger: 'goTo',
483
+ phase: 'requested',
484
+ from: currentStep,
485
+ to: stepId
486
+ });
487
+ if (!forward) {
488
+ _context3.n = 5;
489
+ break;
490
+ }
491
+ emitStepChange({
492
+ trigger: 'goTo',
493
+ phase: 'validating',
494
+ from: currentStep,
495
+ to: stepId
496
+ });
497
+ _context3.n = 3;
498
+ return runValidation();
499
+ case 3:
500
+ _yield$runValidation2 = _context3.v;
501
+ ok = _yield$runValidation2.ok;
502
+ error = _yield$runValidation2.error;
503
+ if (ok) {
504
+ _context3.n = 4;
505
+ break;
506
+ }
507
+ setValidationError(error);
508
+ emitStepChange({
509
+ trigger: 'goTo',
510
+ phase: 'blocked',
511
+ from: currentStep,
512
+ to: stepId,
513
+ error: error
514
+ });
515
+ return _context3.a(2);
516
+ case 4:
517
+ emitStepChange({
518
+ trigger: 'goTo',
519
+ phase: 'validated',
520
+ from: currentStep,
521
+ to: stepId
522
+ });
523
+ case 5:
524
+ applyTransition(stepId, {
525
+ markCompleted: forward
526
+ });
527
+ emitStepChange({
528
+ trigger: 'goTo',
529
+ phase: 'navigated',
530
+ from: currentStep,
531
+ to: stepId
532
+ });
533
+ case 6:
534
+ return _context3.a(2);
535
+ }
536
+ }, _callee3);
537
+ }));
538
+ return function (_x) {
539
+ return _ref5.apply(this, arguments);
540
+ };
541
+ }(), [applyTransition, currentStep, currentStepIndex, emitStepChange, flatSteps, runValidation, steps]);
542
+ var skip = useCallback(function () {
543
+ if (!(currentStepObj != null && currentStepObj.skippable)) return;
544
+ var nextId = resolveNextStepId();
545
+ if (!nextId) return;
546
+ // Skip: no validation, no completion.
547
+ setValidationError(undefined);
548
+ setVisitedSteps(function (prev) {
549
+ return [].concat(prev, [nextId]);
550
+ });
551
+ if (!isControlled) setUncontrolledStep(nextId);
552
+ emitStepChange({
553
+ trigger: 'skip',
554
+ phase: 'navigated',
555
+ from: currentStep,
556
+ to: nextId
557
+ });
558
+ if (sendAnalytics) sendAnalytics({
559
+ type: 'wizardSkip',
560
+ element: 'Wizard'
561
+ });
562
+ }, [sendAnalytics, currentStep, currentStepObj, emitStepChange, isControlled, resolveNextStepId]);
563
+ var complete = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
564
+ var _yield$runValidation3, ok, error, nextCompleted, completedStepsList;
565
+ return _regenerator().w(function (_context4) {
566
+ while (1) switch (_context4.n) {
567
+ case 0:
568
+ if (!isValidating) {
569
+ _context4.n = 1;
570
+ break;
571
+ }
572
+ return _context4.a(2);
573
+ case 1:
574
+ emitStepChange({
575
+ trigger: 'complete',
576
+ phase: 'requested',
577
+ from: currentStep
578
+ });
579
+ emitStepChange({
580
+ trigger: 'complete',
581
+ phase: 'validating',
582
+ from: currentStep
583
+ });
584
+ _context4.n = 2;
585
+ return runValidation();
586
+ case 2:
587
+ _yield$runValidation3 = _context4.v;
588
+ ok = _yield$runValidation3.ok;
589
+ error = _yield$runValidation3.error;
590
+ if (ok) {
591
+ _context4.n = 3;
592
+ break;
593
+ }
594
+ setValidationError(error);
595
+ emitStepChange({
596
+ trigger: 'complete',
597
+ phase: 'blocked',
598
+ from: currentStep,
599
+ error: error
600
+ });
601
+ return _context4.a(2);
602
+ case 3:
603
+ emitStepChange({
604
+ trigger: 'complete',
605
+ phase: 'validated',
606
+ from: currentStep
607
+ });
608
+ setCompletedSteps(function (prev) {
609
+ var nextCompleted = new Set(prev);
610
+ nextCompleted.add(currentStep);
611
+ return nextCompleted;
612
+ });
613
+ // Emit 'completed' before invoking onComplete.
614
+ emitStepChange({
615
+ trigger: 'complete',
616
+ phase: 'completed',
617
+ from: currentStep
618
+ });
619
+ 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
+ completedStepsList = Array.from(nextCompleted);
625
+ onComplete({
626
+ value: formValue,
627
+ completedSteps: completedStepsList
628
+ });
629
+ }
630
+ if (sendAnalytics) sendAnalytics({
631
+ type: 'wizardComplete',
632
+ element: 'Wizard'
633
+ });
634
+ case 4:
635
+ return _context4.a(2);
636
+ }
637
+ }, _callee4);
638
+ })), [sendAnalytics, completedSteps, currentStep, emitStepChange, formValue, isValidating, onComplete, runValidation]);
639
+ var cancel = useCallback(function () {
640
+ emitStepChange({
641
+ trigger: 'cancel',
642
+ phase: 'cancelled',
643
+ from: currentStep
644
+ });
645
+ if (onCancel) {
646
+ onCancel({
647
+ value: formValue,
648
+ reason: 'user'
649
+ });
650
+ } else {
651
+ // Self-close; parent must change `key` to remount.
652
+ setIsOpen(false);
653
+ }
654
+ if (sendAnalytics) sendAnalytics({
655
+ type: 'wizardCancel',
656
+ element: 'Wizard'
657
+ });
658
+ }, [sendAnalytics, currentStep, emitStepChange, formValue, onCancel]);
659
+
660
+ // Scroll to top on step transition: container, then ancestor, then window.
661
+ useLayoutEffect(function () {
662
+ var _wizardRef$current;
663
+ if (!scrollToTop) return;
664
+ // Focus the anchor rendered by WizardStepHeader so screen readers
665
+ // announce the new step. The anchor is located via a data attribute
666
+ // so composed layouts get the same behavior for free.
667
+ (_wizardRef$current = wizardRef.current) == null || (_wizardRef$current = _wizardRef$current.querySelector('[data-g-wizard-focus-anchor]')) == null || _wizardRef$current.focus({
668
+ preventScroll: true
669
+ });
670
+ var safeScrollTo = function safeScrollTo(target) {
671
+ if (!target || typeof target.scrollTo !== 'function') return;
672
+ try {
673
+ target.scrollTo({
674
+ top: 0,
675
+ behavior: 'auto'
676
+ });
677
+ } catch (_unused) {
678
+ // jsdom may throw on scrollTo; ignore.
679
+ }
680
+ };
681
+ var container = wizardRef.current;
682
+ safeScrollTo(container);
683
+ safeScrollTo(findScrollableAncestor(container));
684
+ if (typeof window !== 'undefined') safeScrollTo(window);
685
+ }, [currentStep, scrollToTop, wizardRef]);
686
+ var canGoNext = !(currentStepObj != null && currentStepObj.disabled) && !isValidating;
687
+ var isBlocked = !!validationError && !(currentStepObj != null && currentStepObj.skippable);
688
+ var isCompleted = completedSteps.has(currentStep);
689
+ var contextValue = useMemo(function () {
690
+ return {
691
+ steps: steps,
692
+ flatSteps: flatSteps,
693
+ currentStep: currentStep,
694
+ currentStepIndex: currentStepIndex,
695
+ currentStepObj: currentStepObj,
696
+ totalSteps: totalSteps,
697
+ stepStates: stepStates,
698
+ formValue: formValue,
699
+ setFormValue: setFormValue,
700
+ validationError: validationError,
701
+ isValidating: isValidating,
702
+ isBlocked: isBlocked,
703
+ isCompleted: isCompleted,
704
+ canGoNext: canGoNext,
705
+ next: next,
706
+ previous: previous,
707
+ goTo: goTo,
708
+ skip: skip,
709
+ complete: complete,
710
+ cancel: cancel,
711
+ hasCancelHandler: hasCancelHandler,
712
+ showProgress: effectiveShowProgress,
713
+ renderStep: renderStep,
714
+ // Internal only: `messages` is not part of the public
715
+ // WizardContextValue but is read by internal subcomponents
716
+ // (same pattern as `hasCancelHandler`).
717
+ messages: messages
718
+ };
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]);
720
+ if (!isOpen) return null;
721
+
722
+ // Custom composition: consumers supply their own tree via `children`.
723
+ var content = children;
724
+ if (!content) {
725
+ var _theme$wizard, _theme$wizard2;
726
+ var footerNode = footer != null ? footer : /*#__PURE__*/React.createElement(WizardFooter, null);
727
+ var bodyTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.body;
728
+
729
+ // Default layout: header + middle (progress + step body) + footer.
730
+ // Header/footer stay pinned; only WizardContent scrolls internally.
731
+ content = /*#__PURE__*/React.createElement(Box, _extends({}, (_theme$wizard2 = theme.wizard) == null ? void 0 : _theme$wizard2.container, {
732
+ flex: true
733
+ }), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(WizardHeader, {
734
+ title: title
735
+ }), /*#__PURE__*/React.createElement(Box, {
736
+ align: "center",
737
+ flex: {
738
+ grow: 1,
739
+ shrink: 1
740
+ },
741
+ fill: "horizontal",
742
+ overflow: "auto"
743
+ }, /*#__PURE__*/React.createElement(Box, {
744
+ pad: bodyTheme == null ? void 0 : bodyTheme.pad,
745
+ gap: bodyTheme == null ? void 0 : bodyTheme.gap,
746
+ flex: "grow",
747
+ fill: "horizontal",
748
+ direction: effectiveShowProgress === 'vertical' ? 'row' : 'column'
749
+ }, effectiveShowProgress && responsiveSize !== 'small' && responsiveSize !== 'xsmall' && /*#__PURE__*/React.createElement(WizardProgress, null), /*#__PURE__*/React.createElement(Box, {
750
+ flex: "grow"
751
+ }, /*#__PURE__*/React.createElement(WizardStepHeader, null), /*#__PURE__*/React.createElement(WizardContent, null)))), footerNode));
752
+ }
753
+ return /*#__PURE__*/React.createElement(WizardContext.Provider, {
754
+ value: contextValue
755
+ }, /*#__PURE__*/React.createElement(Box, _extends({
756
+ ref: wizardRef,
757
+ id: id,
758
+ "aria-label": ariaLabel,
759
+ role: "region",
760
+ flex: {
761
+ grow: 1,
762
+ shrink: 1
763
+ }
764
+ }, rest), content));
765
+ });
766
+ Wizard.displayName = 'Wizard';
767
+ Wizard.propTypes = WizardPropTypes;
768
+ export { Wizard };