@eifi1/ui-kit 0.12.0 → 0.13.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 +10 -10
- package/dist/components/amount-input.d.ts +17 -1
- package/dist/components/amount-input.js +46 -11
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/bulk-action-bar.d.ts +10 -2
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/calculator.d.ts +1 -1
- package/dist/components/chart.js +14 -8
- package/dist/components/chart.js.map +1 -1
- package/dist/components/chip.js +20 -15
- package/dist/components/chip.js.map +1 -1
- package/dist/components/combobox-core.d.ts +3 -1
- package/dist/components/combobox-core.js +16 -5
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/data-table-filter-popover.js +8 -1
- package/dist/components/data-table-filter-popover.js.map +1 -1
- package/dist/components/data-table.js +28 -20
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/entity-combobox.js +22 -17
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/error-boundary.d.ts +202 -13
- package/dist/components/error-boundary.js +211 -20
- package/dist/components/error-boundary.js.map +1 -1
- package/dist/components/field-sync.js +90 -83
- package/dist/components/field-sync.js.map +1 -1
- package/dist/components/file-button.d.ts +1 -1
- package/dist/components/file-dropzone.d.ts +1 -1
- package/dist/components/form-actions.d.ts +1 -1
- package/dist/components/full-bleed-dialog.js +4 -0
- package/dist/components/full-bleed-dialog.js.map +1 -1
- package/dist/components/hover-menu.js +64 -56
- package/dist/components/hover-menu.js.map +1 -1
- package/dist/components/list.d.ts +14 -2
- package/dist/components/list.js +3 -1
- package/dist/components/list.js.map +1 -1
- package/dist/components/modal.js.map +1 -1
- package/dist/components/multi-entity-combobox.js +23 -17
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/number-field.d.ts +1 -1
- package/dist/components/number-input.d.ts +1 -1
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +6 -2
- package/dist/components/numpad-sheet.js +3 -2
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/page-header.d.ts +35 -6
- package/dist/components/page-header.js +7 -1
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/picker-sheet.js +3 -0
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/popover.js +3 -0
- package/dist/components/popover.js.map +1 -1
- package/dist/components/settings-fields.d.ts +1 -1
- package/dist/components/signed-amount.d.ts +2 -1
- package/dist/components/signed-amount.js +1 -1
- package/dist/components/signed-amount.js.map +1 -1
- package/dist/components/stat-tile.js +1 -1
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/swipeable-row.js +4 -3
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/text-link.d.ts +73 -11
- package/dist/components/text-link.js +45 -10
- package/dist/components/text-link.js.map +1 -1
- package/dist/components/text.d.ts +26 -2
- package/dist/components/text.js +16 -2
- package/dist/components/text.js.map +1 -1
- package/dist/components/time-input.d.ts +1 -1
- package/dist/components/toggle-group.d.ts +22 -0
- package/dist/components/toggle-group.js +8 -8
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle-legend.d.ts +17 -0
- package/dist/components/toggle-legend.js +6 -2
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/tooltip.d.ts +51 -1
- package/dist/components/tooltip.js +59 -35
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/ui.d.ts +1 -1
- package/dist/components/ui.js +166 -28
- package/dist/components/ui.js.map +1 -1
- package/dist/feedback/feedback-attachment.js +4 -6
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.js +5 -3
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.js +86 -75
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +43 -3
- package/dist/feedback/feedback-thread.js +53 -26
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/feedback.d.ts +1 -1
- package/dist/hooks/use-file-drop.d.ts +1 -1
- package/dist/i18n/defaults.d.ts +1 -1
- package/dist/i18n/kit-labels.d.ts +1 -1
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +1 -1
- package/dist/i18n/locales/de-CH.d.ts +1 -1
- package/dist/i18n/locales/de-informal.d.ts +1 -1
- package/dist/i18n/locales/de.d.ts +1 -1
- package/dist/i18n/locales/de.js +9 -1
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +1 -1
- package/dist/i18n/locales/es.js +9 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +1 -1
- package/dist/i18n/locales/fr.js +9 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +1 -1
- package/dist/i18n/locales/hu.js +9 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +1 -1
- package/dist/i18n/locales/it.js +9 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +1 -1
- package/dist/i18n/locales/zh.js +9 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/{kit-labels-v3biUF1L.d.ts → kit-labels-Mz8zZHIF.d.ts} +102 -3
- package/dist/lib/format.d.ts +23 -5
- package/dist/lib/format.js +3 -1
- package/dist/lib/format.js.map +1 -1
- package/dist/rhf/fields.d.ts +57 -15
- package/dist/rhf/fields.js +41 -11
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +1 -1
- package/dist/rhf.d.ts +2 -2
- package/dist/rhf.js.map +1 -1
- package/dist/search/command-palette.js +20 -14
- package/dist/search/command-palette.js.map +1 -1
- package/dist/shell/app-shell.d.ts +1 -1
- package/dist/shell/app-shell.js +62 -54
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/top-bar-brand.d.ts +1 -1
- package/dist/shell/topbar-action-menu.d.ts +9 -3
- package/dist/shell/topbar-action-menu.js +2 -1
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +1 -1
- package/dist/tour/tour.js +10 -4
- package/dist/tour/tour.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +1 -1
- package/dist/wizard/use-wizard.js +4 -2
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/wizard-step.d.ts +11 -1
- package/dist/wizard/wizard-step.js +24 -6
- package/dist/wizard/wizard-step.js.map +1 -1
- package/dist/wizard.d.ts +1 -1
- package/package.json +6 -6
- package/src/components/amount-input.tsx +97 -10
- package/src/components/bulk-action-bar.tsx +16 -3
- package/src/components/chart.tsx +19 -8
- package/src/components/chip.tsx +6 -0
- package/src/components/combobox-core.tsx +28 -9
- package/src/components/combobox.tsx +2 -0
- package/src/components/data-table-filter-popover.tsx +13 -5
- package/src/components/data-table.tsx +6 -0
- package/src/components/entity-combobox.tsx +7 -4
- package/src/components/error-boundary.tsx +453 -29
- package/src/components/field-sync.tsx +48 -40
- package/src/components/full-bleed-dialog.tsx +4 -0
- package/src/components/hover-menu.tsx +26 -17
- package/src/components/list.tsx +17 -3
- package/src/components/modal.tsx +4 -0
- package/src/components/multi-entity-combobox.tsx +8 -4
- package/src/components/number-input.tsx +1 -0
- package/src/components/numpad-sheet.tsx +6 -1
- package/src/components/page-header.tsx +42 -5
- package/src/components/picker-sheet.tsx +3 -0
- package/src/components/popover.tsx +3 -0
- package/src/components/signed-amount.tsx +12 -3
- package/src/components/stat-tile.tsx +3 -1
- package/src/components/swipeable-row.tsx +7 -7
- package/src/components/text-link.tsx +126 -18
- package/src/components/text.tsx +46 -2
- package/src/components/toggle-group.tsx +35 -10
- package/src/components/toggle-legend.tsx +22 -1
- package/src/components/tooltip.tsx +79 -8
- package/src/components/ui.tsx +307 -39
- package/src/feedback/feedback-attachment.tsx +10 -7
- package/src/feedback/feedback-dialog.tsx +7 -4
- package/src/feedback/feedback-inbox.tsx +7 -0
- package/src/feedback/feedback-thread.tsx +109 -33
- package/src/i18n/kit-labels.tsx +16 -0
- package/src/i18n/locales/de.ts +8 -0
- package/src/i18n/locales/es.ts +8 -0
- package/src/i18n/locales/fr.ts +8 -0
- package/src/i18n/locales/hu.ts +8 -0
- package/src/i18n/locales/it.ts +8 -0
- package/src/i18n/locales/zh.ts +8 -0
- package/src/lib/format.ts +29 -6
- package/src/rhf/fields.tsx +97 -16
- package/src/rhf.ts +1 -1
- package/src/search/command-palette.tsx +29 -19
- package/src/shell/app-shell.tsx +6 -1
- package/src/shell/topbar-action-menu.tsx +11 -4
- package/src/tour/tour.tsx +16 -5
- package/src/wizard/use-wizard.ts +8 -4
- package/src/wizard/wizard-step.tsx +38 -6
package/dist/tour/tour.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tour/tour.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button } from \"../components/ui\";\nimport { useFocusTrap } from \"../hooks/use-focus-trap\";\nimport { dirOf, horizontalStep } from \"../lib/direction\";\nimport type { Direction } from \"../lib/direction\";\n\n/**\n * `start`/`end` follow the reading direction (`end` is the right side in LTR and the\n * left side in RTL) and are what a translated app wants. `left`/`right` stay physical\n * for the steps that genuinely mean a screen side.\n */\nexport type TourPlacement = \"top\" | \"right\" | \"bottom\" | \"left\" | \"start\" | \"end\" | \"center\";\n\nexport interface TourStep {\n /** CSS selector for the element to spotlight. Omit for a centered step\n * (welcome/finish). If the target isn't found/visible, the step centers. */\n target?: string;\n title: string;\n body: ReactNode;\n /** Extra footer content, e.g. a \"load sample data\" shortcut. */\n action?: ReactNode;\n /** Spotlight padding around the target, px (default 8). */\n padding?: number;\n /** Where the card sits relative to the target. Omit for auto placement\n * (below → above → centered). \"center\" ignores the target and centers on\n * screen. \"start\"/\"end\" are the logical sides and flip in RTL; \"left\"/\"right\"\n * are physical. An explicit side flips to the opposite side if it would\n * overflow, then clamps into the viewport. */\n placement?: TourPlacement;\n /** Advance only when the user clicks the spotlighted target itself (not the\n * card's Next button). Requires `target`: the real control's own handler runs\n * first, then the tour steps forward on a microtask. The spotlight hole stays\n * click-through to the target; the rest of the page does not. */\n awaitClick?: boolean;\n /** Runs before the step is shown — e.g. navigate to a route, open a panel.\n * May be async; the step waits for it, then locates the target. */\n beforeStep?: () => void | Promise<void>;\n}\n\nexport interface TourLabels {\n next: string;\n back: string;\n skip: string;\n done: string;\n /** Shown in place of the Next button on an `awaitClick` step. */\n awaitClickHint: string;\n /** Step counter, e.g. (2, 7) => \"2 / 7\". */\n step: (current: number, total: number) => string;\n}\n\nexport const DEFAULT_TOUR_LABELS: TourLabels = {\n next: \"Next\",\n back: \"Back\",\n skip: \"Skip\",\n done: \"Done\",\n awaitClickHint: \"Click the highlighted element to continue\",\n step: (c, t) => `${c} / ${t}`,\n};\n\ninterface StartOptions {\n /** Stable id of the tour, surfaced as `activeId` so the app can mirror it to\n * the URL (deep-link / evaluation tracking) and record completion. */\n id?: string;\n /** Start at this step index instead of 0 (clamped) — for URL/deep-link resume. */\n startIndex?: number;\n /** Fires synchronously when the tour starts (e.g. enable a mock interceptor). */\n onStart?: () => void;\n onFinish?: () => void;\n onSkip?: () => void;\n}\n\ninterface TourContextValue {\n active: boolean;\n /** Id of the running tour (from {@link StartOptions.id}), else null. */\n activeId: string | null;\n /** Start a tour with the given steps. */\n start: (steps: TourStep[], opts?: StartOptions) => void;\n /** End the current tour (no callbacks fire). */\n stop: () => void;\n /** Advance one step; past the last step it finishes the tour (fires onFinish). */\n next: () => void;\n /** Go back one step (no-op on the first). */\n prev: () => void;\n /** Jump to a step by index, clamped to range — e.g. for URL/deep-link resume. */\n goToStep: (index: number) => void;\n /** Current step (0-based; 0 while inactive). */\n index: number;\n /** Total steps (0 while inactive). */\n total: number;\n}\n\nconst TourContext = createContext<TourContextValue | null>(null);\n\nexport function useTour(): TourContextValue {\n const ctx = useContext(TourContext);\n if (!ctx) throw new Error(\"useTour must be used within <TourProvider>\");\n return ctx;\n}\n\n/**\n * The tour engine if it is there, `null` if it is not — for a control that is a\n * DECORATION rather than a participant.\n *\n * {@link useTour}'s throw is correct and stays: a component that runs a tour cannot do\n * its job without the provider, and failing loudly is how that gets fixed. But the\n * throw's blast radius is whatever error boundary is above it, and for a launcher in\n * the app shell that is the whole app.\n *\n * Keksdose feedback dev#524 is what that costs: an `@hb/ui` module was edited while a\n * dev server was running, vite re-evaluated it, and the module's freshly created\n * context object was no longer the one the mounted provider was providing. React's\n * `useContext` then answers `null` for a provider that is, structurally, right there —\n * and the top bar's tour menu took the entire shell down with it. **Build-time module\n * graphs cannot produce that**, so it is a development-only failure; a menu that\n * disappears for a second is the proportionate response to it either way.\n *\n * Only for controls that can honestly render nothing. If a component would show a\n * broken half of itself without the tour, it wants {@link useTour}.\n */\nexport function useTourOptional(): TourContextValue | null {\n return useContext(TourContext);\n}\n\n/**\n * Provides the guided-tour engine: a dimmed spotlight overlay + step card driven\n * by a list of {@link TourStep}s. Domain-free — the app supplies the steps (copy,\n * selectors, per-step navigation, placement) and the translated {@link TourLabels}.\n * Mount once inside the router; start a tour from anywhere via {@link useTour},\n * which also exposes step control (`next`/`prev`/`goToStep`) and the current\n * `index`/`total` for URL mirroring, `awaitClick` and deep-link resume.\n */\nexport function TourProvider({\n children,\n labels,\n}: {\n children: ReactNode;\n labels?: Partial<TourLabels>;\n}) {\n // `labels` over the provider's `tour` over English. Resolved once here and handed\n // down: the step card is portalled, but context crosses portals anyway — this is\n // simply the one place that already owned the merge.\n const merged = useKitLabels(\"tour\", DEFAULT_TOUR_LABELS, labels);\n const [steps, setSteps] = useState<TourStep[] | null>(null);\n const [index, setIndex] = useState(0);\n const [activeId, setActiveId] = useState<string | null>(null);\n const optsRef = useRef<StartOptions>({});\n // Live mirrors so the step-control callbacks can stay stable (identity-safe for\n // consumers) while still reading the current steps/index.\n const stepsRef = useRef<TourStep[] | null>(null);\n stepsRef.current = steps;\n const indexRef = useRef(0);\n indexRef.current = index;\n const active = !!steps && steps.length > 0;\n const total = steps?.length ?? 0;\n\n const start = useCallback((s: TourStep[], opts?: StartOptions) => {\n optsRef.current = opts ?? {};\n optsRef.current.onStart?.();\n setIndex(Math.min(Math.max(0, opts?.startIndex ?? 0), Math.max(0, s.length - 1)));\n setActiveId(opts?.id ?? null);\n setSteps(s);\n }, []);\n const stop = useCallback(() => {\n setSteps(null);\n setActiveId(null);\n }, []);\n const finish = useCallback(() => {\n optsRef.current.onFinish?.();\n setSteps(null);\n setActiveId(null);\n }, []);\n const skip = useCallback(() => {\n optsRef.current.onSkip?.();\n setSteps(null);\n setActiveId(null);\n }, []);\n\n const goToStep = useCallback((i: number) => {\n const len = stepsRef.current?.length ?? 0;\n if (len === 0) return;\n setIndex(Math.min(Math.max(0, i), len - 1));\n }, []);\n const next = useCallback(() => {\n const len = stepsRef.current?.length ?? 0;\n if (len === 0) return;\n if (indexRef.current >= len - 1) finish();\n else setIndex(indexRef.current + 1);\n }, [finish]);\n const prev = useCallback(() => {\n if (indexRef.current > 0) setIndex(indexRef.current - 1);\n }, []);\n\n return (\n <TourContext.Provider value={{ active, activeId, start, stop, next, prev, goToStep, index, total }}>\n {children}\n {active && (\n <TourOverlay\n steps={steps!}\n index={index}\n labels={merged}\n onNext={next}\n onPrev={prev}\n onSkip={skip}\n />\n )}\n </TourContext.Provider>\n );\n}\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\nfunction isVisible(el: Element): boolean {\n // A non-zero box already rules out display:none on the element or any ancestor\n // (an unrendered element measures 0x0). We deliberately do NOT test\n // offsetParent: it is null for position:fixed elements even when fully visible,\n // which made the mobile bottom-nav bar (fixed) un-highlightable on mobile\n // (feedback #313). visibility:hidden keeps a box, so check it explicitly.\n const r = el.getBoundingClientRect();\n if (r.width <= 0 || r.height <= 0) return false;\n const style = getComputedStyle(el);\n return style.visibility !== \"hidden\" && style.display !== \"none\";\n}\n\n// The first VISIBLE element matching the selector, not merely the first in DOM\n// order. This lets a step target the same control across layouts with one\n// combined selector — e.g. the desktop sidebar link AND the mobile bottom-bar\n// link — where the off-layout copy is present but `display:none` (feedback\n// #313). Returns null while none is visible so the finder keeps retrying.\nfunction queryVisibleTarget(selector: string): Element | null {\n const els = document.querySelectorAll(selector);\n for (const el of els) {\n if (isVisible(el)) return el;\n }\n return null;\n}\n\nfunction sameRect(a: Rect | null, b: Rect | null): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n return a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height;\n}\n\nfunction TourOverlay({\n steps,\n index,\n labels,\n onNext,\n onPrev,\n onSkip,\n}: {\n steps: TourStep[];\n index: number;\n labels: TourLabels;\n onNext: () => void;\n onPrev: () => void;\n onSkip: () => void;\n}) {\n const step = steps[index];\n const isFirst = index === 0;\n const isLast = index === steps.length - 1;\n const [rect, setRect] = useState<Rect | null>(null);\n const [ready, setReady] = useState(false);\n // The overlay is portalled to <body>, out of whatever `dir` subtree the app set, so it\n // takes the direction of the element it spotlights (the document's for a centered\n // step). Arrow keys and start/end placement read it.\n const [dir, setDir] = useState<Direction>(() => dirOf(null));\n const rootRef = useRef<HTMLDivElement>(null);\n\n // Run beforeStep, then locate the target (retrying across route/render lag).\n useEffect(() => {\n let cancelled = false;\n let raf = 0;\n setReady(false);\n setRect(null);\n void (async () => {\n await step.beforeStep?.();\n if (cancelled) return;\n if (!step.target) {\n setDir(dirOf(null));\n setReady(true);\n return;\n }\n let tries = 0;\n const find = () => {\n if (cancelled) return;\n const el = queryVisibleTarget(step.target!);\n if (el) {\n el.scrollIntoView({ block: \"center\", behavior: \"smooth\" });\n const r = el.getBoundingClientRect();\n setRect({ top: r.top, left: r.left, width: r.width, height: r.height });\n setDir(dirOf(el));\n setReady(true);\n return;\n }\n if (tries++ < 45) raf = requestAnimationFrame(find);\n else {\n setDir(dirOf(null));\n setReady(true); // give up → render centered\n }\n };\n find();\n })();\n return () => {\n cancelled = true;\n cancelAnimationFrame(raf);\n };\n }, [index, step]);\n\n // Follow the target as the page scrolls / reflows.\n useEffect(() => {\n if (!step.target) return;\n const update = () => {\n const el = queryVisibleTarget(step.target!);\n if (el) {\n const r = el.getBoundingClientRect();\n const next = { top: r.top, left: r.left, width: r.width, height: r.height };\n setRect((prev) => (sameRect(prev, next) ? prev : next));\n }\n };\n window.addEventListener(\"scroll\", update, true);\n window.addEventListener(\"resize\", update);\n const id = window.setInterval(update, 250);\n return () => {\n window.removeEventListener(\"scroll\", update, true);\n window.removeEventListener(\"resize\", update);\n clearInterval(id);\n };\n }, [index, step]);\n\n // awaitClick: advance when the *real* target is clicked. The spotlight hole is\n // click-through (see the shields in the render below) so the element's own\n // handler runs first; we step forward on the next macrotask.\n useEffect(() => {\n if (!ready || !step.awaitClick || !step.target) return;\n const el = queryVisibleTarget(step.target);\n if (!el) return;\n const onClick = () => window.setTimeout(() => onNext(), 0);\n el.addEventListener(\"click\", onClick, { once: true });\n return () => el.removeEventListener(\"click\", onClick);\n }, [ready, index, step, onNext]);\n\n // Keyboard: Esc skips, Enter and the reading-direction arrow advance (→ in LTR,\n // ← in RTL), the other arrow goes back. On awaitClick steps Enter is ignored (it\n // would fire the target's click AND advance) — the forward arrow stays as an escape\n // hatch.\n //\n // Enter on a focused control belongs to that control. This used to advance from\n // anywhere, so Enter on a focused Skip or Back ran the button's own click AND stepped\n // forward: Back moved nowhere, Skip skipped and then called `next` on a dead tour.\n // The same goes for arrows in a text field a step's `action` might contain.\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n onSkip();\n return;\n }\n if (e.key === \"Enter\") {\n if (step.awaitClick || ownsKey(e.target, \"Enter\")) return;\n e.preventDefault();\n onNext();\n return;\n }\n if (ownsKey(e.target, e.key)) return;\n // The overlay root carries `dir`; before it paints, the document's answers.\n const delta = horizontalStep(e.key, rootRef.current);\n if (delta === 1) {\n e.preventDefault();\n onNext();\n } else if (delta === -1) {\n if (!isFirst) onPrev();\n }\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isFirst, step, onNext, onPrev, onSkip]);\n\n if (!ready) return null;\n\n const pad = step.padding ?? 8;\n const spot: Rect | null = rect\n ? { top: rect.top - pad, left: rect.left - pad, width: rect.width + pad * 2, height: rect.height + pad * 2 }\n : null;\n\n // `aria-modal` promises the page behind is out of reach, and the card's focus trap\n // keeps that promise for the keyboard. The pointer used to get no such treatment: the\n // root is `pointer-events-none` so that the spotlight hole can stay live for\n // `awaitClick`, and the scrim is a box-shadow, which takes no clicks — so every\n // control on the dimmed page stayed clickable. Four shields now tile the viewport\n // around the hole: the page is blocked, the card and the spotlighted target are not.\n // Keeping `aria-modal` (rather than dropping it) is the coherent half: the tour\n // really is modal — focus is trapped and Esc/Skip is the way out.\n return createPortal(\n <div\n ref={rootRef}\n className=\"pointer-events-none fixed inset-0 z-[60]\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={step.title}\n dir={dir}\n >\n {spot && <SpotlightShields spot={spot} />}\n {spot ? (\n <div\n className=\"pointer-events-none fixed rounded-lg transition-all duration-200 ease-out\"\n style={{\n top: spot.top,\n left: spot.left,\n width: spot.width,\n height: spot.height,\n // A two-tone frame, not a single translucent ring.\n //\n // The old treatment was `ring-2 ring-white/80` over a 55% scrim, and it\n // \"was barely visible\" on the app's blue-tinted surfaces. Two reasons,\n // and a single ring can't fix either: at 55% the surround stays bright\n // enough that the un-dimmed hole barely reads AS a hole, and a 80%-white\n // ring sitting on the edge of a light card is white-on-near-white.\n //\n // So: an opaque white band immediately around the target, a dark keyline\n // outside it, then the scrim. Whatever the target's own colour is, one of\n // the two bands is always in contrast with it and the other is always in\n // contrast with the dimmed surround — there is no background that can\n // swallow both. The blurred layer between them softens the step so the\n // frame reads as lighting rather than as a pasted-on rectangle.\n boxShadow: [\n \"0 0 0 3px rgba(255,255,255,0.98)\",\n \"0 0 0 5px rgba(15,23,42,0.92)\",\n \"0 0 18px 6px rgba(15,23,42,0.45)\",\n \"0 0 0 9999px rgba(15,23,42,0.70)\",\n ].join(\", \"),\n }}\n />\n ) : (\n <div className=\"pointer-events-auto fixed inset-0 bg-black/70\" />\n )}\n <TourCard\n step={step}\n index={index}\n total={steps.length}\n labels={labels}\n isFirst={isFirst}\n isLast={isLast}\n rect={spot}\n dir={dir}\n onBack={onPrev}\n onNext={onNext}\n onSkip={onSkip}\n />\n </div>,\n document.body,\n );\n}\n\n/** Does the focused element handle `key` itself? Enter on a button or link, and any\n * editing key in a text field or select, is the control's — not the tour's. */\nfunction ownsKey(target: EventTarget | null, key: string): boolean {\n if (!(target instanceof HTMLElement)) return false;\n if (target.isContentEditable) return true;\n const tag = target.tagName;\n if (tag === \"TEXTAREA\" || tag === \"SELECT\") return true;\n if (tag === \"INPUT\") {\n const type = (target as HTMLInputElement).type;\n // Enter on a checkbox does nothing natively, but ←/→ on a radio moves it.\n return key !== \"Enter\" || type !== \"checkbox\";\n }\n if (key !== \"Enter\") return false;\n return (\n tag === \"BUTTON\" ||\n (tag === \"A\" && target.hasAttribute(\"href\")) ||\n target.getAttribute(\"role\") === \"button\" ||\n target.getAttribute(\"role\") === \"link\"\n );\n}\n\n/**\n * Transparent pointer blockers tiling the viewport around the spotlight hole: one\n * full-width band above and below, one on each side at the hole's own height. The hole\n * itself stays uncovered, so the target keeps its clicks.\n */\nfunction SpotlightShields({ spot }: { spot: Rect }) {\n const shield = \"pointer-events-auto fixed\";\n const bottom = spot.top + spot.height;\n return (\n <>\n <div data-tour-shield=\"\" className={shield} style={{ top: 0, left: 0, right: 0, height: Math.max(0, spot.top) }} />\n <div data-tour-shield=\"\" className={shield} style={{ top: bottom, left: 0, right: 0, bottom: 0 }} />\n <div\n data-tour-shield=\"\"\n className={shield}\n style={{ top: spot.top, left: 0, width: Math.max(0, spot.left), height: spot.height }}\n />\n <div\n data-tour-shield=\"\"\n className={shield}\n style={{ top: spot.top, left: spot.left + spot.width, right: 0, height: spot.height }}\n />\n </>\n );\n}\n\n/**\n * Card position (viewport px) for the given placement relative to the padded\n * spotlight `rect`. Omitted placement keeps the original auto behavior\n * (below → above → vertically centered); an explicit side flips to its opposite\n * if it would overflow, then clamps into the viewport. \"center\" (or no rect)\n * centers on screen.\n */\nfunction placeCard(\n rect: Rect | null,\n cw: number,\n ch: number,\n vw: number,\n vh: number,\n m: number,\n placement?: TourPlacement,\n dir: Direction = \"ltr\",\n): { top: number; left: number } {\n // The logical sides resolve to a physical one here, and only here.\n if (placement === \"start\") placement = dir === \"rtl\" ? \"right\" : \"left\";\n else if (placement === \"end\") placement = dir === \"rtl\" ? \"left\" : \"right\";\n if (!rect || placement === \"center\") {\n return { top: Math.max(m, (vh - ch) / 2), left: Math.max(m, (vw - cw) / 2) };\n }\n const clampX = (x: number) => Math.min(Math.max(m, x), Math.max(m, vw - cw - m));\n const clampY = (y: number) => Math.min(Math.max(m, y), Math.max(m, vh - ch - m));\n const centerX = clampX(rect.left + rect.width / 2 - cw / 2);\n const centerY = clampY(rect.top + rect.height / 2 - ch / 2);\n const belowTop = rect.top + rect.height + m;\n const aboveTop = rect.top - ch - m;\n const rightLeft = rect.left + rect.width + m;\n const leftLeft = rect.left - cw - m;\n const fitsBelow = belowTop + ch <= vh;\n const fitsAbove = aboveTop >= 0;\n const fitsRight = rightLeft + cw <= vw;\n const fitsLeft = leftLeft >= 0;\n\n switch (placement) {\n case \"top\":\n return { top: fitsAbove ? aboveTop : fitsBelow ? belowTop : clampY(aboveTop), left: centerX };\n case \"bottom\":\n return { top: fitsBelow ? belowTop : fitsAbove ? aboveTop : clampY(belowTop), left: centerX };\n case \"right\":\n return { top: centerY, left: fitsRight ? rightLeft : fitsLeft ? leftLeft : clampX(rightLeft) };\n case \"left\":\n return { top: centerY, left: fitsLeft ? leftLeft : fitsRight ? rightLeft : clampX(leftLeft) };\n default:\n if (fitsBelow) return { top: belowTop, left: centerX };\n if (fitsAbove) return { top: aboveTop, left: centerX };\n return { top: Math.max(m, (vh - ch) / 2), left: centerX };\n }\n}\n\nfunction TourCard({\n step,\n index,\n total,\n labels,\n isFirst,\n isLast,\n rect,\n dir,\n onBack,\n onNext,\n onSkip,\n}: {\n step: TourStep;\n index: number;\n total: number;\n labels: TourLabels;\n isFirst: boolean;\n isLast: boolean;\n rect: Rect | null;\n dir: Direction;\n onBack: () => void;\n onNext: () => void;\n onSkip: () => void;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n const [style, setStyle] = useState<CSSProperties>({ opacity: 0 });\n\n /**\n * The card holds the focus, because the card is what the tour IS.\n *\n * The overlay above declares `role=\"dialog\" aria-modal=\"true\"` — it always has — and\n * then left focus wherever the page had put it. For a tour that is the most pointed\n * version of the audit's *\"Only Modal manages focus\"*: the whole component exists to\n * say \"look here\", and for a keyboard user \"here\" is the focus ring. They were told\n * the page was hidden, given no way to reach the Next button without Tabbing through\n * it, and left on a control the screen reader would no longer describe.\n *\n * It re-engages on every step, without any bookkeeping here, because `TourOverlay`\n * returns null while it re-locates the next target: the card genuinely unmounts and\n * remounts between steps. That is what keeps focus honest when the BUTTONS change —\n * \"Back\" does not exist on the first step, so stepping back onto it destroys the\n * control the press came from, and focus would otherwise fall to `<body>`, outside\n * this trap's own listener, where Tab walks straight into the page the overlay claims\n * to have hidden.\n *\n * **The cost, written down:** on an `awaitClick` step the user is asked to click the\n * spotlighted element, and they can no longer Tab to it. ArrowRight still advances\n * (the key handler in `TourOverlay` is on the document and does not care where focus\n * is), which is the escape hatch that step already documents for the case where the\n * target cannot be found. Containment is worth that: an `awaitClick` step is a\n * minority of steps, while focus stranded behind `aria-modal` is every step.\n */\n useFocusTrap(ref, { active: true });\n\n useLayoutEffect(() => {\n const card = ref.current;\n if (!card) return;\n setStyle(\n placeCard(rect, card.offsetWidth, card.offsetHeight, window.innerWidth, window.innerHeight, 12, step.placement, dir),\n );\n }, [rect, index, step.placement, dir]);\n\n return (\n <div\n ref={ref}\n // Focusable but not tabbable: the trap above focuses the card itself rather than\n // its first button, so a screen reader reads the step's title and body before it\n // reads \"Next\" — and without this the container cannot take focus at all and the\n // trap silently does nothing.\n tabIndex={-1}\n style={style}\n className=\"pointer-events-auto fixed z-[61] w-80 max-w-[calc(100vw-1.5rem)] rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-4 shadow-xl outline-none transition-all duration-200 ease-out\"\n >\n <div className=\"text-sm font-semibold text-[var(--text-primary)]\">{step.title}</div>\n <div className=\"mt-1 text-sm leading-relaxed text-[var(--text-secondary)]\">{step.body}</div>\n {step.action && <div className=\"mt-3\">{step.action}</div>}\n <div className=\"mt-4 space-y-2\">\n <div className=\"flex items-center justify-between gap-2\">\n <button\n type=\"button\"\n onClick={onSkip}\n className=\"text-xs text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]\"\n >\n {labels.skip}\n </button>\n <div className=\"flex items-center gap-2\">\n <span className=\"whitespace-nowrap text-xs tabular-nums text-[var(--text-placeholder)]\">\n {labels.step(index + 1, total)}\n </span>\n {!isFirst && (\n <Button variant=\"secondary\" onClick={onBack} className=\"px-2.5 py-1 text-xs\">\n {labels.back}\n </Button>\n )}\n {/* On an awaitClick step the Next button is replaced by a hint on its\n own row below, so it doesn't cram the counter + buttons and wrap.\n Only when the target was actually FOUND, though — `rect` is null\n when the finder gave up, and the click listener early-returns on\n the same absence. Keyed on `step.target` alone this hid the only\n way forward on any step whose anchor happens not to be rendered\n for this user (a guest sees no \"add account\" button), leaving the\n undocumented ArrowRight key as the sole escape. */}\n {!(step.awaitClick && step.target && rect) && (\n <Button variant=\"brand\" onClick={onNext} className={cn(\"px-2.5 py-1 text-xs\")}>\n {isLast ? labels.done : labels.next}\n </Button>\n )}\n </div>\n </div>\n {step.awaitClick && step.target && rect && (\n <div className=\"text-center text-xs italic text-[var(--text-placeholder)]\">\n {labels.awaitClickHint}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";AA6MI,SAsSA,UAnSI,KAHJ;AA7MJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,OAAO,sBAAsB;AA+C/B,MAAM,sBAAkC;AAAA,EAC7C,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC;AAC7B;AAkCA,MAAM,cAAc,cAAuC,IAAI;AAExD,SAAS,UAA4B;AAC1C,QAAM,MAAM,WAAW,WAAW;AAClC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,4CAA4C;AACtE,SAAO;AACT;AAsBO,SAAS,kBAA2C;AACzD,SAAO,WAAW,WAAW;AAC/B;AAUO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AAID,QAAM,SAAS,aAAa,QAAQ,qBAAqB,MAAM;AAC/D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA4B,IAAI;AAC1D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,CAAC;AACpC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,UAAU,OAAqB,CAAC,CAAC;AAGvC,QAAM,WAAW,OAA0B,IAAI;AAC/C,WAAS,UAAU;AACnB,QAAM,WAAW,OAAO,CAAC;AACzB,WAAS,UAAU;AACnB,QAAM,SAAS,CAAC,CAAC,SAAS,MAAM,SAAS;AACzC,QAAM,QAAQ,OAAO,U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O,SAAQ,aAAY,SAAS,QAAQ,WAAU,uBACpD,iBAAO,MACV;AAAA,cAUD,EAAE,KAAK,cAAc,KAAK,UAAU,SACnC,oBAAC,UAAO,SAAQ,SAAQ,SAAS,QAAQ,WAAW,GAAG,qBAAqB,GACzE,mBAAS,OAAO,OAAO,OAAO,MACjC;AAAA,eAEJ;AAAA,aACF;AAAA,UACC,KAAK,cAAc,KAAK,UAAU,QACjC,oBAAC,SAAI,WAAU,6DACZ,iBAAO,gBACV;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/tour/tour.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button } from \"../components/ui\";\nimport { useFocusTrap } from \"../hooks/use-focus-trap\";\nimport { dirOf, horizontalStep } from \"../lib/direction\";\nimport type { Direction } from \"../lib/direction\";\n\n/**\n * `start`/`end` follow the reading direction (`end` is the right side in LTR and the\n * left side in RTL) and are what a translated app wants. `left`/`right` stay physical\n * for the steps that genuinely mean a screen side.\n */\nexport type TourPlacement = \"top\" | \"right\" | \"bottom\" | \"left\" | \"start\" | \"end\" | \"center\";\n\nexport interface TourStep {\n /** CSS selector for the element to spotlight. Omit for a centered step\n * (welcome/finish). If the target isn't found/visible, the step centers. */\n target?: string;\n title: string;\n body: ReactNode;\n /** Extra footer content, e.g. a \"load sample data\" shortcut. */\n action?: ReactNode;\n /** Spotlight padding around the target, px (default 8). */\n padding?: number;\n /** Where the card sits relative to the target. Omit for auto placement\n * (below → above → centered). \"center\" ignores the target and centers on\n * screen. \"start\"/\"end\" are the logical sides and flip in RTL; \"left\"/\"right\"\n * are physical. An explicit side flips to the opposite side if it would\n * overflow, then clamps into the viewport. */\n placement?: TourPlacement;\n /** Advance only when the user clicks the spotlighted target itself (not the\n * card's Next button). Requires `target`: the real control's own handler runs\n * first, then the tour steps forward on a microtask. The spotlight hole stays\n * click-through to the target; the rest of the page does not. */\n awaitClick?: boolean;\n /** Runs before the step is shown — e.g. navigate to a route, open a panel.\n * May be async; the step waits for it, then locates the target. */\n beforeStep?: () => void | Promise<void>;\n}\n\nexport interface TourLabels {\n next: string;\n back: string;\n skip: string;\n done: string;\n /** Shown in place of the Next button on an `awaitClick` step. */\n awaitClickHint: string;\n /** Step counter, e.g. (2, 7) => \"2 / 7\". */\n step: (current: number, total: number) => string;\n}\n\nexport const DEFAULT_TOUR_LABELS: TourLabels = {\n next: \"Next\",\n back: \"Back\",\n skip: \"Skip\",\n done: \"Done\",\n awaitClickHint: \"Click the highlighted element to continue\",\n step: (c, t) => `${c} / ${t}`,\n};\n\ninterface StartOptions {\n /** Stable id of the tour, surfaced as `activeId` so the app can mirror it to\n * the URL (deep-link / evaluation tracking) and record completion. */\n id?: string;\n /** Start at this step index instead of 0 (clamped) — for URL/deep-link resume. */\n startIndex?: number;\n /** Fires synchronously when the tour starts (e.g. enable a mock interceptor). */\n onStart?: () => void;\n onFinish?: () => void;\n onSkip?: () => void;\n}\n\ninterface TourContextValue {\n active: boolean;\n /** Id of the running tour (from {@link StartOptions.id}), else null. */\n activeId: string | null;\n /** Start a tour with the given steps. */\n start: (steps: TourStep[], opts?: StartOptions) => void;\n /** End the current tour (no callbacks fire). */\n stop: () => void;\n /** Advance one step; past the last step it finishes the tour (fires onFinish). */\n next: () => void;\n /** Go back one step (no-op on the first). */\n prev: () => void;\n /** Jump to a step by index, clamped to range — e.g. for URL/deep-link resume. */\n goToStep: (index: number) => void;\n /** Current step (0-based; 0 while inactive). */\n index: number;\n /** Total steps (0 while inactive). */\n total: number;\n}\n\nconst TourContext = createContext<TourContextValue | null>(null);\n\nexport function useTour(): TourContextValue {\n const ctx = useContext(TourContext);\n if (!ctx) throw new Error(\"useTour must be used within <TourProvider>\");\n return ctx;\n}\n\n/**\n * The tour engine if it is there, `null` if it is not — for a control that is a\n * DECORATION rather than a participant.\n *\n * {@link useTour}'s throw is correct and stays: a component that runs a tour cannot do\n * its job without the provider, and failing loudly is how that gets fixed. But the\n * throw's blast radius is whatever error boundary is above it, and for a launcher in\n * the app shell that is the whole app.\n *\n * Keksdose feedback dev#524 is what that costs: an `@hb/ui` module was edited while a\n * dev server was running, vite re-evaluated it, and the module's freshly created\n * context object was no longer the one the mounted provider was providing. React's\n * `useContext` then answers `null` for a provider that is, structurally, right there —\n * and the top bar's tour menu took the entire shell down with it. **Build-time module\n * graphs cannot produce that**, so it is a development-only failure; a menu that\n * disappears for a second is the proportionate response to it either way.\n *\n * Only for controls that can honestly render nothing. If a component would show a\n * broken half of itself without the tour, it wants {@link useTour}.\n */\nexport function useTourOptional(): TourContextValue | null {\n return useContext(TourContext);\n}\n\n/**\n * Provides the guided-tour engine: a dimmed spotlight overlay + step card driven\n * by a list of {@link TourStep}s. Domain-free — the app supplies the steps (copy,\n * selectors, per-step navigation, placement) and the translated {@link TourLabels}.\n * Mount once inside the router; start a tour from anywhere via {@link useTour},\n * which also exposes step control (`next`/`prev`/`goToStep`) and the current\n * `index`/`total` for URL mirroring, `awaitClick` and deep-link resume.\n */\nexport function TourProvider({\n children,\n labels,\n}: {\n children: ReactNode;\n labels?: Partial<TourLabels>;\n}) {\n // `labels` over the provider's `tour` over English. Resolved once here and handed\n // down: the step card is portalled, but context crosses portals anyway — this is\n // simply the one place that already owned the merge.\n const merged = useKitLabels(\"tour\", DEFAULT_TOUR_LABELS, labels);\n const [steps, setSteps] = useState<TourStep[] | null>(null);\n const [index, setIndex] = useState(0);\n const [activeId, setActiveId] = useState<string | null>(null);\n const optsRef = useRef<StartOptions>({});\n // Live mirrors so the step-control callbacks can stay stable (identity-safe for\n // consumers) while still reading the current steps/index. Synced in a layout\n // effect — after the commit, before paint and before any passive effect or event\n // can call them — rather than written during render.\n const stepsRef = useRef<TourStep[] | null>(null);\n const indexRef = useRef(0);\n useLayoutEffect(() => {\n stepsRef.current = steps;\n indexRef.current = index;\n }, [steps, index]);\n const active = !!steps && steps.length > 0;\n const total = steps?.length ?? 0;\n\n const start = useCallback((s: TourStep[], opts?: StartOptions) => {\n optsRef.current = opts ?? {};\n optsRef.current.onStart?.();\n setIndex(Math.min(Math.max(0, opts?.startIndex ?? 0), Math.max(0, s.length - 1)));\n setActiveId(opts?.id ?? null);\n setSteps(s);\n }, []);\n const stop = useCallback(() => {\n setSteps(null);\n setActiveId(null);\n }, []);\n const finish = useCallback(() => {\n optsRef.current.onFinish?.();\n setSteps(null);\n setActiveId(null);\n }, []);\n const skip = useCallback(() => {\n optsRef.current.onSkip?.();\n setSteps(null);\n setActiveId(null);\n }, []);\n\n const goToStep = useCallback((i: number) => {\n const len = stepsRef.current?.length ?? 0;\n if (len === 0) return;\n setIndex(Math.min(Math.max(0, i), len - 1));\n }, []);\n const next = useCallback(() => {\n const len = stepsRef.current?.length ?? 0;\n if (len === 0) return;\n if (indexRef.current >= len - 1) finish();\n else setIndex(indexRef.current + 1);\n }, [finish]);\n const prev = useCallback(() => {\n if (indexRef.current > 0) setIndex(indexRef.current - 1);\n }, []);\n\n return (\n <TourContext.Provider value={{ active, activeId, start, stop, next, prev, goToStep, index, total }}>\n {children}\n {active && (\n <TourOverlay\n steps={steps!}\n index={index}\n labels={merged}\n onNext={next}\n onPrev={prev}\n onSkip={skip}\n />\n )}\n </TourContext.Provider>\n );\n}\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\nfunction isVisible(el: Element): boolean {\n // A non-zero box already rules out display:none on the element or any ancestor\n // (an unrendered element measures 0x0). We deliberately do NOT test\n // offsetParent: it is null for position:fixed elements even when fully visible,\n // which made the mobile bottom-nav bar (fixed) un-highlightable on mobile\n // (feedback #313). visibility:hidden keeps a box, so check it explicitly.\n const r = el.getBoundingClientRect();\n if (r.width <= 0 || r.height <= 0) return false;\n const style = getComputedStyle(el);\n return style.visibility !== \"hidden\" && style.display !== \"none\";\n}\n\n// The first VISIBLE element matching the selector, not merely the first in DOM\n// order. This lets a step target the same control across layouts with one\n// combined selector — e.g. the desktop sidebar link AND the mobile bottom-bar\n// link — where the off-layout copy is present but `display:none` (feedback\n// #313). Returns null while none is visible so the finder keeps retrying.\nfunction queryVisibleTarget(selector: string): Element | null {\n const els = document.querySelectorAll(selector);\n for (const el of els) {\n if (isVisible(el)) return el;\n }\n return null;\n}\n\nfunction sameRect(a: Rect | null, b: Rect | null): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n return a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height;\n}\n\nfunction TourOverlay({\n steps,\n index,\n labels,\n onNext,\n onPrev,\n onSkip,\n}: {\n steps: TourStep[];\n index: number;\n labels: TourLabels;\n onNext: () => void;\n onPrev: () => void;\n onSkip: () => void;\n}) {\n const step = steps[index];\n const isFirst = index === 0;\n const isLast = index === steps.length - 1;\n const [rect, setRect] = useState<Rect | null>(null);\n const [ready, setReady] = useState(false);\n // A new step starts unlocated: reset during render when the step changes, so the\n // previous step's spotlight never paints over the new one. The effect below then\n // locates it.\n const [locating, setLocating] = useState({ index, step });\n if (locating.index !== index || locating.step !== step) {\n setLocating({ index, step });\n setReady(false);\n setRect(null);\n }\n // The overlay is portalled to <body>, out of whatever `dir` subtree the app set, so it\n // takes the direction of the element it spotlights (the document's for a centered\n // step). Arrow keys and start/end placement read it.\n const [dir, setDir] = useState<Direction>(() => dirOf(null));\n const rootRef = useRef<HTMLDivElement>(null);\n\n // Run beforeStep, then locate the target (retrying across route/render lag).\n useEffect(() => {\n let cancelled = false;\n let raf = 0;\n void (async () => {\n await step.beforeStep?.();\n if (cancelled) return;\n if (!step.target) {\n setDir(dirOf(null));\n setReady(true);\n return;\n }\n let tries = 0;\n const find = () => {\n if (cancelled) return;\n const el = queryVisibleTarget(step.target!);\n if (el) {\n el.scrollIntoView({ block: \"center\", behavior: \"smooth\" });\n const r = el.getBoundingClientRect();\n setRect({ top: r.top, left: r.left, width: r.width, height: r.height });\n setDir(dirOf(el));\n setReady(true);\n return;\n }\n if (tries++ < 45) raf = requestAnimationFrame(find);\n else {\n setDir(dirOf(null));\n setReady(true); // give up → render centered\n }\n };\n find();\n })();\n return () => {\n cancelled = true;\n cancelAnimationFrame(raf);\n };\n }, [index, step]);\n\n // Follow the target as the page scrolls / reflows.\n useEffect(() => {\n if (!step.target) return;\n const update = () => {\n const el = queryVisibleTarget(step.target!);\n if (el) {\n const r = el.getBoundingClientRect();\n const next = { top: r.top, left: r.left, width: r.width, height: r.height };\n setRect((prev) => (sameRect(prev, next) ? prev : next));\n }\n };\n window.addEventListener(\"scroll\", update, true);\n window.addEventListener(\"resize\", update);\n const id = window.setInterval(update, 250);\n return () => {\n window.removeEventListener(\"scroll\", update, true);\n window.removeEventListener(\"resize\", update);\n clearInterval(id);\n };\n }, [index, step]);\n\n // awaitClick: advance when the *real* target is clicked. The spotlight hole is\n // click-through (see the shields in the render below) so the element's own\n // handler runs first; we step forward on the next macrotask.\n useEffect(() => {\n if (!ready || !step.awaitClick || !step.target) return;\n const el = queryVisibleTarget(step.target);\n if (!el) return;\n const onClick = () => window.setTimeout(() => onNext(), 0);\n el.addEventListener(\"click\", onClick, { once: true });\n return () => el.removeEventListener(\"click\", onClick);\n }, [ready, index, step, onNext]);\n\n // Keyboard: Esc skips, Enter and the reading-direction arrow advance (→ in LTR,\n // ← in RTL), the other arrow goes back. On awaitClick steps Enter is ignored (it\n // would fire the target's click AND advance) — the forward arrow stays as an escape\n // hatch.\n //\n // Enter on a focused control belongs to that control. This used to advance from\n // anywhere, so Enter on a focused Skip or Back ran the button's own click AND stepped\n // forward: Back moved nowhere, Skip skipped and then called `next` on a dead tour.\n // The same goes for arrows in a text field a step's `action` might contain.\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n onSkip();\n return;\n }\n if (e.key === \"Enter\") {\n if (step.awaitClick || ownsKey(e.target, \"Enter\")) return;\n e.preventDefault();\n onNext();\n return;\n }\n if (ownsKey(e.target, e.key)) return;\n // The overlay root carries `dir`; before it paints, the document's answers.\n const delta = horizontalStep(e.key, rootRef.current);\n if (delta === 1) {\n e.preventDefault();\n onNext();\n } else if (delta === -1) {\n if (!isFirst) onPrev();\n }\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isFirst, step, onNext, onPrev, onSkip]);\n\n if (!ready) return null;\n\n const pad = step.padding ?? 8;\n const spot: Rect | null = rect\n ? { top: rect.top - pad, left: rect.left - pad, width: rect.width + pad * 2, height: rect.height + pad * 2 }\n : null;\n\n // `aria-modal` promises the page behind is out of reach, and the card's focus trap\n // keeps that promise for the keyboard. The pointer used to get no such treatment: the\n // root is `pointer-events-none` so that the spotlight hole can stay live for\n // `awaitClick`, and the scrim is a box-shadow, which takes no clicks — so every\n // control on the dimmed page stayed clickable. Four shields now tile the viewport\n // around the hole: the page is blocked, the card and the spotlighted target are not.\n // Keeping `aria-modal` (rather than dropping it) is the coherent half: the tour\n // really is modal — focus is trapped and Esc/Skip is the way out.\n return createPortal(\n <div\n ref={rootRef}\n className=\"pointer-events-none fixed inset-0 z-[60]\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={step.title}\n dir={dir}\n >\n {spot && <SpotlightShields spot={spot} />}\n {spot ? (\n <div\n className=\"pointer-events-none fixed rounded-lg transition-all duration-200 ease-out\"\n style={{\n top: spot.top,\n left: spot.left,\n width: spot.width,\n height: spot.height,\n // A two-tone frame, not a single translucent ring.\n //\n // The old treatment was `ring-2 ring-white/80` over a 55% scrim, and it\n // \"was barely visible\" on the app's blue-tinted surfaces. Two reasons,\n // and a single ring can't fix either: at 55% the surround stays bright\n // enough that the un-dimmed hole barely reads AS a hole, and a 80%-white\n // ring sitting on the edge of a light card is white-on-near-white.\n //\n // So: an opaque white band immediately around the target, a dark keyline\n // outside it, then the scrim. Whatever the target's own colour is, one of\n // the two bands is always in contrast with it and the other is always in\n // contrast with the dimmed surround — there is no background that can\n // swallow both. The blurred layer between them softens the step so the\n // frame reads as lighting rather than as a pasted-on rectangle.\n boxShadow: [\n \"0 0 0 3px rgba(255,255,255,0.98)\",\n \"0 0 0 5px rgba(15,23,42,0.92)\",\n \"0 0 18px 6px rgba(15,23,42,0.45)\",\n \"0 0 0 9999px rgba(15,23,42,0.70)\",\n ].join(\", \"),\n }}\n />\n ) : (\n <div className=\"pointer-events-auto fixed inset-0 bg-black/70\" />\n )}\n <TourCard\n step={step}\n index={index}\n total={steps.length}\n labels={labels}\n isFirst={isFirst}\n isLast={isLast}\n rect={spot}\n dir={dir}\n onBack={onPrev}\n onNext={onNext}\n onSkip={onSkip}\n />\n </div>,\n document.body,\n );\n}\n\n/** Does the focused element handle `key` itself? Enter on a button or link, and any\n * editing key in a text field or select, is the control's — not the tour's. */\nfunction ownsKey(target: EventTarget | null, key: string): boolean {\n if (!(target instanceof HTMLElement)) return false;\n if (target.isContentEditable) return true;\n const tag = target.tagName;\n if (tag === \"TEXTAREA\" || tag === \"SELECT\") return true;\n if (tag === \"INPUT\") {\n const type = (target as HTMLInputElement).type;\n // Enter on a checkbox does nothing natively, but ←/→ on a radio moves it.\n return key !== \"Enter\" || type !== \"checkbox\";\n }\n if (key !== \"Enter\") return false;\n return (\n tag === \"BUTTON\" ||\n (tag === \"A\" && target.hasAttribute(\"href\")) ||\n target.getAttribute(\"role\") === \"button\" ||\n target.getAttribute(\"role\") === \"link\"\n );\n}\n\n/**\n * Transparent pointer blockers tiling the viewport around the spotlight hole: one\n * full-width band above and below, one on each side at the hole's own height. The hole\n * itself stays uncovered, so the target keeps its clicks.\n */\nfunction SpotlightShields({ spot }: { spot: Rect }) {\n const shield = \"pointer-events-auto fixed\";\n const bottom = spot.top + spot.height;\n return (\n <>\n <div data-tour-shield=\"\" className={shield} style={{ top: 0, left: 0, right: 0, height: Math.max(0, spot.top) }} />\n <div data-tour-shield=\"\" className={shield} style={{ top: bottom, left: 0, right: 0, bottom: 0 }} />\n <div\n data-tour-shield=\"\"\n className={shield}\n style={{ top: spot.top, left: 0, width: Math.max(0, spot.left), height: spot.height }}\n />\n <div\n data-tour-shield=\"\"\n className={shield}\n style={{ top: spot.top, left: spot.left + spot.width, right: 0, height: spot.height }}\n />\n </>\n );\n}\n\n/**\n * Card position (viewport px) for the given placement relative to the padded\n * spotlight `rect`. Omitted placement keeps the original auto behavior\n * (below → above → vertically centered); an explicit side flips to its opposite\n * if it would overflow, then clamps into the viewport. \"center\" (or no rect)\n * centers on screen.\n */\nfunction placeCard(\n rect: Rect | null,\n cw: number,\n ch: number,\n vw: number,\n vh: number,\n m: number,\n placement?: TourPlacement,\n dir: Direction = \"ltr\",\n): { top: number; left: number } {\n // The logical sides resolve to a physical one here, and only here.\n if (placement === \"start\") placement = dir === \"rtl\" ? \"right\" : \"left\";\n else if (placement === \"end\") placement = dir === \"rtl\" ? \"left\" : \"right\";\n if (!rect || placement === \"center\") {\n return { top: Math.max(m, (vh - ch) / 2), left: Math.max(m, (vw - cw) / 2) };\n }\n const clampX = (x: number) => Math.min(Math.max(m, x), Math.max(m, vw - cw - m));\n const clampY = (y: number) => Math.min(Math.max(m, y), Math.max(m, vh - ch - m));\n const centerX = clampX(rect.left + rect.width / 2 - cw / 2);\n const centerY = clampY(rect.top + rect.height / 2 - ch / 2);\n const belowTop = rect.top + rect.height + m;\n const aboveTop = rect.top - ch - m;\n const rightLeft = rect.left + rect.width + m;\n const leftLeft = rect.left - cw - m;\n const fitsBelow = belowTop + ch <= vh;\n const fitsAbove = aboveTop >= 0;\n const fitsRight = rightLeft + cw <= vw;\n const fitsLeft = leftLeft >= 0;\n\n switch (placement) {\n case \"top\":\n return { top: fitsAbove ? aboveTop : fitsBelow ? belowTop : clampY(aboveTop), left: centerX };\n case \"bottom\":\n return { top: fitsBelow ? belowTop : fitsAbove ? aboveTop : clampY(belowTop), left: centerX };\n case \"right\":\n return { top: centerY, left: fitsRight ? rightLeft : fitsLeft ? leftLeft : clampX(rightLeft) };\n case \"left\":\n return { top: centerY, left: fitsLeft ? leftLeft : fitsRight ? rightLeft : clampX(leftLeft) };\n default:\n if (fitsBelow) return { top: belowTop, left: centerX };\n if (fitsAbove) return { top: aboveTop, left: centerX };\n return { top: Math.max(m, (vh - ch) / 2), left: centerX };\n }\n}\n\nfunction TourCard({\n step,\n index,\n total,\n labels,\n isFirst,\n isLast,\n rect,\n dir,\n onBack,\n onNext,\n onSkip,\n}: {\n step: TourStep;\n index: number;\n total: number;\n labels: TourLabels;\n isFirst: boolean;\n isLast: boolean;\n rect: Rect | null;\n dir: Direction;\n onBack: () => void;\n onNext: () => void;\n onSkip: () => void;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n const [style, setStyle] = useState<CSSProperties>({ opacity: 0 });\n\n /**\n * The card holds the focus, because the card is what the tour IS.\n *\n * The overlay above declares `role=\"dialog\" aria-modal=\"true\"` — it always has — and\n * then left focus wherever the page had put it. For a tour that is the most pointed\n * version of the audit's *\"Only Modal manages focus\"*: the whole component exists to\n * say \"look here\", and for a keyboard user \"here\" is the focus ring. They were told\n * the page was hidden, given no way to reach the Next button without Tabbing through\n * it, and left on a control the screen reader would no longer describe.\n *\n * It re-engages on every step, without any bookkeeping here, because `TourOverlay`\n * returns null while it re-locates the next target: the card genuinely unmounts and\n * remounts between steps. That is what keeps focus honest when the BUTTONS change —\n * \"Back\" does not exist on the first step, so stepping back onto it destroys the\n * control the press came from, and focus would otherwise fall to `<body>`, outside\n * this trap's own listener, where Tab walks straight into the page the overlay claims\n * to have hidden.\n *\n * **The cost, written down:** on an `awaitClick` step the user is asked to click the\n * spotlighted element, and they can no longer Tab to it. ArrowRight still advances\n * (the key handler in `TourOverlay` is on the document and does not care where focus\n * is), which is the escape hatch that step already documents for the case where the\n * target cannot be found. Containment is worth that: an `awaitClick` step is a\n * minority of steps, while focus stranded behind `aria-modal` is every step.\n */\n useFocusTrap(ref, { active: true });\n\n useLayoutEffect(() => {\n const card = ref.current;\n if (!card) return;\n setStyle(\n placeCard(rect, card.offsetWidth, card.offsetHeight, window.innerWidth, window.innerHeight, 12, step.placement, dir),\n );\n }, [rect, index, step.placement, dir]);\n\n return (\n <div\n ref={ref}\n // Focusable but not tabbable: the trap above focuses the card itself rather than\n // its first button, so a screen reader reads the step's title and body before it\n // reads \"Next\" — and without this the container cannot take focus at all and the\n // trap silently does nothing.\n tabIndex={-1}\n style={style}\n className=\"pointer-events-auto fixed z-[61] w-80 max-w-[calc(100vw-1.5rem)] rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-4 shadow-xl outline-none transition-all duration-200 ease-out\"\n >\n <div className=\"text-sm font-semibold text-[var(--text-primary)]\">{step.title}</div>\n <div className=\"mt-1 text-sm leading-relaxed text-[var(--text-secondary)]\">{step.body}</div>\n {step.action && <div className=\"mt-3\">{step.action}</div>}\n <div className=\"mt-4 space-y-2\">\n <div className=\"flex items-center justify-between gap-2\">\n <button\n type=\"button\"\n onClick={onSkip}\n className=\"text-xs text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]\"\n >\n {labels.skip}\n </button>\n <div className=\"flex items-center gap-2\">\n <span className=\"whitespace-nowrap text-xs tabular-nums text-[var(--text-placeholder)]\">\n {labels.step(index + 1, total)}\n </span>\n {!isFirst && (\n <Button variant=\"secondary\" onClick={onBack} className=\"px-2.5 py-1 text-xs\">\n {labels.back}\n </Button>\n )}\n {/* On an awaitClick step the Next button is replaced by a hint on its\n own row below, so it doesn't cram the counter + buttons and wrap.\n Only when the target was actually FOUND, though — `rect` is null\n when the finder gave up, and the click listener early-returns on\n the same absence. Keyed on `step.target` alone this hid the only\n way forward on any step whose anchor happens not to be rendered\n for this user (a guest sees no \"add account\" button), leaving the\n undocumented ArrowRight key as the sole escape. */}\n {!(step.awaitClick && step.target && rect) && (\n <Button variant=\"brand\" onClick={onNext} className={cn(\"px-2.5 py-1 text-xs\")}>\n {isLast ? labels.done : labels.next}\n </Button>\n )}\n </div>\n </div>\n {step.awaitClick && step.target && rect && (\n <div className=\"text-center text-xs italic text-[var(--text-placeholder)]\">\n {labels.awaitClickHint}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";AAiNI,SA6SA,UA1SI,KAHJ;AAjNJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,OAAO,sBAAsB;AA+C/B,MAAM,sBAAkC;AAAA,EAC7C,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC;AAC7B;AAkCA,MAAM,cAAc,cAAuC,IAAI;AAExD,SAAS,UAA4B;AAC1C,QAAM,MAAM,WAAW,WAAW;AAClC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,4CAA4C;AACtE,SAAO;AACT;AAsBO,SAAS,kBAA2C;AACzD,SAAO,WAAW,WAAW;AAC/B;AAUO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AAID,QAAM,SAAS,aAAa,QAAQ,qBAAqB,MAAM;AAC/D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA4B,IAAI;AAC1D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,CAAC;AACpC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,UAAU,OAAqB,CAAC,CAAC;AAKvC,QAAM,WAAW,OAA0B,IAAI;AAC/C,QAAM,WAAW,OAAO,CAAC;AACzB,kBAAgB,MAAM;AACpB,aAAS,UAAU;AACnB,aAAS,UAAU;AAAA,EACrB,GAAG,CAAC,OAAO,KAAK,CAAC;AACjB,QAAM,SAAS,CAAC,CAAC,SAAS,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L,SAAS;AAAA,gBACT,WAAU;AAAA,gBAET,iBAAO;AAAA;AAAA,YACV;AAAA,YACA,qBAAC,SAAI,WAAU,2BACb;AAAA,kCAAC,UAAK,WAAU,yEACb,iBAAO,KAAK,QAAQ,GAAG,KAAK,GAC/B;AAAA,cACC,CAAC,WACA,oBAAC,UAAO,SAAQ,aAAY,SAAS,QAAQ,WAAU,uBACpD,iBAAO,MACV;AAAA,cAUD,EAAE,KAAK,cAAc,KAAK,UAAU,SACnC,oBAAC,UAAO,SAAQ,SAAQ,SAAS,QAAQ,WAAW,GAAG,qBAAqB,GACzE,mBAAS,OAAO,OAAO,OAAO,MACjC;AAAA,eAEJ;AAAA,aACF;AAAA,UACC,KAAK,cAAc,KAAK,UAAU,QACjC,oBAAC,SAAI,WAAU,6DACZ,iBAAO,gBACV;AAAA,WAEJ;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, ReactElement } from 'react';
|
|
3
|
-
import { f as ButtonVariant } from '../kit-labels-
|
|
3
|
+
import { f as ButtonVariant } from '../kit-labels-Mz8zZHIF.js';
|
|
4
4
|
import { UseWizardReturn, WizardLabels } from './types.js';
|
|
5
5
|
import '../components/data-table-labels.js';
|
|
6
6
|
import '../components/mini-calendar.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, 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";
|
|
@@ -91,7 +91,9 @@ function useWizard(options) {
|
|
|
91
91
|
onValidationFailed
|
|
92
92
|
} = options;
|
|
93
93
|
const stepsRef = useRef(steps);
|
|
94
|
-
|
|
94
|
+
useLayoutEffect(() => {
|
|
95
|
+
stepsRef.current = steps;
|
|
96
|
+
}, [steps]);
|
|
95
97
|
const wizardLabels = useKitLabels("wizard", DEFAULT_WIZARD_LABELS, {
|
|
96
98
|
missingRequired: missingRequiredMessage
|
|
97
99
|
});
|
|
@@ -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, 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 { toast } from \"../components/toast\";\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 // The kit's `toast` loads sonner (an optional peer) lazily, so an app\n // that never trips this never has to install it.\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;AACtC,SAAS,aAAa;AA0BtB,SAAS,cAAc,OAAwE;AAC7F,SAAO,MAAM,uBAAuB,QAAQ,MAAM,mBAAmB,MAAM;AAC7E;AAGA,SAAS,cACP,OACA,OACA;AACA,SAAO,cAAc,KAAK,KAAK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BAAuB;AAAA,IACxC;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;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,cAAc,MAAM;AAAA,IACpB,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;AAQA,SAAS,sBAAsB,OAAe,OAA2B;AACvE,QAAM,CAAC,EAAE,YAAY,IAAI,gBAAgB;AACzC,QAAM,UAAU,OAAO,KAAK;AAC5B,YAAU,MAAM;AACd,QAAI,QAAQ,QAAS;AACrB,iBAAa,CAAC,SAAS;AACrB,WAAK,IAAI,OAAO,OAAO,KAAK,CAAC;AAC7B,aAAO;AAAA,IACT,GAAG,EAAE,SAAS,KAAK,CAAC;AAAA,EACtB,GAAG,CAAC,OAAO,OAAO,YAAY,CAAC;AAC/B,SAAO,YAAY,MAAM;AACvB,QAAI,QAAQ,QAAS;AACrB,YAAQ,UAAU;AAClB,iBAAa,CAAC,SAAS;AACrB,WAAK,OAAO,KAAK;AACjB,aAAO;AAAA,IACT,GAAG,EAAE,SAAS,KAAK,CAAC;AAAA,EACtB,GAAG,CAAC,OAAO,YAAY,CAAC;AAC1B;AAGA,SAAS,aAAa,QAAgB,QAA4B;AAChE,SAAO;AACT;AAEA,SAAS,OAAO;AAAC;","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, useLayoutEffect, useReducer, useRef, useState } from \"react\";\nimport { useSearchParams } from \"react-router\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_WIZARD_LABELS } from \"./types\";\nimport { toast } from \"../components/toast\";\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 // The latest `steps`, for the stable callbacks below. Synced after commit (before\n // paint, and before any handler can run) rather than written during render.\n const stepsRef = useRef<WizardStepConfig[]>(steps);\n useLayoutEffect(() => {\n stepsRef.current = steps;\n }, [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`: reading a ref in render is what the hooks\n // linter (rightly) objects to, and the ref only catches up after the commit.\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 // The kit's `toast` loads sonner (an optional peer) lazily, so an app\n // that never trips this never has to install it.\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,iBAAiB,YAAY,QAAQ,gBAAgB;AACtF,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AACtC,SAAS,aAAa;AA0BtB,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,M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IACZ;AAAA,IACA,cAAc,MAAM;AAAA,IACpB,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;AAQA,SAAS,sBAAsB,OAAe,OAA2B;AACvE,QAAM,CAAC,EAAE,YAAY,IAAI,gBAAgB;AACzC,QAAM,UAAU,OAAO,KAAK;AAC5B,YAAU,MAAM;AACd,QAAI,QAAQ,QAAS;AACrB,iBAAa,CAAC,SAAS;AACrB,WAAK,IAAI,OAAO,OAAO,KAAK,CAAC;AAC7B,aAAO;AAAA,IACT,GAAG,EAAE,SAAS,KAAK,CAAC;AAAA,EACtB,GAAG,CAAC,OAAO,OAAO,YAAY,CAAC;AAC/B,SAAO,YAAY,MAAM;AACvB,QAAI,QAAQ,QAAS;AACrB,YAAQ,UAAU;AAClB,iBAAa,CAAC,SAAS;AACrB,WAAK,OAAO,KAAK;AACjB,aAAO;AAAA,IACT,GAAG,EAAE,SAAS,KAAK,CAAC;AAAA,EACtB,GAAG,CAAC,OAAO,YAAY,CAAC;AAC1B;AAGA,SAAS,aAAa,QAAgB,QAA4B;AAChE,SAAO;AACT;AAEA,SAAS,OAAO;AAAC;","names":[]}
|
|
@@ -14,6 +14,16 @@ interface WizardStepProps {
|
|
|
14
14
|
/** The line under the title: what the step asks for, or why. Rendered only with a
|
|
15
15
|
* `title` or on its own when there is none. */
|
|
16
16
|
description?: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Controls for the step as a whole, at the end of the header row beside the title —
|
|
19
|
+
* kastlan 43: the buildings step's "Add building" had nowhere to go but UNDER the
|
|
20
|
+
* list it adds to, where it falls below the fold once there are three buildings.
|
|
21
|
+
* A header action is where every other kit surface (`PageHeader`, `Card`) puts it.
|
|
22
|
+
*
|
|
23
|
+
* Wraps under the title on a narrow screen rather than squeezing it. Renders the
|
|
24
|
+
* header on its own if there is no `title` either.
|
|
25
|
+
*/
|
|
26
|
+
actions?: ReactNode;
|
|
17
27
|
/** The heading's level. Default 3: the page has its `h1` and the wizard's own
|
|
18
28
|
* chrome sits at `h2` (the review step, the cancel dialog), so a step is under it. */
|
|
19
29
|
headingLevel?: 2 | 3 | 4;
|
|
@@ -21,6 +31,6 @@ interface WizardStepProps {
|
|
|
21
31
|
/** The vertical rhythm one wizard step's content sits on. A component rather
|
|
22
32
|
* than a class string so every step in every app spaces its fields the same —
|
|
23
33
|
* and, with `title` / `description`, heads them the same. */
|
|
24
|
-
declare function WizardStep({ children, className, title, description, headingLevel, }: WizardStepProps): react.JSX.Element;
|
|
34
|
+
declare function WizardStep({ children, className, title, description, headingLevel, actions, }: WizardStepProps): react.JSX.Element;
|
|
25
35
|
|
|
26
36
|
export { WizardStep, type WizardStepProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { cn } from "../lib/cn.js";
|
|
4
4
|
const HEADING = { 2: "h2", 3: "h3", 4: "h4" };
|
|
5
5
|
function WizardStep({
|
|
@@ -7,16 +7,34 @@ function WizardStep({
|
|
|
7
7
|
className,
|
|
8
8
|
title,
|
|
9
9
|
description,
|
|
10
|
-
headingLevel = 3
|
|
10
|
+
headingLevel = 3,
|
|
11
|
+
actions
|
|
11
12
|
}) {
|
|
12
13
|
const hasTitle = title !== void 0 && title !== null && title !== false && title !== "";
|
|
13
14
|
const hasDescription = description !== void 0 && description !== null && description !== false && description !== "";
|
|
15
|
+
const hasActions = actions !== void 0 && actions !== null && actions !== false && actions !== "";
|
|
14
16
|
const Heading = HEADING[headingLevel];
|
|
17
|
+
const heading = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
18
|
+
hasTitle && /* @__PURE__ */ jsx(Heading, { className: "text-lg font-semibold text-[var(--text-primary)]", children: title }),
|
|
19
|
+
hasDescription && /* @__PURE__ */ jsx("p", { className: "text-sm text-[var(--text-muted)]", children: description })
|
|
20
|
+
] });
|
|
15
21
|
return /* @__PURE__ */ jsxs("div", { className: cn("space-y-6", className), children: [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
hasActions ? (
|
|
23
|
+
// One row: the text takes the room, the actions keep their width at the end
|
|
24
|
+
// and wrap below it when there is not enough — `basis-64` is the width the
|
|
25
|
+
// title asks for before that happens (a zero basis would never wrap and
|
|
26
|
+
// squeeze the title to a word a line instead). `items-start` so a two-line
|
|
27
|
+
// description does not pull the button down to its middle; `ms-auto` keeps
|
|
28
|
+
// the actions at the end with no title, and when they wrap.
|
|
29
|
+
/* @__PURE__ */ jsxs("div", { "data-slot": "wizard-step-header", className: "flex flex-wrap items-start justify-between gap-x-4 gap-y-2", children: [
|
|
30
|
+
(hasTitle || hasDescription) && /* @__PURE__ */ jsx("div", { className: "min-w-0 grow basis-64 space-y-1", children: heading }),
|
|
31
|
+
/* @__PURE__ */ jsx("div", { "data-slot": "wizard-step-actions", className: "ms-auto flex shrink-0 flex-wrap items-center gap-2", children: actions })
|
|
32
|
+
] })
|
|
33
|
+
) : (
|
|
34
|
+
// Without actions the header is exactly what it was, so a step that passes
|
|
35
|
+
// none renders as before.
|
|
36
|
+
(hasTitle || hasDescription) && /* @__PURE__ */ jsx("div", { "data-slot": "wizard-step-header", className: "space-y-1", children: heading })
|
|
37
|
+
),
|
|
20
38
|
children
|
|
21
39
|
] });
|
|
22
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wizard/wizard-step.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\n\nexport interface WizardStepProps {\n children: ReactNode;\n className?: string;\n /**\n * The step's heading (\"Choose a unit\"), drawn in the one style every step shares.\n * kastlan's steps each hand-wrote `<h3 className=\"text-lg font-semibold\">` (about\n * sixteen of them: lease-picker-step, lease-unit-step, …), and a hand-written\n * heading is one that drifts — a size here, a colour there. Omitted: no heading.\n */\n title?: ReactNode;\n /** The line under the title: what the step asks for, or why. Rendered only with a\n * `title` or on its own when there is none. */\n description?: ReactNode;\n /** The heading's level. Default 3: the page has its `h1` and the wizard's own\n * chrome sits at `h2` (the review step, the cancel dialog), so a step is under it. */\n headingLevel?: 2 | 3 | 4;\n}\n\nconst HEADING = { 2: \"h2\", 3: \"h3\", 4: \"h4\" } as const;\n\n/** The vertical rhythm one wizard step's content sits on. A component rather\n * than a class string so every step in every app spaces its fields the same —\n * and, with `title` / `description`, heads them the same. */\nexport function WizardStep({\n children,\n className,\n title,\n description,\n headingLevel = 3,\n}: WizardStepProps) {\n const hasTitle = title !== undefined && title !== null && title !== false && title !== \"\";\n const hasDescription =\n description !== undefined && description !== null && description !== false && description !== \"\";\n const Heading = HEADING[headingLevel];\n return (\n <div className={cn(\"space-y-6\", className)}>\n {(
|
|
1
|
+
{"version":3,"sources":["../../src/wizard/wizard-step.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\n\nexport interface WizardStepProps {\n children: ReactNode;\n className?: string;\n /**\n * The step's heading (\"Choose a unit\"), drawn in the one style every step shares.\n * kastlan's steps each hand-wrote `<h3 className=\"text-lg font-semibold\">` (about\n * sixteen of them: lease-picker-step, lease-unit-step, …), and a hand-written\n * heading is one that drifts — a size here, a colour there. Omitted: no heading.\n */\n title?: ReactNode;\n /** The line under the title: what the step asks for, or why. Rendered only with a\n * `title` or on its own when there is none. */\n description?: ReactNode;\n /**\n * Controls for the step as a whole, at the end of the header row beside the title —\n * kastlan 43: the buildings step's \"Add building\" had nowhere to go but UNDER the\n * list it adds to, where it falls below the fold once there are three buildings.\n * A header action is where every other kit surface (`PageHeader`, `Card`) puts it.\n *\n * Wraps under the title on a narrow screen rather than squeezing it. Renders the\n * header on its own if there is no `title` either.\n */\n actions?: ReactNode;\n /** The heading's level. Default 3: the page has its `h1` and the wizard's own\n * chrome sits at `h2` (the review step, the cancel dialog), so a step is under it. */\n headingLevel?: 2 | 3 | 4;\n}\n\nconst HEADING = { 2: \"h2\", 3: \"h3\", 4: \"h4\" } as const;\n\n/** The vertical rhythm one wizard step's content sits on. A component rather\n * than a class string so every step in every app spaces its fields the same —\n * and, with `title` / `description`, heads them the same. */\nexport function WizardStep({\n children,\n className,\n title,\n description,\n headingLevel = 3,\n actions,\n}: WizardStepProps) {\n const hasTitle = title !== undefined && title !== null && title !== false && title !== \"\";\n const hasDescription =\n description !== undefined && description !== null && description !== false && description !== \"\";\n const hasActions = actions !== undefined && actions !== null && actions !== false && actions !== \"\";\n const Heading = HEADING[headingLevel];\n const heading = (\n <>\n {hasTitle && <Heading className=\"text-lg font-semibold text-[var(--text-primary)]\">{title}</Heading>}\n {hasDescription && <p className=\"text-sm text-[var(--text-muted)]\">{description}</p>}\n </>\n );\n return (\n <div className={cn(\"space-y-6\", className)}>\n {hasActions ? (\n // One row: the text takes the room, the actions keep their width at the end\n // and wrap below it when there is not enough — `basis-64` is the width the\n // title asks for before that happens (a zero basis would never wrap and\n // squeeze the title to a word a line instead). `items-start` so a two-line\n // description does not pull the button down to its middle; `ms-auto` keeps\n // the actions at the end with no title, and when they wrap.\n <div data-slot=\"wizard-step-header\" className=\"flex flex-wrap items-start justify-between gap-x-4 gap-y-2\">\n {(hasTitle || hasDescription) && <div className=\"min-w-0 grow basis-64 space-y-1\">{heading}</div>}\n <div data-slot=\"wizard-step-actions\" className=\"ms-auto flex shrink-0 flex-wrap items-center gap-2\">\n {actions}\n </div>\n </div>\n ) : (\n // Without actions the header is exactly what it was, so a step that passes\n // none renders as before.\n (hasTitle || hasDescription) && (\n <div data-slot=\"wizard-step-header\" className=\"space-y-1\">\n {heading}\n </div>\n )\n )}\n {children}\n </div>\n );\n}\n"],"mappings":";AAkDI,mBACe,KADf;AAjDJ,SAAS,UAAU;AA8BnB,MAAM,UAAU,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AAKrC,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf;AACF,GAAoB;AAClB,QAAM,WAAW,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AACvF,QAAM,iBACJ,gBAAgB,UAAa,gBAAgB,QAAQ,gBAAgB,SAAS,gBAAgB;AAChG,QAAM,aAAa,YAAY,UAAa,YAAY,QAAQ,YAAY,SAAS,YAAY;AACjG,QAAM,UAAU,QAAQ,YAAY;AACpC,QAAM,UACJ,iCACG;AAAA,gBAAY,oBAAC,WAAQ,WAAU,oDAAoD,iBAAM;AAAA,IACzF,kBAAkB,oBAAC,OAAE,WAAU,oCAAoC,uBAAY;AAAA,KAClF;AAEF,SACE,qBAAC,SAAI,WAAW,GAAG,aAAa,SAAS,GACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOC,qBAAC,SAAI,aAAU,sBAAqB,WAAU,8DAC1C;AAAA,qBAAY,mBAAmB,oBAAC,SAAI,WAAU,mCAAmC,mBAAQ;AAAA,QAC3F,oBAAC,SAAI,aAAU,uBAAsB,WAAU,sDAC5C,mBACH;AAAA,SACF;AAAA;AAAA;AAAA;AAAA,OAIC,YAAY,mBACX,oBAAC,SAAI,aAAU,sBAAqB,WAAU,aAC3C,mBACH;AAAA;AAAA,IAGH;AAAA,KACH;AAEJ;","names":[]}
|
package/dist/wizard.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { WizardStep, WizardStepProps } from './wizard/wizard-step.js';
|
|
|
6
6
|
export { WizardSummary } from './wizard/wizard-summary.js';
|
|
7
7
|
export { StepperNav } from './wizard/stepper-nav.js';
|
|
8
8
|
import 'react';
|
|
9
|
-
import './kit-labels-
|
|
9
|
+
import './kit-labels-Mz8zZHIF.js';
|
|
10
10
|
import './components/data-table-labels.js';
|
|
11
11
|
import './components/mini-calendar.js';
|
|
12
12
|
import './components/calendar-heatmap.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eifi1/ui-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "App-agnostic shared design system: domain-free React components, theme and tokens.",
|
|
6
6
|
"_sideEffects": "The barrel (src/index.ts) re-exports EVERY component, including components/chart, which statically imports recharts. Without this field a bundler must assume each of those modules has side effects, so it cannot drop the unused ones: importing a Button from '@eifi1/ui-kit' dragged all 433KB of recharts into the consumer's ENTRY chunk, and Keksdose was preloading it on every page load, login included. Nothing in src/ imports for side effects (no bare imports, no CSS imports from JS, no module-level global writes) — the token stylesheet is its own './tokens.css' export — so this is safe. CSS is still listed so any future stylesheet survives. Re-checked when `flag-icons` left `dependencies` and tsup started emitting a `\"use client\"` banner: neither touches this. The flag stylesheet was never imported from JS in the first place (that was the finding), and a directive prologue is a string literal every bundler lifts out before it decides whether a module is inert.",
|
|
@@ -68,23 +68,23 @@
|
|
|
68
68
|
"LICENSE"
|
|
69
69
|
],
|
|
70
70
|
"scripts": {
|
|
71
|
-
"typecheck": "tsc --noEmit",
|
|
72
|
-
"lint": "eslint .",
|
|
71
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.node.json",
|
|
72
|
+
"lint": "eslint . --max-warnings 0",
|
|
73
73
|
"check:tokens": "node scripts/check-token-discipline.mjs",
|
|
74
74
|
"test:coverage": "vitest run --coverage",
|
|
75
75
|
"check:graph": "node scripts/check-module-graph.mjs",
|
|
76
|
-
"check:package": "node scripts/verify-package.mjs",
|
|
76
|
+
"check:package": "node scripts/verify-package.mjs --quiet",
|
|
77
77
|
"check:tailwind": "node scripts/check-tailwind-scan.mjs",
|
|
78
78
|
"check:security": "npm audit --audit-level=high",
|
|
79
79
|
"check:commits": "node scripts/check-commit-range.cjs",
|
|
80
80
|
"check": "npm run typecheck && npm run lint && npm run check:tokens && npm run test:coverage && npm run build && npm run check:graph && npm run check:package && npm run build:showcase && npm run check:tailwind && npm run check:security && npm run check:commits",
|
|
81
81
|
"test": "vitest run",
|
|
82
82
|
"test:watch": "vitest",
|
|
83
|
-
"build": "tsup && node scripts/fix-esm-extensions.mjs",
|
|
83
|
+
"build": "node scripts/tsup-quiet.mjs && node scripts/fix-esm-extensions.mjs",
|
|
84
84
|
"verify:package": "npm run build && node scripts/verify-package.mjs",
|
|
85
85
|
"dev": "tsup --watch",
|
|
86
86
|
"dev:showcase": "vite --config showcase/vite.config.ts",
|
|
87
|
-
"build:showcase": "vite build --config showcase/vite.config.ts",
|
|
87
|
+
"build:showcase": "vite build --config showcase/vite.config.ts --logLevel warn",
|
|
88
88
|
"preview:showcase": "vite preview --config showcase/vite.config.ts",
|
|
89
89
|
"prepublishOnly": "npm run build",
|
|
90
90
|
"release": "commit-and-tag-version",
|