react-wizard-engine 0.1.3 → 0.1.4
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/CHANGELOG.md +6 -0
- package/dist/chunk-5ZSA2PNS.js +76 -0
- package/dist/chunk-5ZSA2PNS.js.map +1 -0
- package/dist/chunk-XNH2LQZL.cjs +76 -0
- package/dist/chunk-XNH2LQZL.cjs.map +1 -0
- package/dist/index.cjs +388 -548
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -104
- package/dist/index.js.map +1 -1
- package/dist/shadcn/index.cjs +64 -156
- package/dist/shadcn/index.cjs.map +1 -1
- package/dist/shadcn/index.js +32 -83
- package/dist/shadcn/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
WizardComponentsProvider,
|
|
4
|
+
WizardEngineContext,
|
|
5
|
+
WizardError,
|
|
6
|
+
WizardInitializationError,
|
|
7
|
+
WizardNavigationError,
|
|
8
|
+
WizardResolverError,
|
|
9
|
+
cn,
|
|
10
|
+
useWizard,
|
|
11
|
+
useWizardComponents
|
|
12
|
+
} from "./chunk-5ZSA2PNS.js";
|
|
2
13
|
|
|
3
14
|
// src/enums/wizard-event-type.enum.ts
|
|
4
15
|
var WizardEventType = /* @__PURE__ */ ((WizardEventType2) => {
|
|
@@ -210,24 +221,6 @@ var wizardDefaultState = {
|
|
|
210
221
|
};
|
|
211
222
|
var wizardDefaultBranch = "main";
|
|
212
223
|
|
|
213
|
-
// src/core/errors/wizard.error.ts
|
|
214
|
-
var WizardError = class extends Error {
|
|
215
|
-
name = "WizardError";
|
|
216
|
-
constructor(message) {
|
|
217
|
-
super(message);
|
|
218
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
var WizardInitializationError = class extends WizardError {
|
|
222
|
-
name = "WizardInitializationError";
|
|
223
|
-
};
|
|
224
|
-
var WizardNavigationError = class extends WizardError {
|
|
225
|
-
name = "WizardNavigationError";
|
|
226
|
-
};
|
|
227
|
-
var WizardResolverError = class extends WizardError {
|
|
228
|
-
name = "WizardResolverError";
|
|
229
|
-
};
|
|
230
|
-
|
|
231
224
|
// src/core/rules/wizard-rule.ts
|
|
232
225
|
var WizardRule = class {
|
|
233
226
|
};
|
|
@@ -1693,61 +1686,22 @@ var WizardCategoryDirection = /* @__PURE__ */ ((WizardCategoryDirection2) => {
|
|
|
1693
1686
|
return WizardCategoryDirection2;
|
|
1694
1687
|
})(WizardCategoryDirection || {});
|
|
1695
1688
|
|
|
1696
|
-
// src/react/components-provider.tsx
|
|
1697
|
-
import { createContext, useContext } from "react";
|
|
1698
|
-
import { jsx } from "react/jsx-runtime";
|
|
1699
|
-
var FallbackButton = (props) => {
|
|
1700
|
-
const { children, asChild: _asChild, variant: _variant, size: _size, ...rest } = props;
|
|
1701
|
-
return /* @__PURE__ */ jsx("button", { ...rest, type: props.type ?? "button", children });
|
|
1702
|
-
};
|
|
1703
|
-
var FallbackBackArrowIcon = ({ className }) => /* @__PURE__ */ jsx("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10 4 L6 8 L10 12", stroke: "currentColor", strokeWidth: "1.5", fill: "none" }) });
|
|
1704
|
-
var defaults = { Button: FallbackButton, BackArrowIcon: FallbackBackArrowIcon };
|
|
1705
|
-
var WizardComponentsContext = createContext(defaults);
|
|
1706
|
-
function WizardComponentsProvider(props) {
|
|
1707
|
-
const { Button, BackArrowIcon, children } = props;
|
|
1708
|
-
const value = {
|
|
1709
|
-
Button: Button ?? defaults.Button,
|
|
1710
|
-
BackArrowIcon: BackArrowIcon ?? defaults.BackArrowIcon
|
|
1711
|
-
};
|
|
1712
|
-
return /* @__PURE__ */ jsx(WizardComponentsContext.Provider, { value, children });
|
|
1713
|
-
}
|
|
1714
|
-
function useWizardComponents() {
|
|
1715
|
-
return useContext(WizardComponentsContext);
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
// src/react/use-wizard.ts
|
|
1719
|
-
import { useContext as useContext2, useSyncExternalStore } from "react";
|
|
1720
|
-
|
|
1721
|
-
// src/react/context.ts
|
|
1722
|
-
import { createContext as createContext2 } from "react";
|
|
1723
|
-
var WizardEngineContext = createContext2(null);
|
|
1724
|
-
|
|
1725
|
-
// src/react/use-wizard.ts
|
|
1726
|
-
function useWizard() {
|
|
1727
|
-
const engine = useContext2(WizardEngineContext);
|
|
1728
|
-
if (!engine) {
|
|
1729
|
-
throw new WizardError("useWizard must be used inside <WizardProvider>");
|
|
1730
|
-
}
|
|
1731
|
-
useSyncExternalStore(engine.subscribe, engine.getTreeSnapshot, engine.getTreeSnapshot);
|
|
1732
|
-
return engine;
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
1689
|
// src/react/components/wizard-action-button.tsx
|
|
1736
1690
|
import { Slot } from "@radix-ui/react-slot";
|
|
1737
|
-
import { jsx
|
|
1691
|
+
import { jsx } from "react/jsx-runtime";
|
|
1738
1692
|
function WizardActionButton(props) {
|
|
1739
1693
|
const { Button } = useWizardComponents();
|
|
1740
1694
|
if (props.asChild) {
|
|
1741
|
-
return /* @__PURE__ */
|
|
1695
|
+
return /* @__PURE__ */ jsx(Slot, { className: props.className, onClick: props.onClick, children: props.children });
|
|
1742
1696
|
}
|
|
1743
|
-
return /* @__PURE__ */
|
|
1697
|
+
return /* @__PURE__ */ jsx(Button, { className: props.className, onClick: props.onClick, type: "button", variant: props.variant, children: props.children ?? props.defaultLabel });
|
|
1744
1698
|
}
|
|
1745
1699
|
|
|
1746
1700
|
// src/react/components/wizard-back.tsx
|
|
1747
|
-
import { jsx as
|
|
1701
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1748
1702
|
function WizardBack(props) {
|
|
1749
1703
|
const wizard = useWizard();
|
|
1750
|
-
return /* @__PURE__ */
|
|
1704
|
+
return /* @__PURE__ */ jsx2(
|
|
1751
1705
|
WizardActionButton,
|
|
1752
1706
|
{
|
|
1753
1707
|
asChild: props.asChild,
|
|
@@ -1761,28 +1715,21 @@ function WizardBack(props) {
|
|
|
1761
1715
|
}
|
|
1762
1716
|
|
|
1763
1717
|
// src/react/components/wizard-category.tsx
|
|
1764
|
-
import { Fragment, jsx as
|
|
1718
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
1765
1719
|
function WizardCategory(props) {
|
|
1766
1720
|
const wizard = useWizard();
|
|
1767
1721
|
if (wizard.tree.activeCategory.id !== props.categoryId) return null;
|
|
1768
|
-
return /* @__PURE__ */
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
// src/utils/cn.ts
|
|
1772
|
-
import { clsx } from "clsx";
|
|
1773
|
-
import { twMerge } from "tailwind-merge";
|
|
1774
|
-
function cn(...inputs) {
|
|
1775
|
-
return twMerge(clsx(...inputs));
|
|
1722
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: props.children });
|
|
1776
1723
|
}
|
|
1777
1724
|
|
|
1778
1725
|
// src/react/components/wizard-stepper-dot.tsx
|
|
1779
1726
|
import { CheckIcon } from "lucide-react";
|
|
1780
|
-
import { jsx as
|
|
1727
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
1781
1728
|
function WizardStepperDot(props) {
|
|
1782
1729
|
const { clickable = false, isLast = false, label, onClick, progress, state } = props;
|
|
1783
1730
|
const isInteractive = clickable && !!onClick;
|
|
1784
1731
|
return /* @__PURE__ */ jsxs("li", { className: "relative flex flex-1 items-center", "data-state": state, children: [
|
|
1785
|
-
/* @__PURE__ */
|
|
1732
|
+
/* @__PURE__ */ jsx4(
|
|
1786
1733
|
"button",
|
|
1787
1734
|
{
|
|
1788
1735
|
"aria-current": state === "active" ? "step" : void 0,
|
|
@@ -1799,17 +1746,17 @@ function WizardStepperDot(props) {
|
|
|
1799
1746
|
disabled: !isInteractive,
|
|
1800
1747
|
onClick: isInteractive ? onClick : void 0,
|
|
1801
1748
|
type: "button",
|
|
1802
|
-
children: state === "completed" && /* @__PURE__ */
|
|
1749
|
+
children: state === "completed" && /* @__PURE__ */ jsx4(CheckIcon, { className: "size-2 text-background" })
|
|
1803
1750
|
}
|
|
1804
1751
|
),
|
|
1805
|
-
!isLast && /* @__PURE__ */
|
|
1752
|
+
!isLast && /* @__PURE__ */ jsx4("span", { "aria-hidden": true, className: "relative ml-1 mr-1 h-px flex-1 bg-border", children: /* @__PURE__ */ jsx4(
|
|
1806
1753
|
"span",
|
|
1807
1754
|
{
|
|
1808
1755
|
className: "absolute inset-y-0 left-0 bg-success-border transition-[width]",
|
|
1809
1756
|
style: { width: `${Math.max(0, Math.min(100, progress))}%` }
|
|
1810
1757
|
}
|
|
1811
1758
|
) }),
|
|
1812
|
-
label && /* @__PURE__ */
|
|
1759
|
+
label && /* @__PURE__ */ jsx4(
|
|
1813
1760
|
"span",
|
|
1814
1761
|
{
|
|
1815
1762
|
className: cn(
|
|
@@ -1824,7 +1771,7 @@ function WizardStepperDot(props) {
|
|
|
1824
1771
|
}
|
|
1825
1772
|
|
|
1826
1773
|
// src/react/components/wizard-stepper.tsx
|
|
1827
|
-
import { jsx as
|
|
1774
|
+
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1828
1775
|
function WizardStepper(props) {
|
|
1829
1776
|
const { canAccessCategory, categories, doneDot, headerI18n, onCategoryClick, progress } = props;
|
|
1830
1777
|
const lastIdx = categories.length - 1;
|
|
@@ -1832,7 +1779,7 @@ function WizardStepper(props) {
|
|
|
1832
1779
|
categories.map((category, idx) => {
|
|
1833
1780
|
const isLast = idx === lastIdx && !doneDot;
|
|
1834
1781
|
const clickable = canAccessCategory?.(category) ?? false;
|
|
1835
|
-
return /* @__PURE__ */
|
|
1782
|
+
return /* @__PURE__ */ jsx5(
|
|
1836
1783
|
WizardStepperDot,
|
|
1837
1784
|
{
|
|
1838
1785
|
clickable,
|
|
@@ -1845,7 +1792,7 @@ function WizardStepper(props) {
|
|
|
1845
1792
|
category.id
|
|
1846
1793
|
);
|
|
1847
1794
|
}),
|
|
1848
|
-
doneDot && /* @__PURE__ */
|
|
1795
|
+
doneDot && /* @__PURE__ */ jsx5(WizardStepperDot, { isLast: true, label: doneDot.text, progress: 0, state: "pending" })
|
|
1849
1796
|
] });
|
|
1850
1797
|
}
|
|
1851
1798
|
function getDotState(category, progress) {
|
|
@@ -1856,7 +1803,7 @@ function getDotState(category, progress) {
|
|
|
1856
1803
|
}
|
|
1857
1804
|
|
|
1858
1805
|
// src/react/components/wizard-header.tsx
|
|
1859
|
-
import { jsx as
|
|
1806
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1860
1807
|
function WizardHeader() {
|
|
1861
1808
|
const wizard = useWizard();
|
|
1862
1809
|
const tree = wizard.tree;
|
|
@@ -1894,8 +1841,8 @@ function WizardHeader() {
|
|
|
1894
1841
|
config.stickyHeader && "sticky top-0 z-10"
|
|
1895
1842
|
),
|
|
1896
1843
|
children: [
|
|
1897
|
-
/* @__PURE__ */
|
|
1898
|
-
showSteps && /* @__PURE__ */
|
|
1844
|
+
/* @__PURE__ */ jsx6(WizardBack, {}),
|
|
1845
|
+
showSteps && /* @__PURE__ */ jsx6(
|
|
1899
1846
|
WizardStepper,
|
|
1900
1847
|
{
|
|
1901
1848
|
canAccessCategory,
|
|
@@ -1912,11 +1859,11 @@ function WizardHeader() {
|
|
|
1912
1859
|
}
|
|
1913
1860
|
|
|
1914
1861
|
// src/react/components/wizard-next.tsx
|
|
1915
|
-
import { jsx as
|
|
1862
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1916
1863
|
function WizardNext(props) {
|
|
1917
1864
|
const wizard = useWizard();
|
|
1918
1865
|
const defaultLabel = !props.asChild && props.children === void 0 ? getNextLabel(wizard) : "";
|
|
1919
|
-
return /* @__PURE__ */
|
|
1866
|
+
return /* @__PURE__ */ jsx7(
|
|
1920
1867
|
WizardActionButton,
|
|
1921
1868
|
{
|
|
1922
1869
|
asChild: props.asChild,
|
|
@@ -1965,20 +1912,20 @@ function projectCategory(category) {
|
|
|
1965
1912
|
}
|
|
1966
1913
|
|
|
1967
1914
|
// src/react/components/wizard-rail.tsx
|
|
1968
|
-
import { jsx as
|
|
1915
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1969
1916
|
function WizardRail(props) {
|
|
1970
1917
|
const { canAccessCategory, className, headerI18n, subStepLabels } = props;
|
|
1971
1918
|
const wizard = useWizard();
|
|
1972
1919
|
const view = useWizardCategoriesView();
|
|
1973
1920
|
const labels = headerI18n ?? wizard.configOptions.headerI18n;
|
|
1974
1921
|
const isClickable = (category) => canAccessCategory?.(category) ?? defaultClickable(category.state);
|
|
1975
|
-
return /* @__PURE__ */
|
|
1922
|
+
return /* @__PURE__ */ jsx8("nav", { "aria-label": "Wizard steps", className: cn("flex flex-col gap-1", className), children: /* @__PURE__ */ jsx8("ol", { className: "relative flex flex-col gap-1", children: view.map((category, idx) => {
|
|
1976
1923
|
const label = labels?.[category.id] ?? String(category.id);
|
|
1977
1924
|
const clickable = isClickable(category);
|
|
1978
1925
|
const isLast = idx === view.length - 1;
|
|
1979
1926
|
const isPassed = category.state === "completed" || category.state === "skipped";
|
|
1980
1927
|
return /* @__PURE__ */ jsxs4("li", { className: "relative", children: [
|
|
1981
|
-
!isLast && /* @__PURE__ */
|
|
1928
|
+
!isLast && /* @__PURE__ */ jsx8(
|
|
1982
1929
|
"span",
|
|
1983
1930
|
{
|
|
1984
1931
|
"aria-hidden": true,
|
|
@@ -2007,12 +1954,12 @@ function WizardRail(props) {
|
|
|
2007
1954
|
},
|
|
2008
1955
|
type: "button",
|
|
2009
1956
|
children: [
|
|
2010
|
-
/* @__PURE__ */
|
|
2011
|
-
/* @__PURE__ */
|
|
1957
|
+
/* @__PURE__ */ jsx8(RailDot, { state: category.state }),
|
|
1958
|
+
/* @__PURE__ */ jsx8("span", { children: label })
|
|
2012
1959
|
]
|
|
2013
1960
|
}
|
|
2014
1961
|
),
|
|
2015
|
-
category.isActive && category.subSteps.length > 0 && /* @__PURE__ */
|
|
1962
|
+
category.isActive && category.subSteps.length > 0 && /* @__PURE__ */ jsx8("ol", { className: "mt-1 ml-7 flex flex-col gap-1 border-l border-border pl-3", children: category.subSteps.map((step) => /* @__PURE__ */ jsx8(
|
|
2016
1963
|
"li",
|
|
2017
1964
|
{
|
|
2018
1965
|
"aria-current": step.isActive ? "step" : void 0,
|
|
@@ -2031,7 +1978,7 @@ function defaultClickable(state) {
|
|
|
2031
1978
|
return state !== "pending";
|
|
2032
1979
|
}
|
|
2033
1980
|
function RailDot({ state }) {
|
|
2034
|
-
return /* @__PURE__ */
|
|
1981
|
+
return /* @__PURE__ */ jsx8(
|
|
2035
1982
|
"span",
|
|
2036
1983
|
{
|
|
2037
1984
|
"aria-hidden": true,
|
|
@@ -2042,23 +1989,23 @@ function RailDot({ state }) {
|
|
|
2042
1989
|
state === "completed" && "border-success-border bg-success-text",
|
|
2043
1990
|
state === "skipped" && "border-border bg-background opacity-60"
|
|
2044
1991
|
),
|
|
2045
|
-
children: state === "completed" && /* @__PURE__ */
|
|
1992
|
+
children: state === "completed" && /* @__PURE__ */ jsx8(CheckIcon2, { className: "size-2.5 text-background motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-75 motion-safe:duration-200" })
|
|
2046
1993
|
}
|
|
2047
1994
|
);
|
|
2048
1995
|
}
|
|
2049
1996
|
|
|
2050
1997
|
// src/react/components/wizard-step.tsx
|
|
2051
|
-
import { useCallback, useContext
|
|
2052
|
-
import { jsx as
|
|
1998
|
+
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
1999
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
2053
2000
|
function WizardStep(props) {
|
|
2054
|
-
const engine =
|
|
2001
|
+
const engine = useContext(WizardEngineContext);
|
|
2055
2002
|
if (!engine) {
|
|
2056
2003
|
throw new WizardError("WizardStep must be used inside <WizardProvider>");
|
|
2057
2004
|
}
|
|
2058
2005
|
const getSnapshot = useCallback(() => engine.isStepVisible(props.id), [engine, props.id]);
|
|
2059
|
-
const isVisible =
|
|
2006
|
+
const isVisible = useSyncExternalStore(engine.subscribe, getSnapshot, getSnapshot);
|
|
2060
2007
|
if (!isVisible) return null;
|
|
2061
|
-
return /* @__PURE__ */
|
|
2008
|
+
return /* @__PURE__ */ jsx9(
|
|
2062
2009
|
"div",
|
|
2063
2010
|
{
|
|
2064
2011
|
className: "motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-1 motion-safe:duration-300 motion-safe:ease-(--ease-out-strong)",
|
|
@@ -2070,7 +2017,7 @@ function WizardStep(props) {
|
|
|
2070
2017
|
|
|
2071
2018
|
// src/react/provider.tsx
|
|
2072
2019
|
import { useEffect, useState } from "react";
|
|
2073
|
-
import { jsx as
|
|
2020
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
2074
2021
|
function WizardProvider(props) {
|
|
2075
2022
|
const { activeBranch, children, config, initializers, listeners, scrollContainer, state, strategies } = props;
|
|
2076
2023
|
const [bootOptions] = useState(() => ({
|
|
@@ -2098,7 +2045,7 @@ function WizardProvider(props) {
|
|
|
2098
2045
|
if (!engine) {
|
|
2099
2046
|
return null;
|
|
2100
2047
|
}
|
|
2101
|
-
return /* @__PURE__ */
|
|
2048
|
+
return /* @__PURE__ */ jsx10(WizardEngineContext.Provider, { value: engine, children });
|
|
2102
2049
|
}
|
|
2103
2050
|
|
|
2104
2051
|
// src/react/use-wizard-engine-ref.ts
|
|
@@ -2120,9 +2067,9 @@ function WizardEngineRefCapture({
|
|
|
2120
2067
|
}
|
|
2121
2068
|
|
|
2122
2069
|
// src/react/use-wizard-event.ts
|
|
2123
|
-
import { useContext as
|
|
2070
|
+
import { useContext as useContext2, useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2124
2071
|
function useWizardEvent(type, handler) {
|
|
2125
|
-
const engine =
|
|
2072
|
+
const engine = useContext2(WizardEngineContext);
|
|
2126
2073
|
if (!engine) {
|
|
2127
2074
|
throw new WizardError("useWizardEvent must be used inside <WizardProvider>");
|
|
2128
2075
|
}
|
|
@@ -2136,9 +2083,9 @@ function useWizardEvent(type, handler) {
|
|
|
2136
2083
|
}
|
|
2137
2084
|
|
|
2138
2085
|
// src/react/use-wizard-step.ts
|
|
2139
|
-
import { useCallback as useCallback2, useContext as
|
|
2086
|
+
import { useCallback as useCallback2, useContext as useContext3, useRef as useRef3, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
2140
2087
|
function useWizardStep(stepId) {
|
|
2141
|
-
const engine =
|
|
2088
|
+
const engine = useContext3(WizardEngineContext);
|
|
2142
2089
|
if (!engine) {
|
|
2143
2090
|
throw new WizardError("useWizardStep must be used inside <WizardProvider>");
|
|
2144
2091
|
}
|
|
@@ -2153,7 +2100,7 @@ function useWizardStep(stepId) {
|
|
|
2153
2100
|
lastRef.current = next;
|
|
2154
2101
|
return next;
|
|
2155
2102
|
}, [engine, stepId]);
|
|
2156
|
-
return
|
|
2103
|
+
return useSyncExternalStore2(engine.subscribe, getSnapshot, getSnapshot);
|
|
2157
2104
|
}
|
|
2158
2105
|
export {
|
|
2159
2106
|
TypedEmitter,
|