@eifi1/ui-kit 0.7.0 → 0.8.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/README.md +32 -17
- package/dist/chart.d.ts +3 -2
- package/dist/components/alert-banner.d.ts +59 -10
- package/dist/components/alert-banner.js +114 -8
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +5 -0
- package/dist/components/button-group.d.ts +26 -0
- package/dist/components/button-group.js +49 -0
- package/dist/components/button-group.js.map +1 -0
- package/dist/components/calculator.d.ts +5 -0
- package/dist/components/chart-zoom.d.ts +63 -14
- package/dist/components/chart-zoom.js +82 -16
- package/dist/components/chart-zoom.js.map +1 -1
- package/dist/components/chip.d.ts +67 -2
- package/dist/components/chip.js +73 -8
- package/dist/components/chip.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +120 -0
- package/dist/components/confirm-dialog.js +96 -0
- package/dist/components/confirm-dialog.js.map +1 -0
- package/dist/components/copy-button.d.ts +62 -0
- package/dist/components/copy-button.js +95 -0
- package/dist/components/copy-button.js.map +1 -0
- package/dist/components/data-table-filter-popover.d.ts +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-pagination.d.ts +5 -1
- package/dist/components/data-table-pagination.js +71 -58
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table-sort.d.ts +28 -5
- package/dist/components/data-table-sort.js +11 -7
- package/dist/components/data-table-sort.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +544 -423
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +51 -5
- package/dist/components/date-picker.js +152 -40
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/description-list.d.ts +60 -0
- package/dist/components/description-list.js +112 -0
- package/dist/components/description-list.js.map +1 -0
- package/dist/components/disclosure.d.ts +37 -2
- package/dist/components/disclosure.js +14 -5
- package/dist/components/disclosure.js.map +1 -1
- package/dist/components/facing-pair.d.ts +2 -0
- package/dist/components/file-button.d.ts +19 -1
- package/dist/components/file-button.js +8 -1
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +56 -9
- package/dist/components/file-dropzone.js +100 -70
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/floating-panel.d.ts +107 -0
- package/dist/components/floating-panel.js +206 -0
- package/dist/components/floating-panel.js.map +1 -0
- package/dist/components/full-bleed-dialog.d.ts +12 -1
- package/dist/components/full-bleed-dialog.js +26 -5
- package/dist/components/full-bleed-dialog.js.map +1 -1
- package/dist/components/modal.d.ts +6 -2
- package/dist/components/modal.js +2 -1
- package/dist/components/modal.js.map +1 -1
- package/dist/components/number-field.d.ts +5 -0
- package/dist/components/number-input.d.ts +5 -0
- package/dist/components/numpad-sheet.d.ts +5 -0
- package/dist/components/progress-bar.d.ts +54 -0
- package/dist/components/progress-bar.js +94 -0
- package/dist/components/progress-bar.js.map +1 -0
- package/dist/components/scroll-area.d.ts +53 -0
- package/dist/components/scroll-area.js +86 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/separator.d.ts +23 -0
- package/dist/components/separator.js +24 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/series-chart-ticks.d.ts +34 -1
- package/dist/components/series-chart-ticks.js +83 -1
- package/dist/components/series-chart-ticks.js.map +1 -1
- package/dist/components/series-chart.d.ts +314 -19
- package/dist/components/series-chart.js +510 -120
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +2 -0
- package/dist/components/skeleton.d.ts +36 -0
- package/dist/components/skeleton.js +35 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/stat-tile.d.ts +60 -6
- package/dist/components/stat-tile.js +60 -26
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/table.d.ts +83 -0
- package/dist/components/table.js +166 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/time-input.d.ts +2 -0
- package/dist/components/toggle-legend.d.ts +3 -2
- package/dist/components/toggle-legend.js +1 -1
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/tooltip.d.ts +10 -4
- package/dist/components/tooltip.js +23 -6
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/tree-view.d.ts +129 -0
- package/dist/components/tree-view.js +376 -0
- package/dist/components/tree-view.js.map +1 -0
- package/dist/components/treemap.d.ts +9 -2
- package/dist/components/treemap.js +2 -1
- package/dist/components/treemap.js.map +1 -1
- package/dist/components/ui.d.ts +92 -14
- package/dist/components/ui.js +112 -30
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -1
- package/dist/{data-table-filters-noy0Abvi.d.ts → data-table-filters-CF1PXqjQ.d.ts} +73 -3
- package/dist/data-table.d.ts +2 -2
- package/dist/data-table.js.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +28 -0
- package/dist/hooks/use-copy-to-clipboard.js +81 -0
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
- package/dist/hooks/use-debounce.d.ts +43 -0
- package/dist/hooks/use-debounce.js +56 -0
- package/dist/hooks/use-debounce.js.map +1 -0
- package/dist/hooks/use-file-drop.d.ts +72 -0
- package/dist/hooks/use-file-drop.js +57 -0
- package/dist/hooks/use-file-drop.js.map +1 -0
- package/dist/i18n/defaults.d.ts +5 -0
- package/dist/i18n/defaults.js +7 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +17 -0
- package/dist/i18n/kit-labels.js +6 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +43 -0
- package/dist/i18n/locales/de-CH-informal.js +8 -0
- package/dist/i18n/locales/de-CH-informal.js.map +1 -0
- package/dist/i18n/locales/de-CH.d.ts +5 -0
- package/dist/i18n/locales/de-CH.js +1 -14
- package/dist/i18n/locales/de-CH.js.map +1 -1
- package/dist/i18n/locales/de-informal.d.ts +64 -0
- package/dist/i18n/locales/de-informal.js +37 -0
- package/dist/i18n/locales/de-informal.js.map +1 -0
- package/dist/i18n/locales/de.d.ts +5 -0
- package/dist/i18n/locales/de.js +25 -0
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +5 -0
- package/dist/i18n/locales/es.js +25 -0
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +5 -0
- package/dist/i18n/locales/fr.js +25 -0
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +5 -0
- package/dist/i18n/locales/hu.js +25 -0
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +5 -0
- package/dist/i18n/locales/it.js +25 -0
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +5 -0
- package/dist/i18n/locales/zh.js +25 -0
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/swiss.d.ts +13 -0
- package/dist/i18n/swiss.js +19 -0
- package/dist/i18n/swiss.js.map +1 -0
- package/dist/index.d.ts +26 -11
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/dates.d.ts +37 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/rhf/form.d.ts +2 -0
- package/dist/rhf.d.ts +2 -0
- package/dist/search/command-palette.d.ts +15 -1
- package/dist/search/command-palette.js +10 -2
- package/dist/search/command-palette.js.map +1 -1
- package/dist/shell/app-shell.js +2 -2
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +35 -2
- package/dist/wizard/stepper-nav.js +54 -22
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.d.ts +107 -5
- package/dist/wizard/types.js +2 -1
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.js +141 -21
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/wizard-summary.d.ts +10 -2
- package/dist/wizard/wizard-summary.js +3 -1
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/dist/wizard.d.ts +4 -1
- package/dist/wizard.js.map +1 -1
- package/package.json +1 -1
- package/src/components/alert-banner.tsx +211 -20
- package/src/components/button-group.tsx +75 -0
- package/src/components/chart-zoom.tsx +158 -20
- package/src/components/chip.tsx +160 -9
- package/src/components/confirm-dialog.tsx +242 -0
- package/src/components/copy-button.tsx +158 -0
- package/src/components/data-table-pagination.tsx +19 -6
- package/src/components/data-table-sort.ts +49 -10
- package/src/components/data-table.tsx +293 -24
- package/src/components/date-picker.tsx +262 -57
- package/src/components/description-list.tsx +174 -0
- package/src/components/disclosure.tsx +58 -5
- package/src/components/file-button.tsx +22 -2
- package/src/components/file-dropzone.tsx +198 -100
- package/src/components/floating-panel.tsx +341 -0
- package/src/components/full-bleed-dialog.tsx +48 -5
- package/src/components/modal.tsx +9 -2
- package/src/components/progress-bar.tsx +163 -0
- package/src/components/scroll-area.tsx +129 -0
- package/src/components/separator.tsx +37 -0
- package/src/components/series-chart-ticks.ts +135 -0
- package/src/components/series-chart.tsx +934 -67
- package/src/components/skeleton.tsx +65 -0
- package/src/components/stat-tile.tsx +160 -27
- package/src/components/table.tsx +263 -0
- package/src/components/toggle-legend.tsx +4 -3
- package/src/components/tooltip.tsx +40 -12
- package/src/components/tree-view.tsx +589 -0
- package/src/components/treemap.tsx +10 -2
- package/src/components/ui.tsx +268 -42
- package/src/data-table.ts +2 -0
- package/src/hooks/use-copy-to-clipboard.ts +122 -0
- package/src/hooks/use-debounce.ts +105 -0
- package/src/hooks/use-file-drop.ts +123 -0
- package/src/i18n/defaults.ts +6 -0
- package/src/i18n/kit-labels.tsx +19 -0
- package/src/i18n/locales/de-CH-informal.ts +10 -0
- package/src/i18n/locales/de-CH.ts +1 -16
- package/src/i18n/locales/de-informal.ts +61 -0
- package/src/i18n/locales/de.ts +25 -0
- package/src/i18n/locales/es.ts +25 -0
- package/src/i18n/locales/fr.ts +25 -0
- package/src/i18n/locales/hu.ts +25 -0
- package/src/i18n/locales/it.ts +25 -0
- package/src/i18n/locales/zh.ts +25 -0
- package/src/i18n/swiss.ts +25 -0
- package/src/index.ts +29 -0
- package/src/lib/dates.ts +48 -0
- package/src/search/command-palette.tsx +29 -3
- package/src/shell/app-shell.tsx +2 -2
- package/src/wizard/stepper-nav.tsx +102 -28
- package/src/wizard/types.ts +106 -4
- package/src/wizard/use-wizard.ts +211 -31
- package/src/wizard/wizard-summary.tsx +24 -12
- package/src/wizard.ts +3 -2
package/dist/wizard/types.d.ts
CHANGED
|
@@ -25,12 +25,83 @@ interface WizardStepConfig {
|
|
|
25
25
|
* per-field error messages via `wizard.fieldErrors`.
|
|
26
26
|
*/
|
|
27
27
|
validate?: () => ValidateResult | Promise<ValidateResult>;
|
|
28
|
+
/**
|
|
29
|
+
* The forward button's label on THIS step, in place of `labels.next` — "Analyse",
|
|
30
|
+
* "Import", "Send code". On the committing step (see {@link commits}) it labels
|
|
31
|
+
* Finish instead of `labels.finish`; `labels.submitting` still replaces it while
|
|
32
|
+
* the commit runs. Like `label`, a node the app has already translated.
|
|
33
|
+
*/
|
|
34
|
+
nextLabel?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* This step's forward button COMMITS: it runs `onComplete` (via `finish`) instead
|
|
37
|
+
* of just advancing. Without the flag the last step commits, as it always has.
|
|
38
|
+
*
|
|
39
|
+
* Flag a step before the last and every step after it becomes a post-commit step —
|
|
40
|
+
* an import's "here is what happened, set up recurring rules?" page:
|
|
41
|
+
* - a successful `onComplete` advances onto the next step (a failed one stays, with
|
|
42
|
+
* `wizard.error`, exactly like a last-step Finish);
|
|
43
|
+
* - from there Back, the indicator and `goBack`/`goToStep` cannot cross back over
|
|
44
|
+
* the commit, and Cancel is hidden — there is nothing left to discard;
|
|
45
|
+
* - the last post-commit step's button is Done, which calls `onDone` (and is not
|
|
46
|
+
* shown when there is no `onDone`: the step then carries its own way out).
|
|
47
|
+
*
|
|
48
|
+
* Only the FIRST flagged step counts. Steps after it may still validate, skip and
|
|
49
|
+
* use `nextLabel` like any other.
|
|
50
|
+
*/
|
|
51
|
+
commits?: boolean;
|
|
28
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Where the active step lives. `true` (the default) mirrors it to `?step=N` through
|
|
55
|
+
* react-router, as every wizard before 0.8 did; `{ param }` renames that param (two
|
|
56
|
+
* wizards on one page, or a page that already uses `step`); `false` keeps it in
|
|
57
|
+
* memory only and needs no router at all.
|
|
58
|
+
*
|
|
59
|
+
* Read once, at mount: switching it on a mounted wizard has no effect.
|
|
60
|
+
*/
|
|
61
|
+
type WizardUrlSync = boolean | {
|
|
62
|
+
param?: string;
|
|
63
|
+
};
|
|
29
64
|
interface UseWizardOptions<TData extends Record<string, unknown>> {
|
|
30
65
|
steps: WizardStepConfig[];
|
|
31
66
|
initialData?: Partial<TData>;
|
|
32
67
|
onComplete?: (data: TData) => void | Promise<void>;
|
|
33
68
|
onCancel?: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Leave the wizard BACKWARDS: when given, Back is shown on the first step too and
|
|
71
|
+
* calls this — keksdose's import panel, whose first step's Back returns to the
|
|
72
|
+
* dropzone the file came from. No confirm dialog: going back is not discarding.
|
|
73
|
+
*/
|
|
74
|
+
onExit?: () => void;
|
|
75
|
+
/**
|
|
76
|
+
* The Done button on the last step after a committing step (see
|
|
77
|
+
* {@link WizardStepConfig.commits}). Without it no Done button is rendered, and the
|
|
78
|
+
* post-commit step is expected to carry its own way out.
|
|
79
|
+
*/
|
|
80
|
+
onDone?: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Whether the chrome offers Cancel at all. Default `true`. `false` hides the button
|
|
83
|
+
* (`wizard.canCancel` is false); `wizard.cancel()` still works if the app calls it.
|
|
84
|
+
*/
|
|
85
|
+
cancellable?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Whether Cancel asks first ("Discard this form?"). Default `true`. `false` makes
|
|
88
|
+
* `cancel()` call `onCancel` straight away — for a wizard that has nothing to lose
|
|
89
|
+
* yet, or one whose data is kept elsewhere.
|
|
90
|
+
*/
|
|
91
|
+
confirmCancel?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Mirror the active step to the URL. Default `true` (`?step=N`, needs a router).
|
|
94
|
+
* See {@link WizardUrlSync}.
|
|
95
|
+
*
|
|
96
|
+
* The param is WRITTEN only, never read back (see the note in `use-wizard.ts`). It
|
|
97
|
+
* is removed again when the wizard is left through the kit: a confirmed Cancel,
|
|
98
|
+
* `onExit` from the first step's Back, and Done — each before the app's callback
|
|
99
|
+
* runs, so an app that navigates away navigates from a clean URL. It is NOT removed
|
|
100
|
+
* after `onComplete` on a last step: an app navigating away there would otherwise
|
|
101
|
+
* be pulled back by the kit's own URL write. An app that stays on the page after a
|
|
102
|
+
* final Finish drops the param itself, or uses `urlSync: false`.
|
|
103
|
+
*/
|
|
104
|
+
urlSync?: WizardUrlSync;
|
|
34
105
|
/**
|
|
35
106
|
* Shown when a step blocks with no per-field detail — an RHF step surfacing
|
|
36
107
|
* its own inline messages, say — so the user learns why the wizard did not
|
|
@@ -52,14 +123,35 @@ interface UseWizardReturn<TData extends Record<string, unknown>> {
|
|
|
52
123
|
steps: WizardStepConfig[];
|
|
53
124
|
isFirstStep: boolean;
|
|
54
125
|
isLastStep: boolean;
|
|
55
|
-
/** True once every step before the
|
|
126
|
+
/** True once every step before the committing one (the last, unless a step is
|
|
127
|
+
* flagged `commits`) has been completed or skipped. */
|
|
56
128
|
canFinish: boolean;
|
|
129
|
+
/** The step whose forward button commits: the first `commits` step, else the last. */
|
|
130
|
+
commitStepIndex: number;
|
|
131
|
+
/** The active step is {@link commitStepIndex}: the chrome shows Finish, not Next. */
|
|
132
|
+
isCommitStep: boolean;
|
|
133
|
+
/** `onComplete` has resolved. Once the active step is past the committing one, Back
|
|
134
|
+
* cannot cross it and Cancel is hidden. */
|
|
135
|
+
committed: boolean;
|
|
136
|
+
/** Whether Back is offered here: not on the first step unless `onExit` was given,
|
|
137
|
+
* and never back across a commit. (Disabled, not hidden, while `isSubmitting`.) */
|
|
138
|
+
canGoBack: boolean;
|
|
139
|
+
/** Whether Cancel is offered: `cancellable`, and not after a commit. */
|
|
140
|
+
canCancel: boolean;
|
|
141
|
+
/** Whether Done is offered: the last step, past a commit, with an `onDone`. */
|
|
142
|
+
canDone: boolean;
|
|
143
|
+
/** Whether the indicator may jump to `index` — a completed/skipped/active step on
|
|
144
|
+
* the right side of any commit. `goToStep` refuses anything this rejects. */
|
|
145
|
+
canGoToStep: (index: number) => boolean;
|
|
57
146
|
goNext: () => Promise<void>;
|
|
147
|
+
/** One step back — or, on the first step, `onExit`. Refused while submitting. */
|
|
58
148
|
goBack: () => void;
|
|
59
149
|
goToStep: (index: number) => void;
|
|
60
150
|
skip: () => void;
|
|
61
151
|
cancel: () => void;
|
|
62
152
|
finish: () => Promise<void>;
|
|
153
|
+
/** Leave after the post-commit steps: drops the URL param, then calls `onDone`. */
|
|
154
|
+
done: () => void;
|
|
63
155
|
/** Register a validator for the mounted step (used by useRhfWizardStep). */
|
|
64
156
|
registerStepValidate: (fn: () => ValidateResult | Promise<ValidateResult>) => () => void;
|
|
65
157
|
/** True when the mounted step has blocked forward navigation (Next/Skip disabled). */
|
|
@@ -71,6 +163,9 @@ interface UseWizardReturn<TData extends Record<string, unknown>> {
|
|
|
71
163
|
data: TData;
|
|
72
164
|
updateData: (partial: Partial<TData>) => void;
|
|
73
165
|
isSubmitting: boolean;
|
|
166
|
+
/** A `goNext`/`finish` is running the step's validators (an async server check,
|
|
167
|
+
* say). The chrome shows Next pending — spinner, `aria-busy`, disabled. */
|
|
168
|
+
isValidating: boolean;
|
|
74
169
|
error: string | null;
|
|
75
170
|
clearError: () => void;
|
|
76
171
|
fieldErrors: FieldErrors;
|
|
@@ -85,8 +180,12 @@ interface SummaryItem {
|
|
|
85
180
|
}
|
|
86
181
|
interface SummarySection {
|
|
87
182
|
label: ReactNode;
|
|
88
|
-
/**
|
|
89
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Which step the section's edit button jumps back to. Leave it out for a section
|
|
185
|
+
* that belongs to no step — file-level counts, a total — and the card has no edit
|
|
186
|
+
* button, instead of borrowing one from whichever step it was parked under.
|
|
187
|
+
*/
|
|
188
|
+
stepIndex?: number;
|
|
90
189
|
items: SummaryItem[];
|
|
91
190
|
}
|
|
92
191
|
/**
|
|
@@ -131,10 +230,13 @@ interface WizardLabels {
|
|
|
131
230
|
/** `wizard.error` when `onComplete` rejects with nothing readable — a thrown
|
|
132
231
|
* non-Error, or an Error whose message is empty. Optional: see above. */
|
|
133
232
|
genericError?: string;
|
|
233
|
+
/** The button on the last step after a committing step (`onDone`). Optional: see
|
|
234
|
+
* `missingRequired`. */
|
|
235
|
+
done?: string;
|
|
134
236
|
}
|
|
135
237
|
/** Typed with the two optional keys made required, so code reading the defaults
|
|
136
238
|
* directly (the fallback in `useWizard`) needs no `!`. */
|
|
137
|
-
declare const DEFAULT_WIZARD_LABELS: WizardLabels & Required<Pick<WizardLabels, "missingRequired" | "genericError">>;
|
|
239
|
+
declare const DEFAULT_WIZARD_LABELS: WizardLabels & Required<Pick<WizardLabels, "missingRequired" | "genericError" | "done">>;
|
|
138
240
|
declare function resolveWizardLabels(labels?: Partial<WizardLabels>): WizardLabels;
|
|
139
241
|
|
|
140
|
-
export { DEFAULT_WIZARD_LABELS, type FieldErrors, type StepStatus, type SummaryItem, type SummarySection, type UseWizardOptions, type UseWizardReturn, type ValidateResult, type WizardLabels, type WizardStepConfig, resolveWizardLabels };
|
|
242
|
+
export { DEFAULT_WIZARD_LABELS, type FieldErrors, type StepStatus, type SummaryItem, type SummarySection, type UseWizardOptions, type UseWizardReturn, type ValidateResult, type WizardLabels, type WizardStepConfig, type WizardUrlSync, resolveWizardLabels };
|
package/dist/wizard/types.js
CHANGED
|
@@ -15,7 +15,8 @@ const DEFAULT_WIZARD_LABELS = {
|
|
|
15
15
|
reviewTitle: "Review",
|
|
16
16
|
edit: "Edit",
|
|
17
17
|
missingRequired: "Please fill in all required fields.",
|
|
18
|
-
genericError: "An error occurred"
|
|
18
|
+
genericError: "An error occurred",
|
|
19
|
+
done: "Done"
|
|
19
20
|
};
|
|
20
21
|
function resolveWizardLabels(labels) {
|
|
21
22
|
return labels ? { ...DEFAULT_WIZARD_LABELS, ...labels } : DEFAULT_WIZARD_LABELS;
|
package/dist/wizard/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wizard/types.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nexport type FieldErrors = Record<string, string>;\n\nexport type ValidateResult = boolean | { ok: boolean; errors?: FieldErrors };\n\nexport interface WizardStepConfig {\n /** Unique step identifier. */\n id: string;\n /**\n * What the step is called in the indicator.\n *\n * A `ReactNode`, not a translation key: the engine never resolves strings.\n * An app with i18n maps its own keys at the `useWizard` call — the same split\n * `TourStep` and `DataTableLabels` already use.\n */\n label: ReactNode;\n /** Whether the step can be skipped. */\n optional?: boolean;\n /**\n * Validation gate before advancing.\n * - Return `true` / `false` to just block.\n * - Return `{ ok: false, errors: { fieldName: \"message\" } }` to also surface\n * per-field error messages via `wizard.fieldErrors`.\n */\n validate?: () => ValidateResult | Promise<ValidateResult>;\n}\n\nexport interface UseWizardOptions<TData extends Record<string, unknown>> {\n steps: WizardStepConfig[];\n initialData?: Partial<TData>;\n onComplete?: (data: TData) => void | Promise<void>;\n onCancel?: () => void;\n /**\n * Shown when a step blocks with no per-field detail — an RHF step surfacing\n * its own inline messages, say — so the user learns why the wizard did not\n * advance. Falls back to `wizard.missingRequired` from the {@link UiKitProvider},\n * then to English.\n */\n missingRequiredMessage?: string;\n /**\n * How to surface {@link missingRequiredMessage}. Defaults to a `sonner` toast\n * (an optional peer, imported only when this actually fires). Pass your own to\n * route it somewhere else, or to a no-op to silence it.\n */\n onValidationFailed?: (message: string) => void;\n}\n\nexport type StepStatus = \"upcoming\" | \"active\" | \"completed\" | \"skipped\";\n\nexport interface UseWizardReturn<TData extends Record<string, unknown>> {\n // Navigation\n currentStepIndex: number;\n currentStep: WizardStepConfig;\n steps: WizardStepConfig[];\n isFirstStep: boolean;\n isLastStep: boolean;\n /** True once every step before the last has been completed or skipped. */\n canFinish: boolean;\n goNext: () => Promise<void>;\n goBack: () => void;\n goToStep: (index: number) => void;\n skip: () => void;\n cancel: () => void;\n finish: () => Promise<void>;\n /** Register a validator for the mounted step (used by useRhfWizardStep). */\n registerStepValidate: (\n fn: () => ValidateResult | Promise<ValidateResult>,\n ) => () => void;\n /** True when the mounted step has blocked forward navigation (Next/Skip disabled). */\n nextBlocked: boolean;\n /** Set by the active step (via useWizardNextGate) to disable/enable Next+Skip. */\n setNextBlocked: (blocked: boolean) => void;\n\n // Step state\n stepStatus: (index: number) => StepStatus;\n completedSteps: Set<number>;\n\n // Data\n data: TData;\n updateData: (partial: Partial<TData>) => void;\n\n // Loading / error\n isSubmitting: boolean;\n error: string | null;\n clearError: () => void;\n\n // Per-field validation errors (populated by the last failed goNext)\n fieldErrors: FieldErrors;\n clearFieldErrors: () => void;\n\n // Cancel dialog\n showCancelDialog: boolean;\n confirmCancel: () => void;\n dismissCancel: () => void;\n}\n\nexport interface SummaryItem {\n label: ReactNode;\n value: ReactNode;\n}\n\nexport interface SummarySection {\n label: ReactNode;\n /** Which step the section's edit button jumps back to. */\n stepIndex: number;\n items: SummaryItem[];\n}\n\n/**\n * Every string the wizard chrome shows. All optional with English defaults, so a\n * monolingual app can mount `StepperNav` bare; a translated app passes the whole\n * object once (typically from a thin app-side wrapper).\n */\nexport interface WizardLabels {\n cancel: string;\n back: string;\n next: string;\n skip: string;\n finish: string;\n /** Shown on Finish while `isSubmitting`. */\n submitting: string;\n /** `aria-label` for the step indicator's `<nav>`. */\n steps: string;\n /** The mobile \"Step 2 of 5\" line. */\n step: (current: number, total: number) => string;\n /** Heading of the cancel-confirmation dialog. */\n cancelTitle: string;\n /** Body of the cancel-confirmation dialog. */\n confirmCancel: string;\n /** Confirm button in the cancel dialog. */\n cancelConfirmLabel: string;\n /** Dismiss button in the cancel dialog (\"keep editing\"). */\n cancelDismissLabel: string;\n /** Heading above a {@link WizardSummary}. */\n reviewTitle: string;\n /** `aria-label` on a summary section's edit button. */\n edit: string;\n /**\n * Toasted (or handed to `onValidationFailed`) when a step blocks Next without\n * saying which field is at fault. `useWizard`'s `missingRequiredMessage` wins.\n *\n * This and `genericError` are OPTIONAL, unlike every key above, for the reason\n * `TwoFactorSettingLabels.qrAlt` is: apps annotate a full translation as\n * `const DE: WizardLabels = {…}`, and a new required key would be a compile error\n * in each of them on the next update. The defaults below always carry both.\n */\n missingRequired?: string;\n /** `wizard.error` when `onComplete` rejects with nothing readable — a thrown\n * non-Error, or an Error whose message is empty. Optional: see above. */\n genericError?: string;\n}\n\n/** Typed with the two optional keys made required, so code reading the defaults\n * directly (the fallback in `useWizard`) needs no `!`. */\nexport const DEFAULT_WIZARD_LABELS: WizardLabels &\n Required<Pick<WizardLabels, \"missingRequired\" | \"genericError\">> = {\n cancel: \"Cancel\",\n back: \"Back\",\n next: \"Next\",\n skip: \"Skip\",\n finish: \"Finish\",\n submitting: \"Creating…\",\n steps: \"Steps\",\n step: (current, total) => `Step ${current} of ${total}`,\n cancelTitle: \"Discard this form?\",\n confirmCancel: \"Your entries will be lost.\",\n cancelConfirmLabel: \"Discard\",\n cancelDismissLabel: \"Keep editing\",\n reviewTitle: \"Review\",\n edit: \"Edit\",\n missingRequired: \"Please fill in all required fields.\",\n genericError: \"An error occurred\",\n};\n\nexport function resolveWizardLabels(labels?: Partial<WizardLabels>): WizardLabels {\n return labels ? { ...DEFAULT_WIZARD_LABELS, ...labels } : DEFAULT_WIZARD_LABELS;\n}\n"],"mappings":";AA2JO,MAAM,wBACwD;AAAA,EACnE,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,MAAM,CAAC,SAAS,UAAU,QAAQ,OAAO,OAAO,KAAK;AAAA,EACrD,aAAa;AAAA,EACb,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,cAAc;AAChB;AAEO,SAAS,oBAAoB,QAA8C;AAChF,SAAO,SAAS,EAAE,GAAG,uBAAuB,GAAG,OAAO,IAAI;AAC5D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/wizard/types.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nexport type FieldErrors = Record<string, string>;\n\nexport type ValidateResult = boolean | { ok: boolean; errors?: FieldErrors };\n\nexport interface WizardStepConfig {\n /** Unique step identifier. */\n id: string;\n /**\n * What the step is called in the indicator.\n *\n * A `ReactNode`, not a translation key: the engine never resolves strings.\n * An app with i18n maps its own keys at the `useWizard` call — the same split\n * `TourStep` and `DataTableLabels` already use.\n */\n label: ReactNode;\n /** Whether the step can be skipped. */\n optional?: boolean;\n /**\n * Validation gate before advancing.\n * - Return `true` / `false` to just block.\n * - Return `{ ok: false, errors: { fieldName: \"message\" } }` to also surface\n * per-field error messages via `wizard.fieldErrors`.\n */\n validate?: () => ValidateResult | Promise<ValidateResult>;\n /**\n * The forward button's label on THIS step, in place of `labels.next` — \"Analyse\",\n * \"Import\", \"Send code\". On the committing step (see {@link commits}) it labels\n * Finish instead of `labels.finish`; `labels.submitting` still replaces it while\n * the commit runs. Like `label`, a node the app has already translated.\n */\n nextLabel?: ReactNode;\n /**\n * This step's forward button COMMITS: it runs `onComplete` (via `finish`) instead\n * of just advancing. Without the flag the last step commits, as it always has.\n *\n * Flag a step before the last and every step after it becomes a post-commit step —\n * an import's \"here is what happened, set up recurring rules?\" page:\n * - a successful `onComplete` advances onto the next step (a failed one stays, with\n * `wizard.error`, exactly like a last-step Finish);\n * - from there Back, the indicator and `goBack`/`goToStep` cannot cross back over\n * the commit, and Cancel is hidden — there is nothing left to discard;\n * - the last post-commit step's button is Done, which calls `onDone` (and is not\n * shown when there is no `onDone`: the step then carries its own way out).\n *\n * Only the FIRST flagged step counts. Steps after it may still validate, skip and\n * use `nextLabel` like any other.\n */\n commits?: boolean;\n}\n\n/**\n * Where the active step lives. `true` (the default) mirrors it to `?step=N` through\n * react-router, as every wizard before 0.8 did; `{ param }` renames that param (two\n * wizards on one page, or a page that already uses `step`); `false` keeps it in\n * memory only and needs no router at all.\n *\n * Read once, at mount: switching it on a mounted wizard has no effect.\n */\nexport type WizardUrlSync = boolean | { param?: string };\n\nexport interface UseWizardOptions<TData extends Record<string, unknown>> {\n steps: WizardStepConfig[];\n initialData?: Partial<TData>;\n onComplete?: (data: TData) => void | Promise<void>;\n onCancel?: () => void;\n /**\n * Leave the wizard BACKWARDS: when given, Back is shown on the first step too and\n * calls this — keksdose's import panel, whose first step's Back returns to the\n * dropzone the file came from. No confirm dialog: going back is not discarding.\n */\n onExit?: () => void;\n /**\n * The Done button on the last step after a committing step (see\n * {@link WizardStepConfig.commits}). Without it no Done button is rendered, and the\n * post-commit step is expected to carry its own way out.\n */\n onDone?: () => void;\n /**\n * Whether the chrome offers Cancel at all. Default `true`. `false` hides the button\n * (`wizard.canCancel` is false); `wizard.cancel()` still works if the app calls it.\n */\n cancellable?: boolean;\n /**\n * Whether Cancel asks first (\"Discard this form?\"). Default `true`. `false` makes\n * `cancel()` call `onCancel` straight away — for a wizard that has nothing to lose\n * yet, or one whose data is kept elsewhere.\n */\n confirmCancel?: boolean;\n /**\n * Mirror the active step to the URL. Default `true` (`?step=N`, needs a router).\n * See {@link WizardUrlSync}.\n *\n * The param is WRITTEN only, never read back (see the note in `use-wizard.ts`). It\n * is removed again when the wizard is left through the kit: a confirmed Cancel,\n * `onExit` from the first step's Back, and Done — each before the app's callback\n * runs, so an app that navigates away navigates from a clean URL. It is NOT removed\n * after `onComplete` on a last step: an app navigating away there would otherwise\n * be pulled back by the kit's own URL write. An app that stays on the page after a\n * final Finish drops the param itself, or uses `urlSync: false`.\n */\n urlSync?: WizardUrlSync;\n /**\n * Shown when a step blocks with no per-field detail — an RHF step surfacing\n * its own inline messages, say — so the user learns why the wizard did not\n * advance. Falls back to `wizard.missingRequired` from the {@link UiKitProvider},\n * then to English.\n */\n missingRequiredMessage?: string;\n /**\n * How to surface {@link missingRequiredMessage}. Defaults to a `sonner` toast\n * (an optional peer, imported only when this actually fires). Pass your own to\n * route it somewhere else, or to a no-op to silence it.\n */\n onValidationFailed?: (message: string) => void;\n}\n\nexport type StepStatus = \"upcoming\" | \"active\" | \"completed\" | \"skipped\";\n\nexport interface UseWizardReturn<TData extends Record<string, unknown>> {\n // Navigation\n currentStepIndex: number;\n currentStep: WizardStepConfig;\n steps: WizardStepConfig[];\n isFirstStep: boolean;\n isLastStep: boolean;\n /** True once every step before the committing one (the last, unless a step is\n * flagged `commits`) has been completed or skipped. */\n canFinish: boolean;\n /** The step whose forward button commits: the first `commits` step, else the last. */\n commitStepIndex: number;\n /** The active step is {@link commitStepIndex}: the chrome shows Finish, not Next. */\n isCommitStep: boolean;\n /** `onComplete` has resolved. Once the active step is past the committing one, Back\n * cannot cross it and Cancel is hidden. */\n committed: boolean;\n /** Whether Back is offered here: not on the first step unless `onExit` was given,\n * and never back across a commit. (Disabled, not hidden, while `isSubmitting`.) */\n canGoBack: boolean;\n /** Whether Cancel is offered: `cancellable`, and not after a commit. */\n canCancel: boolean;\n /** Whether Done is offered: the last step, past a commit, with an `onDone`. */\n canDone: boolean;\n /** Whether the indicator may jump to `index` — a completed/skipped/active step on\n * the right side of any commit. `goToStep` refuses anything this rejects. */\n canGoToStep: (index: number) => boolean;\n goNext: () => Promise<void>;\n /** One step back — or, on the first step, `onExit`. Refused while submitting. */\n goBack: () => void;\n goToStep: (index: number) => void;\n skip: () => void;\n cancel: () => void;\n finish: () => Promise<void>;\n /** Leave after the post-commit steps: drops the URL param, then calls `onDone`. */\n done: () => void;\n /** Register a validator for the mounted step (used by useRhfWizardStep). */\n registerStepValidate: (\n fn: () => ValidateResult | Promise<ValidateResult>,\n ) => () => void;\n /** True when the mounted step has blocked forward navigation (Next/Skip disabled). */\n nextBlocked: boolean;\n /** Set by the active step (via useWizardNextGate) to disable/enable Next+Skip. */\n setNextBlocked: (blocked: boolean) => void;\n\n // Step state\n stepStatus: (index: number) => StepStatus;\n completedSteps: Set<number>;\n\n // Data\n data: TData;\n updateData: (partial: Partial<TData>) => void;\n\n // Loading / error\n isSubmitting: boolean;\n /** A `goNext`/`finish` is running the step's validators (an async server check,\n * say). The chrome shows Next pending — spinner, `aria-busy`, disabled. */\n isValidating: boolean;\n error: string | null;\n clearError: () => void;\n\n // Per-field validation errors (populated by the last failed goNext)\n fieldErrors: FieldErrors;\n clearFieldErrors: () => void;\n\n // Cancel dialog\n showCancelDialog: boolean;\n confirmCancel: () => void;\n dismissCancel: () => void;\n}\n\nexport interface SummaryItem {\n label: ReactNode;\n value: ReactNode;\n}\n\nexport interface SummarySection {\n label: ReactNode;\n /**\n * Which step the section's edit button jumps back to. Leave it out for a section\n * that belongs to no step — file-level counts, a total — and the card has no edit\n * button, instead of borrowing one from whichever step it was parked under.\n */\n stepIndex?: number;\n items: SummaryItem[];\n}\n\n/**\n * Every string the wizard chrome shows. All optional with English defaults, so a\n * monolingual app can mount `StepperNav` bare; a translated app passes the whole\n * object once (typically from a thin app-side wrapper).\n */\nexport interface WizardLabels {\n cancel: string;\n back: string;\n next: string;\n skip: string;\n finish: string;\n /** Shown on Finish while `isSubmitting`. */\n submitting: string;\n /** `aria-label` for the step indicator's `<nav>`. */\n steps: string;\n /** The mobile \"Step 2 of 5\" line. */\n step: (current: number, total: number) => string;\n /** Heading of the cancel-confirmation dialog. */\n cancelTitle: string;\n /** Body of the cancel-confirmation dialog. */\n confirmCancel: string;\n /** Confirm button in the cancel dialog. */\n cancelConfirmLabel: string;\n /** Dismiss button in the cancel dialog (\"keep editing\"). */\n cancelDismissLabel: string;\n /** Heading above a {@link WizardSummary}. */\n reviewTitle: string;\n /** `aria-label` on a summary section's edit button. */\n edit: string;\n /**\n * Toasted (or handed to `onValidationFailed`) when a step blocks Next without\n * saying which field is at fault. `useWizard`'s `missingRequiredMessage` wins.\n *\n * This and `genericError` are OPTIONAL, unlike every key above, for the reason\n * `TwoFactorSettingLabels.qrAlt` is: apps annotate a full translation as\n * `const DE: WizardLabels = {…}`, and a new required key would be a compile error\n * in each of them on the next update. The defaults below always carry both.\n */\n missingRequired?: string;\n /** `wizard.error` when `onComplete` rejects with nothing readable — a thrown\n * non-Error, or an Error whose message is empty. Optional: see above. */\n genericError?: string;\n /** The button on the last step after a committing step (`onDone`). Optional: see\n * `missingRequired`. */\n done?: string;\n}\n\n/** Typed with the two optional keys made required, so code reading the defaults\n * directly (the fallback in `useWizard`) needs no `!`. */\nexport const DEFAULT_WIZARD_LABELS: WizardLabels &\n Required<Pick<WizardLabels, \"missingRequired\" | \"genericError\" | \"done\">> = {\n cancel: \"Cancel\",\n back: \"Back\",\n next: \"Next\",\n skip: \"Skip\",\n finish: \"Finish\",\n submitting: \"Creating…\",\n steps: \"Steps\",\n step: (current, total) => `Step ${current} of ${total}`,\n cancelTitle: \"Discard this form?\",\n confirmCancel: \"Your entries will be lost.\",\n cancelConfirmLabel: \"Discard\",\n cancelDismissLabel: \"Keep editing\",\n reviewTitle: \"Review\",\n edit: \"Edit\",\n missingRequired: \"Please fill in all required fields.\",\n genericError: \"An error occurred\",\n done: \"Done\",\n};\n\nexport function resolveWizardLabels(labels?: Partial<WizardLabels>): WizardLabels {\n return labels ? { ...DEFAULT_WIZARD_LABELS, ...labels } : DEFAULT_WIZARD_LABELS;\n}\n"],"mappings":";AAgQO,MAAM,wBACiE;AAAA,EAC5E,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,MAAM,CAAC,SAAS,UAAU,QAAQ,OAAO,OAAO,KAAK;AAAA,EACrD,aAAa;AAAA,EACb,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,MAAM;AACR;AAEO,SAAS,oBAAoB,QAA8C;AAChF,SAAO,SAAS,EAAE,GAAG,uBAAuB,GAAG,OAAO,IAAI;AAC5D;","names":[]}
|
|
@@ -3,6 +3,12 @@ import { useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
|
3
3
|
import { useSearchParams } from "react-router";
|
|
4
4
|
import { useKitLabels } from "../i18n/kit-labels.js";
|
|
5
5
|
import { DEFAULT_WIZARD_LABELS } from "./types.js";
|
|
6
|
+
function isAfterCommit(state) {
|
|
7
|
+
return state.committedStepIndex !== null && state.currentStepIndex > state.committedStepIndex;
|
|
8
|
+
}
|
|
9
|
+
function crossesCommit(state, index) {
|
|
10
|
+
return isAfterCommit(state) && index <= state.committedStepIndex;
|
|
11
|
+
}
|
|
6
12
|
function createReducer(stepCount) {
|
|
7
13
|
return function reducer(state, action) {
|
|
8
14
|
switch (action.type) {
|
|
@@ -15,10 +21,12 @@ function createReducer(stepCount) {
|
|
|
15
21
|
}
|
|
16
22
|
case "GO_BACK": {
|
|
17
23
|
const prevIndex = Math.max(state.currentStepIndex - 1, 0);
|
|
24
|
+
if (crossesCommit(state, prevIndex)) return state;
|
|
18
25
|
return { ...state, currentStepIndex: prevIndex, fieldErrors: {} };
|
|
19
26
|
}
|
|
20
27
|
case "GO_TO_STEP": {
|
|
21
28
|
if (action.index < 0 || action.index >= stepCount) return state;
|
|
29
|
+
if (crossesCommit(state, action.index)) return state;
|
|
22
30
|
if (!state.completedSteps.has(action.index) && action.index > state.currentStepIndex) {
|
|
23
31
|
return state;
|
|
24
32
|
}
|
|
@@ -38,8 +46,24 @@ function createReducer(stepCount) {
|
|
|
38
46
|
}
|
|
39
47
|
return { ...state, data: { ...state.data, ...action.partial }, fieldErrors: nextErrors };
|
|
40
48
|
}
|
|
49
|
+
case "COMMITTED": {
|
|
50
|
+
const committed = { ...state, committedStepIndex: action.from };
|
|
51
|
+
if (action.from !== state.currentStepIndex || action.from >= stepCount - 1) {
|
|
52
|
+
return committed;
|
|
53
|
+
}
|
|
54
|
+
const completed = new Set(state.completedSteps);
|
|
55
|
+
completed.add(action.from);
|
|
56
|
+
return {
|
|
57
|
+
...committed,
|
|
58
|
+
currentStepIndex: action.from + 1,
|
|
59
|
+
completedSteps: completed,
|
|
60
|
+
fieldErrors: {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
41
63
|
case "SET_SUBMITTING":
|
|
42
64
|
return { ...state, isSubmitting: action.value };
|
|
65
|
+
case "SET_VALIDATING":
|
|
66
|
+
return { ...state, isValidating: action.value };
|
|
43
67
|
case "SET_ERROR":
|
|
44
68
|
return { ...state, error: action.error };
|
|
45
69
|
case "SET_FIELD_ERRORS":
|
|
@@ -52,7 +76,19 @@ function createReducer(stepCount) {
|
|
|
52
76
|
};
|
|
53
77
|
}
|
|
54
78
|
function useWizard(options) {
|
|
55
|
-
const {
|
|
79
|
+
const {
|
|
80
|
+
steps,
|
|
81
|
+
initialData,
|
|
82
|
+
onComplete,
|
|
83
|
+
onCancel,
|
|
84
|
+
onExit,
|
|
85
|
+
onDone,
|
|
86
|
+
cancellable = true,
|
|
87
|
+
confirmCancel: askBeforeCancel = true,
|
|
88
|
+
urlSync = true,
|
|
89
|
+
missingRequiredMessage,
|
|
90
|
+
onValidationFailed
|
|
91
|
+
} = options;
|
|
56
92
|
const stepsRef = useRef(steps);
|
|
57
93
|
stepsRef.current = steps;
|
|
58
94
|
const wizardLabels = useKitLabels("wizard", DEFAULT_WIZARD_LABELS, {
|
|
@@ -73,7 +109,10 @@ function useWizard(options) {
|
|
|
73
109
|
},
|
|
74
110
|
[]
|
|
75
111
|
);
|
|
76
|
-
const [
|
|
112
|
+
const [useStepUrl] = useState(() => urlSync === false ? useNoStepUrl : useSearchParamStepUrl);
|
|
113
|
+
const [urlParam] = useState(
|
|
114
|
+
() => typeof urlSync === "object" && urlSync.param ? urlSync.param : "step"
|
|
115
|
+
);
|
|
77
116
|
const initialStep = 0;
|
|
78
117
|
const reducer = createReducer(steps.length);
|
|
79
118
|
const [state, dispatch] = useReducer(reducer, {
|
|
@@ -82,27 +121,31 @@ function useWizard(options) {
|
|
|
82
121
|
skippedSteps: /* @__PURE__ */ new Set(),
|
|
83
122
|
data: initialData ?? {},
|
|
84
123
|
isSubmitting: false,
|
|
124
|
+
isValidating: false,
|
|
85
125
|
error: null,
|
|
86
126
|
fieldErrors: {},
|
|
87
|
-
showCancelDialog: false
|
|
127
|
+
showCancelDialog: false,
|
|
128
|
+
committedStepIndex: null
|
|
88
129
|
});
|
|
89
130
|
const [nextBlocked, setNextBlockedState] = useState(false);
|
|
90
131
|
const setNextBlocked = useCallback(
|
|
91
132
|
(blocked) => setNextBlockedState(blocked),
|
|
92
133
|
[]
|
|
93
134
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
prev.set("step", String(state.currentStepIndex));
|
|
97
|
-
return prev;
|
|
98
|
-
}, { replace: true });
|
|
99
|
-
}, [state.currentStepIndex, setUrlParams]);
|
|
100
|
-
const currentStep = stepsRef.current[state.currentStepIndex];
|
|
135
|
+
const clearStepUrl = useStepUrl(urlParam, state.currentStepIndex);
|
|
136
|
+
const currentStep = steps[state.currentStepIndex];
|
|
101
137
|
const isFirstStep = state.currentStepIndex === 0;
|
|
102
|
-
const isLastStep = state.currentStepIndex ===
|
|
103
|
-
const
|
|
104
|
-
|
|
138
|
+
const isLastStep = state.currentStepIndex === steps.length - 1;
|
|
139
|
+
const flagged = steps.findIndex((s) => s.commits);
|
|
140
|
+
const commitStepIndex = flagged === -1 ? steps.length - 1 : flagged;
|
|
141
|
+
const isCommitStep = state.currentStepIndex === commitStepIndex;
|
|
142
|
+
const afterCommit = isAfterCommit(state);
|
|
143
|
+
const canFinish = steps.every(
|
|
144
|
+
(_, index) => index >= commitStepIndex || state.completedSteps.has(index) || state.skippedSteps.has(index)
|
|
105
145
|
);
|
|
146
|
+
const canGoBack = (!isFirstStep || onExit !== void 0) && !crossesCommit(state, state.currentStepIndex - 1);
|
|
147
|
+
const canCancel = cancellable && !afterCommit;
|
|
148
|
+
const canDone = isLastStep && afterCommit && onDone !== void 0;
|
|
106
149
|
const runStepValidators = useCallback(async () => {
|
|
107
150
|
const step = stepsRef.current[state.currentStepIndex];
|
|
108
151
|
const validators = [...validatorsRef.current.values()];
|
|
@@ -145,31 +188,53 @@ function useWizard(options) {
|
|
|
145
188
|
if (advancingRef.current) return;
|
|
146
189
|
advancingRef.current = true;
|
|
147
190
|
const from = state.currentStepIndex;
|
|
191
|
+
dispatch({ type: "SET_VALIDATING", value: true });
|
|
148
192
|
try {
|
|
149
193
|
if (await runStepValidators()) {
|
|
150
194
|
dispatch({ type: "GO_NEXT", from });
|
|
151
195
|
}
|
|
152
196
|
} finally {
|
|
197
|
+
dispatch({ type: "SET_VALIDATING", value: false });
|
|
153
198
|
advancingRef.current = false;
|
|
154
199
|
}
|
|
155
200
|
}, [runStepValidators, state.currentStepIndex]);
|
|
201
|
+
const submittingRef = useRef(false);
|
|
156
202
|
const goBack = useCallback(() => {
|
|
203
|
+
if (submittingRef.current) return;
|
|
204
|
+
if (state.currentStepIndex === 0 && onExit) {
|
|
205
|
+
clearStepUrl();
|
|
206
|
+
onExit();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
157
209
|
dispatch({ type: "GO_BACK" });
|
|
158
|
-
}, []);
|
|
210
|
+
}, [state.currentStepIndex, onExit, clearStepUrl]);
|
|
159
211
|
const goToStep = useCallback((index) => {
|
|
160
212
|
dispatch({ type: "GO_TO_STEP", index });
|
|
161
213
|
}, []);
|
|
214
|
+
const canGoToStep = useCallback(
|
|
215
|
+
(index) => index >= 0 && index < steps.length && (index <= state.currentStepIndex || state.completedSteps.has(index)) && !crossesCommit(state, index),
|
|
216
|
+
[steps.length, state]
|
|
217
|
+
);
|
|
162
218
|
const skip = useCallback(() => {
|
|
163
219
|
if (advancingRef.current) return;
|
|
164
220
|
dispatch({ type: "SKIP", from: state.currentStepIndex });
|
|
165
221
|
}, [state.currentStepIndex]);
|
|
166
|
-
const cancel = useCallback(() => {
|
|
167
|
-
dispatch({ type: "SHOW_CANCEL_DIALOG", show: true });
|
|
168
|
-
}, []);
|
|
169
222
|
const confirmCancel = useCallback(() => {
|
|
170
223
|
dispatch({ type: "SHOW_CANCEL_DIALOG", show: false });
|
|
224
|
+
clearStepUrl();
|
|
171
225
|
onCancel?.();
|
|
172
|
-
}, [onCancel]);
|
|
226
|
+
}, [onCancel, clearStepUrl]);
|
|
227
|
+
const cancel = useCallback(() => {
|
|
228
|
+
if (!askBeforeCancel) {
|
|
229
|
+
confirmCancel();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
dispatch({ type: "SHOW_CANCEL_DIALOG", show: true });
|
|
233
|
+
}, [askBeforeCancel, confirmCancel]);
|
|
234
|
+
const done = useCallback(() => {
|
|
235
|
+
clearStepUrl();
|
|
236
|
+
onDone?.();
|
|
237
|
+
}, [onDone, clearStepUrl]);
|
|
173
238
|
const dismissCancel = useCallback(() => {
|
|
174
239
|
dispatch({ type: "SHOW_CANCEL_DIALOG", show: false });
|
|
175
240
|
}, []);
|
|
@@ -184,24 +249,46 @@ function useWizard(options) {
|
|
|
184
249
|
}, []);
|
|
185
250
|
const finish = useCallback(async () => {
|
|
186
251
|
if (!onComplete || !canFinish) return;
|
|
252
|
+
if (commitStepIndex < steps.length - 1 && state.committedStepIndex !== null) return;
|
|
187
253
|
if (advancingRef.current) return;
|
|
188
254
|
advancingRef.current = true;
|
|
255
|
+
const from = state.currentStepIndex;
|
|
189
256
|
try {
|
|
190
|
-
|
|
257
|
+
dispatch({ type: "SET_VALIDATING", value: true });
|
|
258
|
+
let valid;
|
|
259
|
+
try {
|
|
260
|
+
valid = await runStepValidators();
|
|
261
|
+
} finally {
|
|
262
|
+
dispatch({ type: "SET_VALIDATING", value: false });
|
|
263
|
+
}
|
|
264
|
+
if (!valid) return;
|
|
265
|
+
submittingRef.current = true;
|
|
191
266
|
dispatch({ type: "SET_SUBMITTING", value: true });
|
|
192
267
|
dispatch({ type: "SET_ERROR", error: null });
|
|
193
268
|
try {
|
|
194
269
|
await onComplete(state.data);
|
|
270
|
+
dispatch({ type: "COMMITTED", from });
|
|
195
271
|
} catch (err) {
|
|
196
272
|
const message = err instanceof Error && err.message ? err.message : genericError;
|
|
197
273
|
dispatch({ type: "SET_ERROR", error: message });
|
|
198
274
|
} finally {
|
|
275
|
+
submittingRef.current = false;
|
|
199
276
|
dispatch({ type: "SET_SUBMITTING", value: false });
|
|
200
277
|
}
|
|
201
278
|
} finally {
|
|
202
279
|
advancingRef.current = false;
|
|
203
280
|
}
|
|
204
|
-
}, [
|
|
281
|
+
}, [
|
|
282
|
+
onComplete,
|
|
283
|
+
canFinish,
|
|
284
|
+
commitStepIndex,
|
|
285
|
+
steps.length,
|
|
286
|
+
state.committedStepIndex,
|
|
287
|
+
state.currentStepIndex,
|
|
288
|
+
state.data,
|
|
289
|
+
runStepValidators,
|
|
290
|
+
genericError
|
|
291
|
+
]);
|
|
205
292
|
const stepStatus = useCallback(
|
|
206
293
|
(index) => {
|
|
207
294
|
if (index === state.currentStepIndex) return "active";
|
|
@@ -214,16 +301,24 @@ function useWizard(options) {
|
|
|
214
301
|
return {
|
|
215
302
|
currentStepIndex: state.currentStepIndex,
|
|
216
303
|
currentStep,
|
|
217
|
-
steps
|
|
304
|
+
steps,
|
|
218
305
|
isFirstStep,
|
|
219
306
|
isLastStep,
|
|
220
307
|
canFinish,
|
|
308
|
+
commitStepIndex,
|
|
309
|
+
isCommitStep,
|
|
310
|
+
committed: state.committedStepIndex !== null,
|
|
311
|
+
canGoBack,
|
|
312
|
+
canCancel,
|
|
313
|
+
canDone,
|
|
314
|
+
canGoToStep,
|
|
221
315
|
goNext,
|
|
222
316
|
goBack,
|
|
223
317
|
goToStep,
|
|
224
318
|
skip,
|
|
225
319
|
cancel,
|
|
226
320
|
finish,
|
|
321
|
+
done,
|
|
227
322
|
registerStepValidate,
|
|
228
323
|
nextBlocked,
|
|
229
324
|
setNextBlocked,
|
|
@@ -232,6 +327,7 @@ function useWizard(options) {
|
|
|
232
327
|
data: state.data,
|
|
233
328
|
updateData,
|
|
234
329
|
isSubmitting: state.isSubmitting,
|
|
330
|
+
isValidating: state.isValidating,
|
|
235
331
|
error: state.error,
|
|
236
332
|
clearError,
|
|
237
333
|
fieldErrors: state.fieldErrors,
|
|
@@ -241,6 +337,30 @@ function useWizard(options) {
|
|
|
241
337
|
dismissCancel
|
|
242
338
|
};
|
|
243
339
|
}
|
|
340
|
+
function useSearchParamStepUrl(param, index) {
|
|
341
|
+
const [, setUrlParams] = useSearchParams();
|
|
342
|
+
const leftRef = useRef(false);
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
if (leftRef.current) return;
|
|
345
|
+
setUrlParams((prev) => {
|
|
346
|
+
prev.set(param, String(index));
|
|
347
|
+
return prev;
|
|
348
|
+
}, { replace: true });
|
|
349
|
+
}, [param, index, setUrlParams]);
|
|
350
|
+
return useCallback(() => {
|
|
351
|
+
if (leftRef.current) return;
|
|
352
|
+
leftRef.current = true;
|
|
353
|
+
setUrlParams((prev) => {
|
|
354
|
+
prev.delete(param);
|
|
355
|
+
return prev;
|
|
356
|
+
}, { replace: true });
|
|
357
|
+
}, [param, setUrlParams]);
|
|
358
|
+
}
|
|
359
|
+
function useNoStepUrl(_param, _index) {
|
|
360
|
+
return noop;
|
|
361
|
+
}
|
|
362
|
+
function noop() {
|
|
363
|
+
}
|
|
244
364
|
export {
|
|
245
365
|
useWizard
|
|
246
366
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wizard/use-wizard.ts"],"sourcesContent":["/**\n * The multi-step wizard state machine: step index, completed/skipped sets,\n * per-step async validators, collected data, field errors, submit and the\n * cancel-confirm gate.\n *\n * Domain-free, but NOT router-free: it mirrors the active step to `?step=N`, so\n * it must be mounted inside a react-router context — the same requirement\n * `DataTable` already carries. It only ever WRITES that param (see the note on\n * `initialStep` below for why it deliberately does not read it back).\n */\nimport { useCallback, useEffect, useReducer, useRef, useState } from \"react\";\nimport { useSearchParams } from \"react-router\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_WIZARD_LABELS } from \"./types\";\nimport type {\n FieldErrors,\n StepStatus,\n UseWizardOptions,\n UseWizardReturn,\n ValidateResult,\n WizardStepConfig,\n} from \"./types\";\n\ninterface WizardState<TData> {\n currentStepIndex: number;\n completedSteps: Set<number>;\n skippedSteps: Set<number>;\n data: TData;\n isSubmitting: boolean;\n error: string | null;\n fieldErrors: FieldErrors;\n showCancelDialog: boolean;\n}\n\ntype WizardAction<TData> =\n // `from` is the step the move was decided ON. A move whose step is no longer the\n // current one is stale — see `goNext` — and is dropped rather than applied relative\n // to wherever the wizard has got to since.\n | { type: \"GO_NEXT\"; from: number }\n | { type: \"GO_BACK\" }\n | { type: \"GO_TO_STEP\"; index: number }\n | { type: \"SKIP\"; from: number }\n | { type: \"UPDATE_DATA\"; partial: Partial<TData> }\n | { type: \"SET_SUBMITTING\"; value: boolean }\n | { type: \"SET_ERROR\"; error: string | null }\n | { type: \"SET_FIELD_ERRORS\"; errors: FieldErrors }\n | { type: \"SHOW_CANCEL_DIALOG\"; show: boolean };\n\nfunction createReducer<TData>(stepCount: number) {\n return function reducer(\n state: WizardState<TData>,\n action: WizardAction<TData>,\n ): WizardState<TData> {\n switch (action.type) {\n case \"GO_NEXT\": {\n if (action.from !== state.currentStepIndex) return state;\n const completed = new Set(state.completedSteps);\n completed.add(state.currentStepIndex);\n const nextIndex = Math.min(state.currentStepIndex + 1, stepCount - 1);\n return { ...state, currentStepIndex: nextIndex, completedSteps: completed, fieldErrors: {} };\n }\n case \"GO_BACK\": {\n const prevIndex = Math.max(state.currentStepIndex - 1, 0);\n return { ...state, currentStepIndex: prevIndex, fieldErrors: {} };\n }\n case \"GO_TO_STEP\": {\n if (action.index < 0 || action.index >= stepCount) return state;\n if (!state.completedSteps.has(action.index) && action.index > state.currentStepIndex) {\n return state;\n }\n return { ...state, currentStepIndex: action.index };\n }\n case \"SKIP\": {\n if (action.from !== state.currentStepIndex) return state;\n const skipped = new Set(state.skippedSteps);\n skipped.add(state.currentStepIndex);\n const nextIndex = Math.min(state.currentStepIndex + 1, stepCount - 1);\n return { ...state, currentStepIndex: nextIndex, skippedSteps: skipped };\n }\n case \"UPDATE_DATA\": {\n // Clear error for any field that is now being edited (so typing makes\n // the red message disappear).\n const nextErrors = { ...state.fieldErrors };\n for (const key of Object.keys(action.partial)) {\n delete nextErrors[key];\n }\n return { ...state, data: { ...state.data, ...action.partial }, fieldErrors: nextErrors };\n }\n case \"SET_SUBMITTING\":\n return { ...state, isSubmitting: action.value };\n case \"SET_ERROR\":\n return { ...state, error: action.error };\n case \"SET_FIELD_ERRORS\":\n return { ...state, fieldErrors: action.errors };\n case \"SHOW_CANCEL_DIALOG\":\n return { ...state, showCancelDialog: action.show };\n default:\n return state;\n }\n };\n}\n\nexport function useWizard<TData extends Record<string, unknown>>(\n options: UseWizardOptions<TData>,\n): UseWizardReturn<TData> {\n const { steps, initialData, onComplete, onCancel, missingRequiredMessage, onValidationFailed } =\n options;\n const stepsRef = useRef<WizardStepConfig[]>(steps);\n stepsRef.current = steps;\n // A hook, not a component, but it produces two sentences of its own — the\n // \"fill in the required fields\" toast and the fallback submit error — and both\n // reach the user. So it reads the provider like any component does; only the two\n // strings are depended on below, so the callbacks stay stable across renders.\n // The `??` is for the type only: both keys are optional on `WizardLabels` (see\n // there), and the merge never replaces a default with `undefined`.\n const wizardLabels = useKitLabels(\"wizard\", DEFAULT_WIZARD_LABELS, {\n missingRequired: missingRequiredMessage,\n });\n const missingRequired = wizardLabels.missingRequired ?? DEFAULT_WIZARD_LABELS.missingRequired;\n const genericError = wizardLabels.genericError ?? DEFAULT_WIZARD_LABELS.genericError;\n\n // Validators registered by the CURRENT step's mounted components (RHF steps\n // register via `useRhfWizardStep` through the wizard context). Only the active\n // step's validators are present — each unregisters on unmount. `goNext` and\n // `finish` run them (via `runStepValidators`) alongside the step config's own\n // `validate`.\n const validatorsRef = useRef(\n new Map<symbol, () => ValidateResult | Promise<ValidateResult>>(),\n );\n const registerStepValidate = useCallback(\n (fn: () => ValidateResult | Promise<ValidateResult>) => {\n const token = Symbol();\n validatorsRef.current.set(token, fn);\n return () => {\n validatorsRef.current.delete(token);\n };\n },\n [],\n );\n\n const [, setUrlParams] = useSearchParams();\n // The wizard's entered `data` and `completedSteps` are NOT persisted across a\n // reload / deep-link (the reducer re-inits to empty defaults on every mount).\n // Restoring a later step index from `?step=N` would therefore leave the wizard\n // on (or past) the last step with an EMPTY data set, letting Finish submit an\n // empty payload. Always start at step 0 so a reload re-runs the wizard from a\n // valid state instead of losing the entered data silently.\n const initialStep = 0;\n\n const reducer = createReducer<TData>(steps.length);\n const [state, dispatch] = useReducer(reducer, {\n currentStepIndex: initialStep,\n completedSteps: new Set<number>(),\n skippedSteps: new Set<number>(),\n data: (initialData ?? {}) as TData,\n isSubmitting: false,\n error: null,\n fieldErrors: {},\n showCancelDialog: false,\n });\n\n // A mounted step can DISABLE forward navigation (Next/Skip) while its own\n // state is invalid (e.g. tenant shares != 100%). Defaults to false, so\n // wizards that never call setNextBlocked behave exactly as before.\n const [nextBlocked, setNextBlockedState] = useState(false);\n const setNextBlocked = useCallback(\n (blocked: boolean) => setNextBlockedState(blocked),\n [],\n );\n\n // Sync step index to URL\n useEffect(() => {\n setUrlParams((prev) => {\n prev.set(\"step\", String(state.currentStepIndex));\n return prev;\n }, { replace: true });\n }, [state.currentStepIndex, setUrlParams]);\n\n const currentStep = stepsRef.current[state.currentStepIndex];\n const isFirstStep = state.currentStepIndex === 0;\n const isLastStep = state.currentStepIndex === stepsRef.current.length - 1;\n // Finish is only valid once every step before the last has actually been\n // walked through (completed or skipped). Guards against a restored/last-step\n // index submitting a payload built from empty defaults.\n const canFinish = stepsRef.current.every(\n (_, index) =>\n index === stepsRef.current.length - 1 ||\n state.completedSteps.has(index) ||\n state.skippedSteps.has(index),\n );\n\n // Runs the active step's config `validate` plus every validator its mounted\n // components registered (RHF steps via useRhfWizardStep), AND-combining the\n // results and merging any per-field errors. Returns `true` when the step\n // passes (or registered no validators). Shared by `goNext` and `finish` so a\n // form-bearing last step is validated (and its values flushed) on Finish too.\n const runStepValidators = useCallback(async (): Promise<boolean> => {\n const step = stepsRef.current[state.currentStepIndex];\n const validators = [...validatorsRef.current.values()];\n if (step.validate) validators.push(step.validate);\n if (validators.length === 0) return true;\n let ok = true;\n let errors: FieldErrors = {};\n try {\n for (const validate of validators) {\n const result = await validate();\n const vOk = typeof result === \"boolean\" ? result : result.ok;\n if (!vOk) {\n ok = false;\n if (typeof result !== \"boolean\" && result.errors) {\n errors = { ...errors, ...result.errors };\n }\n }\n }\n } catch (err) {\n // FALL THROUGH, do not return. A bare `return false` here blocked Next while\n // skipping the `if (!ok)` block below — the only thing that shows a message,\n // and whose own comment is \"say something anyway, so the user is not left with\n // a Next button that silently does nothing\". So a validator that threw (an\n // async one whose request rejected, a null dereference in a field rule)\n // produced exactly the outcome that block was written to prevent: no field\n // errors, no toast, `onValidationFailed` never called, nothing in the console.\n //\n // The step still must not advance; `ok = false` is what says so. Whatever\n // partial `errors` the loop had collected before the throw are kept — they are\n // real, and an empty set is what routes this to the generic message.\n console.error(\"[wizard] a step validator threw\", err);\n ok = false;\n }\n if (!ok) {\n dispatch({ type: \"SET_FIELD_ERRORS\", errors });\n if (Object.keys(errors).length === 0) {\n // No per-field detail (e.g. an RHF step surfacing its own inline\n // message) — say something anyway, so the user is not left with a Next\n // button that silently does nothing.\n const message = missingRequired;\n if (onValidationFailed) {\n onValidationFailed(message);\n } else {\n // sonner is an optional peer: imported here, on the failure path only,\n // so an app that never trips this never has to install it.\n const { toast } = await import(\"sonner\");\n toast.error(message);\n }\n }\n return false;\n }\n return true;\n }, [state.currentStepIndex, missingRequired, onValidationFailed]);\n\n /**\n * One forward move at a time. A double-click on Next used to validate the CURRENT\n * step twice and then advance twice — the second GO_NEXT landing on a step whose\n * own validators never ran, so a required field two steps in could be walked past.\n * Two layers, because either alone leaves a gap:\n *\n * - this ref refuses a second `goNext`/`skip`/`finish` while one is in flight,\n * which covers an async validator (a server check) of any length;\n * - the `from` on each action drops a move decided on a step that is no longer\n * current, which covers the click that arrives after the first move resolved\n * but before React re-rendered — its closure still holds the old step index.\n */\n const advancingRef = useRef(false);\n\n const goNext = useCallback(async () => {\n if (advancingRef.current) return;\n advancingRef.current = true;\n const from = state.currentStepIndex;\n try {\n if (await runStepValidators()) {\n dispatch({ type: \"GO_NEXT\", from });\n }\n } finally {\n advancingRef.current = false;\n }\n }, [runStepValidators, state.currentStepIndex]);\n\n const goBack = useCallback(() => {\n dispatch({ type: \"GO_BACK\" });\n }, []);\n\n const goToStep = useCallback((index: number) => {\n dispatch({ type: \"GO_TO_STEP\", index });\n }, []);\n\n const skip = useCallback(() => {\n // Not while Next is validating: the skip would land first and the pending GO_NEXT\n // would then be stale anyway — but the user asked for one move, not a race.\n if (advancingRef.current) return;\n dispatch({ type: \"SKIP\", from: state.currentStepIndex });\n }, [state.currentStepIndex]);\n\n const cancel = useCallback(() => {\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: true });\n }, []);\n\n const confirmCancel = useCallback(() => {\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: false });\n onCancel?.();\n }, [onCancel]);\n\n const dismissCancel = useCallback(() => {\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: false });\n }, []);\n\n const updateData = useCallback((partial: Partial<TData>) => {\n dispatch({ type: \"UPDATE_DATA\", partial });\n }, []);\n\n const clearError = useCallback(() => {\n dispatch({ type: \"SET_ERROR\", error: null });\n }, []);\n\n const clearFieldErrors = useCallback(() => {\n dispatch({ type: \"SET_FIELD_ERRORS\", errors: {} });\n }, []);\n\n const finish = useCallback(async () => {\n if (!onComplete || !canFinish) return;\n // The same re-entry guard as `goNext`: a double-click on Finish would otherwise\n // validate twice and call `onComplete` twice — `isSubmitting` is only set once\n // validation has passed, too late to stop the second click.\n if (advancingRef.current) return;\n advancingRef.current = true;\n try {\n // Validate the (possibly form-bearing) last step before submitting, matching\n // the Next gate — review-only steps register no validators and pass through.\n if (!(await runStepValidators())) return;\n dispatch({ type: \"SET_SUBMITTING\", value: true });\n dispatch({ type: \"SET_ERROR\", error: null });\n try {\n await onComplete(state.data);\n } catch (err) {\n const message = err instanceof Error && err.message ? err.message : genericError;\n dispatch({ type: \"SET_ERROR\", error: message });\n } finally {\n dispatch({ type: \"SET_SUBMITTING\", value: false });\n }\n } finally {\n advancingRef.current = false;\n }\n }, [onComplete, canFinish, state.data, runStepValidators, genericError]);\n\n const stepStatus = useCallback(\n (index: number): StepStatus => {\n if (index === state.currentStepIndex) return \"active\";\n if (state.skippedSteps.has(index)) return \"skipped\";\n if (state.completedSteps.has(index)) return \"completed\";\n return \"upcoming\";\n },\n [state.currentStepIndex, state.completedSteps, state.skippedSteps],\n );\n\n return {\n currentStepIndex: state.currentStepIndex,\n currentStep,\n steps: stepsRef.current,\n isFirstStep,\n isLastStep,\n canFinish,\n goNext,\n goBack,\n goToStep,\n skip,\n cancel,\n finish,\n registerStepValidate,\n nextBlocked,\n setNextBlocked,\n stepStatus,\n completedSteps: state.completedSteps,\n data: state.data,\n updateData,\n isSubmitting: state.isSubmitting,\n error: state.error,\n clearError,\n fieldErrors: state.fieldErrors,\n clearFieldErrors,\n showCancelDialog: state.showCancelDialog,\n confirmCancel,\n dismissCancel,\n };\n}\n"],"mappings":";AAUA,SAAS,aAAa,WAAW,YAAY,QAAQ,gBAAgB;AACrE,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAmCtC,SAAS,cAAqB,WAAmB;AAC/C,SAAO,SAAS,QACd,OACA,QACoB;AACpB,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK,WAAW;AACd,YAAI,OAAO,SAAS,MAAM,iB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AM,iBAAkB,QAAO;AAC7C,UAAI,MAAM,aAAa,IAAI,KAAK,EAAG,QAAO;AAC1C,UAAI,MAAM,eAAe,IAAI,KAAK,EAAG,QAAO;AAC5C,aAAO;AAAA,IACT;AAAA,IACA,CAAC,MAAM,kBAAkB,MAAM,gBAAgB,MAAM,YAAY;AAAA,EACnE;AAEA,SAAO;AAAA,IACL,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA,OAAO,SAAS;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,cAAc,MAAM;AAAA,IACpB,OAAO,MAAM;AAAA,IACb;AAAA,IACA,aAAa,MAAM;AAAA,IACnB;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/wizard/use-wizard.ts"],"sourcesContent":["/**\n * The multi-step wizard state machine: step index, completed/skipped sets,\n * per-step async validators, collected data, field errors, submit and the\n * cancel-confirm gate.\n *\n * Domain-free, and router-free on request. By default it mirrors the active step\n * to `?step=N`, so it must be mounted inside a react-router context — the same\n * requirement `DataTable` already carries. `urlSync: false` keeps the step in\n * memory and needs no router; `urlSync: { param }` renames the param. It only ever\n * WRITES that param (see the note on `initialStep` below for why it deliberately\n * does not read it back), and removes it when the wizard is left through the kit\n * (see `UseWizardOptions.urlSync`).\n *\n * The committing step is the last one unless a step says `commits: true`; the\n * steps after that one are post-commit steps (see `WizardStepConfig.commits`).\n */\nimport { useCallback, useEffect, useReducer, useRef, useState } from \"react\";\nimport { useSearchParams } from \"react-router\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_WIZARD_LABELS } from \"./types\";\nimport type {\n FieldErrors,\n StepStatus,\n UseWizardOptions,\n UseWizardReturn,\n ValidateResult,\n WizardStepConfig,\n} from \"./types\";\n\ninterface WizardState<TData> {\n currentStepIndex: number;\n completedSteps: Set<number>;\n skippedSteps: Set<number>;\n data: TData;\n isSubmitting: boolean;\n isValidating: boolean;\n error: string | null;\n fieldErrors: FieldErrors;\n showCancelDialog: boolean;\n /** The step whose `onComplete` resolved, or null before any commit. */\n committedStepIndex: number | null;\n}\n\n/** Past the commit: the active step comes after the step that committed. Moves to\n * that step or any before it are refused from here. */\nfunction isAfterCommit(state: { currentStepIndex: number; committedStepIndex: number | null }) {\n return state.committedStepIndex !== null && state.currentStepIndex > state.committedStepIndex;\n}\n\n/** Whether `index` is on the far side of a commit the wizard has already moved past. */\nfunction crossesCommit(\n state: { currentStepIndex: number; committedStepIndex: number | null },\n index: number,\n) {\n return isAfterCommit(state) && index <= (state.committedStepIndex as number);\n}\n\ntype WizardAction<TData> =\n // `from` is the step the move was decided ON. A move whose step is no longer the\n // current one is stale — see `goNext` — and is dropped rather than applied relative\n // to wherever the wizard has got to since.\n | { type: \"GO_NEXT\"; from: number }\n | { type: \"GO_BACK\" }\n | { type: \"GO_TO_STEP\"; index: number }\n | { type: \"SKIP\"; from: number }\n | { type: \"UPDATE_DATA\"; partial: Partial<TData> }\n | { type: \"COMMITTED\"; from: number }\n | { type: \"SET_SUBMITTING\"; value: boolean }\n | { type: \"SET_VALIDATING\"; value: boolean }\n | { type: \"SET_ERROR\"; error: string | null }\n | { type: \"SET_FIELD_ERRORS\"; errors: FieldErrors }\n | { type: \"SHOW_CANCEL_DIALOG\"; show: boolean };\n\nfunction createReducer<TData>(stepCount: number) {\n return function reducer(\n state: WizardState<TData>,\n action: WizardAction<TData>,\n ): WizardState<TData> {\n switch (action.type) {\n case \"GO_NEXT\": {\n if (action.from !== state.currentStepIndex) return state;\n const completed = new Set(state.completedSteps);\n completed.add(state.currentStepIndex);\n const nextIndex = Math.min(state.currentStepIndex + 1, stepCount - 1);\n return { ...state, currentStepIndex: nextIndex, completedSteps: completed, fieldErrors: {} };\n }\n case \"GO_BACK\": {\n const prevIndex = Math.max(state.currentStepIndex - 1, 0);\n if (crossesCommit(state, prevIndex)) return state;\n return { ...state, currentStepIndex: prevIndex, fieldErrors: {} };\n }\n case \"GO_TO_STEP\": {\n if (action.index < 0 || action.index >= stepCount) return state;\n if (crossesCommit(state, action.index)) return state;\n if (!state.completedSteps.has(action.index) && action.index > state.currentStepIndex) {\n return state;\n }\n return { ...state, currentStepIndex: action.index };\n }\n case \"SKIP\": {\n if (action.from !== state.currentStepIndex) return state;\n const skipped = new Set(state.skippedSteps);\n skipped.add(state.currentStepIndex);\n const nextIndex = Math.min(state.currentStepIndex + 1, stepCount - 1);\n return { ...state, currentStepIndex: nextIndex, skippedSteps: skipped };\n }\n case \"UPDATE_DATA\": {\n // Clear error for any field that is now being edited (so typing makes\n // the red message disappear).\n const nextErrors = { ...state.fieldErrors };\n for (const key of Object.keys(action.partial)) {\n delete nextErrors[key];\n }\n return { ...state, data: { ...state.data, ...action.partial }, fieldErrors: nextErrors };\n }\n case \"COMMITTED\": {\n // Recorded whatever step committed, so `wizard.committed` reads true after any\n // successful Finish. Only a commit with steps after it MOVES: the default\n // last-step commit stays where it is and looks exactly as it did before 0.8.\n const committed = { ...state, committedStepIndex: action.from };\n if (action.from !== state.currentStepIndex || action.from >= stepCount - 1) {\n return committed;\n }\n const completed = new Set(state.completedSteps);\n completed.add(action.from);\n return {\n ...committed,\n currentStepIndex: action.from + 1,\n completedSteps: completed,\n fieldErrors: {},\n };\n }\n case \"SET_SUBMITTING\":\n return { ...state, isSubmitting: action.value };\n case \"SET_VALIDATING\":\n return { ...state, isValidating: action.value };\n case \"SET_ERROR\":\n return { ...state, error: action.error };\n case \"SET_FIELD_ERRORS\":\n return { ...state, fieldErrors: action.errors };\n case \"SHOW_CANCEL_DIALOG\":\n return { ...state, showCancelDialog: action.show };\n default:\n return state;\n }\n };\n}\n\nexport function useWizard<TData extends Record<string, unknown>>(\n options: UseWizardOptions<TData>,\n): UseWizardReturn<TData> {\n const {\n steps,\n initialData,\n onComplete,\n onCancel,\n onExit,\n onDone,\n cancellable = true,\n confirmCancel: askBeforeCancel = true,\n urlSync = true,\n missingRequiredMessage,\n onValidationFailed,\n } = options;\n const stepsRef = useRef<WizardStepConfig[]>(steps);\n stepsRef.current = steps;\n // A hook, not a component, but it produces two sentences of its own — the\n // \"fill in the required fields\" toast and the fallback submit error — and both\n // reach the user. So it reads the provider like any component does; only the two\n // strings are depended on below, so the callbacks stay stable across renders.\n // The `??` is for the type only: both keys are optional on `WizardLabels` (see\n // there), and the merge never replaces a default with `undefined`.\n const wizardLabels = useKitLabels(\"wizard\", DEFAULT_WIZARD_LABELS, {\n missingRequired: missingRequiredMessage,\n });\n const missingRequired = wizardLabels.missingRequired ?? DEFAULT_WIZARD_LABELS.missingRequired;\n const genericError = wizardLabels.genericError ?? DEFAULT_WIZARD_LABELS.genericError;\n\n // Validators registered by the CURRENT step's mounted components (RHF steps\n // register via `useRhfWizardStep` through the wizard context). Only the active\n // step's validators are present — each unregisters on unmount. `goNext` and\n // `finish` run them (via `runStepValidators`) alongside the step config's own\n // `validate`.\n const validatorsRef = useRef(\n new Map<symbol, () => ValidateResult | Promise<ValidateResult>>(),\n );\n const registerStepValidate = useCallback(\n (fn: () => ValidateResult | Promise<ValidateResult>) => {\n const token = Symbol();\n validatorsRef.current.set(token, fn);\n return () => {\n validatorsRef.current.delete(token);\n };\n },\n [],\n );\n\n // Chosen once, at mount: a hook may not be called conditionally, but it may be\n // chosen once and then called unconditionally on every render — which is what\n // makes `urlSync: false` work with no router above the wizard at all.\n const [useStepUrl] = useState(() => (urlSync === false ? useNoStepUrl : useSearchParamStepUrl));\n const [urlParam] = useState(() =>\n typeof urlSync === \"object\" && urlSync.param ? urlSync.param : \"step\",\n );\n // The wizard's entered `data` and `completedSteps` are NOT persisted across a\n // reload / deep-link (the reducer re-inits to empty defaults on every mount).\n // Restoring a later step index from `?step=N` would therefore leave the wizard\n // on (or past) the last step with an EMPTY data set, letting Finish submit an\n // empty payload. Always start at step 0 so a reload re-runs the wizard from a\n // valid state instead of losing the entered data silently.\n const initialStep = 0;\n\n const reducer = createReducer<TData>(steps.length);\n const [state, dispatch] = useReducer(reducer, {\n currentStepIndex: initialStep,\n completedSteps: new Set<number>(),\n skippedSteps: new Set<number>(),\n data: (initialData ?? {}) as TData,\n isSubmitting: false,\n isValidating: false,\n error: null,\n fieldErrors: {},\n showCancelDialog: false,\n committedStepIndex: null,\n });\n\n // A mounted step can DISABLE forward navigation (Next/Skip) while its own\n // state is invalid (e.g. tenant shares != 100%). Defaults to false, so\n // wizards that never call setNextBlocked behave exactly as before.\n const [nextBlocked, setNextBlockedState] = useState(false);\n const setNextBlocked = useCallback(\n (blocked: boolean) => setNextBlockedState(blocked),\n [],\n );\n\n // Sync step index to URL (a no-op under `urlSync: false`). `clearStepUrl` drops\n // the param when the wizard is left through the kit, and stops the sync writing\n // it back.\n const clearStepUrl = useStepUrl(urlParam, state.currentStepIndex);\n\n // `steps`, not `stepsRef.current`: during render the two are the same array, and\n // reading a ref in render is what the hooks linter (rightly) objects to.\n const currentStep = steps[state.currentStepIndex];\n const isFirstStep = state.currentStepIndex === 0;\n const isLastStep = state.currentStepIndex === steps.length - 1;\n // The step whose forward button commits: the first one flagged `commits`, else the\n // last — which is every wizard written before the flag existed.\n const flagged = steps.findIndex((s) => s.commits);\n const commitStepIndex = flagged === -1 ? steps.length - 1 : flagged;\n const isCommitStep = state.currentStepIndex === commitStepIndex;\n const afterCommit = isAfterCommit(state);\n // Finish is only valid once every step before the committing one has actually\n // been walked through (completed or skipped). Guards against a restored/last-step\n // index submitting a payload built from empty defaults.\n const canFinish = steps.every(\n (_, index) =>\n index >= commitStepIndex ||\n state.completedSteps.has(index) ||\n state.skippedSteps.has(index),\n );\n const canGoBack =\n (!isFirstStep || onExit !== undefined) &&\n !crossesCommit(state, state.currentStepIndex - 1);\n const canCancel = cancellable && !afterCommit;\n const canDone = isLastStep && afterCommit && onDone !== undefined;\n\n // Runs the active step's config `validate` plus every validator its mounted\n // components registered (RHF steps via useRhfWizardStep), AND-combining the\n // results and merging any per-field errors. Returns `true` when the step\n // passes (or registered no validators). Shared by `goNext` and `finish` so a\n // form-bearing last step is validated (and its values flushed) on Finish too.\n const runStepValidators = useCallback(async (): Promise<boolean> => {\n const step = stepsRef.current[state.currentStepIndex];\n const validators = [...validatorsRef.current.values()];\n if (step.validate) validators.push(step.validate);\n if (validators.length === 0) return true;\n let ok = true;\n let errors: FieldErrors = {};\n try {\n for (const validate of validators) {\n const result = await validate();\n const vOk = typeof result === \"boolean\" ? result : result.ok;\n if (!vOk) {\n ok = false;\n if (typeof result !== \"boolean\" && result.errors) {\n errors = { ...errors, ...result.errors };\n }\n }\n }\n } catch (err) {\n // FALL THROUGH, do not return. A bare `return false` here blocked Next while\n // skipping the `if (!ok)` block below — the only thing that shows a message,\n // and whose own comment is \"say something anyway, so the user is not left with\n // a Next button that silently does nothing\". So a validator that threw (an\n // async one whose request rejected, a null dereference in a field rule)\n // produced exactly the outcome that block was written to prevent: no field\n // errors, no toast, `onValidationFailed` never called, nothing in the console.\n //\n // The step still must not advance; `ok = false` is what says so. Whatever\n // partial `errors` the loop had collected before the throw are kept — they are\n // real, and an empty set is what routes this to the generic message.\n console.error(\"[wizard] a step validator threw\", err);\n ok = false;\n }\n if (!ok) {\n dispatch({ type: \"SET_FIELD_ERRORS\", errors });\n if (Object.keys(errors).length === 0) {\n // No per-field detail (e.g. an RHF step surfacing its own inline\n // message) — say something anyway, so the user is not left with a Next\n // button that silently does nothing.\n const message = missingRequired;\n if (onValidationFailed) {\n onValidationFailed(message);\n } else {\n // sonner is an optional peer: imported here, on the failure path only,\n // so an app that never trips this never has to install it.\n const { toast } = await import(\"sonner\");\n toast.error(message);\n }\n }\n return false;\n }\n return true;\n }, [state.currentStepIndex, missingRequired, onValidationFailed]);\n\n /**\n * One forward move at a time. A double-click on Next used to validate the CURRENT\n * step twice and then advance twice — the second GO_NEXT landing on a step whose\n * own validators never ran, so a required field two steps in could be walked past.\n * Two layers, because either alone leaves a gap:\n *\n * - this ref refuses a second `goNext`/`skip`/`finish` while one is in flight,\n * which covers an async validator (a server check) of any length;\n * - the `from` on each action drops a move decided on a step that is no longer\n * current, which covers the click that arrives after the first move resolved\n * but before React re-rendered — its closure still holds the old step index.\n */\n const advancingRef = useRef(false);\n\n const goNext = useCallback(async () => {\n if (advancingRef.current) return;\n advancingRef.current = true;\n const from = state.currentStepIndex;\n // Pending state for the chrome (spinner, aria-busy). The ref above is still what\n // refuses the second click: state would only be seen after a re-render.\n dispatch({ type: \"SET_VALIDATING\", value: true });\n try {\n if (await runStepValidators()) {\n dispatch({ type: \"GO_NEXT\", from });\n }\n } finally {\n dispatch({ type: \"SET_VALIDATING\", value: false });\n advancingRef.current = false;\n }\n }, [runStepValidators, state.currentStepIndex]);\n\n // Read by `goBack`, which must not move while `onComplete` runs: the commit was\n // decided on the data of the step the user is on, and Back mid-commit would show a\n // step whose edits can no longer reach it. The chrome disables the button too; this\n // covers an app calling `goBack` itself.\n const submittingRef = useRef(false);\n\n const goBack = useCallback(() => {\n if (submittingRef.current) return;\n if (state.currentStepIndex === 0 && onExit) {\n clearStepUrl();\n onExit();\n return;\n }\n // On step 0 with no `onExit` this stays the no-op move (clearing field errors) it\n // always was.\n dispatch({ type: \"GO_BACK\" });\n }, [state.currentStepIndex, onExit, clearStepUrl]);\n\n const goToStep = useCallback((index: number) => {\n dispatch({ type: \"GO_TO_STEP\", index });\n }, []);\n\n const canGoToStep = useCallback(\n (index: number) =>\n index >= 0 &&\n index < steps.length &&\n (index <= state.currentStepIndex || state.completedSteps.has(index)) &&\n !crossesCommit(state, index),\n [steps.length, state],\n );\n\n const skip = useCallback(() => {\n // Not while Next is validating: the skip would land first and the pending GO_NEXT\n // would then be stale anyway — but the user asked for one move, not a race.\n if (advancingRef.current) return;\n dispatch({ type: \"SKIP\", from: state.currentStepIndex });\n }, [state.currentStepIndex]);\n\n const confirmCancel = useCallback(() => {\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: false });\n clearStepUrl();\n onCancel?.();\n }, [onCancel, clearStepUrl]);\n\n const cancel = useCallback(() => {\n if (!askBeforeCancel) {\n confirmCancel();\n return;\n }\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: true });\n }, [askBeforeCancel, confirmCancel]);\n\n const done = useCallback(() => {\n clearStepUrl();\n onDone?.();\n }, [onDone, clearStepUrl]);\n\n const dismissCancel = useCallback(() => {\n dispatch({ type: \"SHOW_CANCEL_DIALOG\", show: false });\n }, []);\n\n const updateData = useCallback((partial: Partial<TData>) => {\n dispatch({ type: \"UPDATE_DATA\", partial });\n }, []);\n\n const clearError = useCallback(() => {\n dispatch({ type: \"SET_ERROR\", error: null });\n }, []);\n\n const clearFieldErrors = useCallback(() => {\n dispatch({ type: \"SET_FIELD_ERRORS\", errors: {} });\n }, []);\n\n const finish = useCallback(async () => {\n if (!onComplete || !canFinish) return;\n // A commit with steps after it happens once: those steps exist because the\n // data has been written. (A last-step commit keeps its old behaviour — the app\n // may retry Finish after `onComplete` resolved, as it always could.)\n if (commitStepIndex < steps.length - 1 && state.committedStepIndex !== null) return;\n // The same re-entry guard as `goNext`: a double-click on Finish would otherwise\n // validate twice and call `onComplete` twice — `isSubmitting` is only set once\n // validation has passed, too late to stop the second click.\n if (advancingRef.current) return;\n advancingRef.current = true;\n const from = state.currentStepIndex;\n try {\n // Validate the (possibly form-bearing) committing step before submitting,\n // matching the Next gate — review-only steps register no validators and pass\n // through.\n dispatch({ type: \"SET_VALIDATING\", value: true });\n let valid: boolean;\n try {\n valid = await runStepValidators();\n } finally {\n dispatch({ type: \"SET_VALIDATING\", value: false });\n }\n if (!valid) return;\n submittingRef.current = true;\n dispatch({ type: \"SET_SUBMITTING\", value: true });\n dispatch({ type: \"SET_ERROR\", error: null });\n try {\n await onComplete(state.data);\n dispatch({ type: \"COMMITTED\", from });\n } catch (err) {\n const message = err instanceof Error && err.message ? err.message : genericError;\n dispatch({ type: \"SET_ERROR\", error: message });\n } finally {\n submittingRef.current = false;\n dispatch({ type: \"SET_SUBMITTING\", value: false });\n }\n } finally {\n advancingRef.current = false;\n }\n }, [\n onComplete,\n canFinish,\n commitStepIndex,\n steps.length,\n state.committedStepIndex,\n state.currentStepIndex,\n state.data,\n runStepValidators,\n genericError,\n ]);\n\n const stepStatus = useCallback(\n (index: number): StepStatus => {\n if (index === state.currentStepIndex) return \"active\";\n if (state.skippedSteps.has(index)) return \"skipped\";\n if (state.completedSteps.has(index)) return \"completed\";\n return \"upcoming\";\n },\n [state.currentStepIndex, state.completedSteps, state.skippedSteps],\n );\n\n return {\n currentStepIndex: state.currentStepIndex,\n currentStep,\n steps,\n isFirstStep,\n isLastStep,\n canFinish,\n commitStepIndex,\n isCommitStep,\n committed: state.committedStepIndex !== null,\n canGoBack,\n canCancel,\n canDone,\n canGoToStep,\n goNext,\n goBack,\n goToStep,\n skip,\n cancel,\n finish,\n done,\n registerStepValidate,\n nextBlocked,\n setNextBlocked,\n stepStatus,\n completedSteps: state.completedSteps,\n data: state.data,\n updateData,\n isSubmitting: state.isSubmitting,\n isValidating: state.isValidating,\n error: state.error,\n clearError,\n fieldErrors: state.fieldErrors,\n clearFieldErrors,\n showCancelDialog: state.showCancelDialog,\n confirmCancel,\n dismissCancel,\n };\n}\n\n/**\n * `urlSync: true` / `{ param }`: mirror the active step to `?<param>=N`, and hand back\n * the function that removes it again. Once removed it stays removed — the sync effect\n * re-runs whenever react-router hands out a new setter (every search change), and\n * without the latch it would write the param straight back after the exit cleared it.\n */\nfunction useSearchParamStepUrl(param: string, index: number): () => void {\n const [, setUrlParams] = useSearchParams();\n const leftRef = useRef(false);\n useEffect(() => {\n if (leftRef.current) return;\n setUrlParams((prev) => {\n prev.set(param, String(index));\n return prev;\n }, { replace: true });\n }, [param, index, setUrlParams]);\n return useCallback(() => {\n if (leftRef.current) return;\n leftRef.current = true;\n setUrlParams((prev) => {\n prev.delete(param);\n return prev;\n }, { replace: true });\n }, [param, setUrlParams]);\n}\n\n/** `urlSync: false`: the step lives in the reducer only. Touches no router context. */\nfunction useNoStepUrl(_param: string, _index: number): () => void {\n return noop;\n}\n\nfunction noop() {}\n"],"mappings":";AAgBA,SAAS,aAAa,WAAW,YAAY,QAAQ,gBAAgB;AACrE,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AA0BtC,SAAS,cAAc,OAAwE;AAC7F,SAAO,MAAM,uBAAuB,QAAQ,MAAM,mBAAmB,MAAM;AAC7E;AAGA,SAAS,cACP,OACA,OACA;AACA,SAAO,cAAc,KAAK,KAAK,SAAU,MAAM;AACjD;AAkBA,SAAS,cAAqB,WAAmB;AAC/C,SAAO,SAAS,QACd,OACA,QACoB;AACpB,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK,WAAW;AACd,YAAI,OAAO,SAAS,MAAM,iBAAkB,QAAO;AACnD,cAAM,YAAY,IAAI,IAAI,MAAM,cAAc;AAC9C,kBAAU,IAAI,MAAM,gBAAgB;AACpC,cAAM,YAAY,KAAK,IAAI,MAAM,mBAAmB,GAAG,YAAY,CAAC;AACpE,eAAO,EAAE,GAAG,OAAO,kBAAkB,WAAW,gBAAgB,WAAW,aAAa,CAAC,EAAE;AAAA,MAC7F;AAAA,MACA,KAAK,WAAW;AACd,cAAM,YAAY,KAAK,IAAI,MAAM,mBAAmB,GAAG,CAAC;AACxD,YAAI,cAAc,OAAO,SAAS,EAAG,QAAO;AAC5C,eAAO,EAAE,GAAG,OAAO,kBAAkB,WAAW,aAAa,CAAC,EAAE;AAAA,MAClE;AAAA,MACA,KAAK,cAAc;AACjB,YAAI,OAAO,QAAQ,KAAK,OAAO,SAAS,UAAW,QAAO;AAC1D,YAAI,cAAc,OAAO,OAAO,KAAK,EAAG,QAAO;AAC/C,YAAI,CAAC,MAAM,eAAe,IAAI,OAAO,KAAK,KAAK,OAAO,QAAQ,MAAM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