@btst/plugin-cms 0.0.0-stage → 1.0.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/LICENSE.md +17 -0
- package/dist/api/getters.cjs +328 -0
- package/dist/api/getters.mjs +314 -0
- package/dist/api/index.cjs +29 -0
- package/dist/api/index.d.cts +209 -0
- package/dist/api/index.d.mts +209 -0
- package/dist/api/index.d.ts +209 -0
- package/dist/api/index.mjs +7 -0
- package/dist/api/lifecycle-migrations.cjs +13 -0
- package/dist/api/lifecycle-migrations.mjs +11 -0
- package/dist/api/mutations.cjs +59 -0
- package/dist/api/mutations.mjs +57 -0
- package/dist/api/operations.cjs +1769 -0
- package/dist/api/operations.mjs +1762 -0
- package/dist/api/plugin.cjs +337 -0
- package/dist/api/plugin.mjs +331 -0
- package/dist/api/query-key-defs.cjs +44 -0
- package/dist/api/query-key-defs.mjs +39 -0
- package/dist/api/relations.cjs +76 -0
- package/dist/api/relations.mjs +70 -0
- package/dist/client/components/forms/content-form.cjs +286 -0
- package/dist/client/components/forms/content-form.mjs +284 -0
- package/dist/client/components/forms/file-upload.cjs +160 -0
- package/dist/client/components/forms/file-upload.mjs +158 -0
- package/dist/client/components/forms/relation-field.cjs +237 -0
- package/dist/client/components/forms/relation-field.mjs +235 -0
- package/dist/client/components/index.cjs +14 -0
- package/dist/client/components/index.d.cts +20 -0
- package/dist/client/components/index.d.mts +20 -0
- package/dist/client/components/index.d.ts +20 -0
- package/dist/client/components/index.mjs +10 -0
- package/dist/client/components/inverse-relations-panel.cjs +272 -0
- package/dist/client/components/inverse-relations-panel.mjs +270 -0
- package/dist/client/components/loading/dashboard-skeleton.cjs +18 -0
- package/dist/client/components/loading/dashboard-skeleton.mjs +16 -0
- package/dist/client/components/loading/editor-skeleton.cjs +32 -0
- package/dist/client/components/loading/editor-skeleton.mjs +30 -0
- package/dist/client/components/loading/list-skeleton.cjs +32 -0
- package/dist/client/components/loading/list-skeleton.mjs +30 -0
- package/dist/client/components/pages/404-page.cjs +26 -0
- package/dist/client/components/pages/404-page.mjs +24 -0
- package/dist/client/components/pages/content-editor-page.cjs +84 -0
- package/dist/client/components/pages/content-editor-page.internal.cjs +170 -0
- package/dist/client/components/pages/content-editor-page.internal.mjs +168 -0
- package/dist/client/components/pages/content-editor-page.mjs +82 -0
- package/dist/client/components/pages/content-list-page.cjs +49 -0
- package/dist/client/components/pages/content-list-page.internal.cjs +334 -0
- package/dist/client/components/pages/content-list-page.internal.mjs +332 -0
- package/dist/client/components/pages/content-list-page.mjs +47 -0
- package/dist/client/components/pages/dashboard-page.cjs +42 -0
- package/dist/client/components/pages/dashboard-page.internal.cjs +102 -0
- package/dist/client/components/pages/dashboard-page.internal.mjs +100 -0
- package/dist/client/components/pages/dashboard-page.mjs +40 -0
- package/dist/client/components/shared/default-error.cjs +17 -0
- package/dist/client/components/shared/default-error.mjs +15 -0
- package/dist/client/components/shared/empty-state.cjs +16 -0
- package/dist/client/components/shared/empty-state.mjs +14 -0
- package/dist/client/components/shared/page-wrapper.cjs +29 -0
- package/dist/client/components/shared/page-wrapper.mjs +27 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/cms-hooks.cjs +300 -0
- package/dist/client/hooks/cms-hooks.mjs +280 -0
- package/dist/client/hooks/cms-resource.cjs +13 -0
- package/dist/client/hooks/cms-resource.mjs +11 -0
- package/dist/client/hooks/index.cjs +25 -0
- package/dist/client/hooks/index.d.cts +693 -0
- package/dist/client/hooks/index.d.mts +693 -0
- package/dist/client/hooks/index.d.ts +693 -0
- package/dist/client/hooks/index.mjs +1 -0
- package/dist/client/index.cjs +15 -0
- package/dist/client/index.d.cts +654 -0
- package/dist/client/index.d.mts +654 -0
- package/dist/client/index.d.ts +654 -0
- package/dist/client/index.mjs +3 -0
- package/dist/client/overrides.cjs +26 -0
- package/dist/client/overrides.mjs +24 -0
- package/dist/client/plugin.cjs +316 -0
- package/dist/client/plugin.mjs +314 -0
- package/dist/client.css +3 -0
- package/dist/db.cjs +118 -0
- package/dist/db.mjs +116 -0
- package/dist/permissions.cjs +46 -0
- package/dist/permissions.d.cts +42 -0
- package/dist/permissions.d.mts +42 -0
- package/dist/permissions.d.ts +42 -0
- package/dist/permissions.mjs +44 -0
- package/dist/query-keys.cjs +229 -0
- package/dist/query-keys.d.cts +8 -0
- package/dist/query-keys.d.mts +8 -0
- package/dist/query-keys.d.ts +8 -0
- package/dist/query-keys.mjs +225 -0
- package/dist/schemas.cjs +81 -0
- package/dist/schemas.mjs +72 -0
- package/dist/shared/plugin-cms.BBshPRkb.d.cts +6 -0
- package/dist/shared/plugin-cms.BBshPRkb.d.mts +6 -0
- package/dist/shared/plugin-cms.BBshPRkb.d.ts +6 -0
- package/dist/shared/plugin-cms.DQLAoogy.d.ts +1749 -0
- package/dist/shared/plugin-cms.W4Le8D91.d.mts +1749 -0
- package/dist/shared/plugin-cms.c-GeWvTf.d.cts +1749 -0
- package/dist/style.css +6 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +406 -0
- package/dist/types.d.mts +406 -0
- package/dist/types.d.ts +406 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/accordion.cjs +81 -0
- package/dist/ui/src/components/accordion.mjs +62 -0
- package/dist/ui/src/components/alert-dialog.cjs +157 -0
- package/dist/ui/src/components/alert-dialog.mjs +132 -0
- package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
- package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
- package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
- package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
- package/dist/ui/src/components/auto-form/config.cjs +40 -0
- package/dist/ui/src/components/auto-form/config.mjs +37 -0
- package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
- package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
- package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
- package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
- package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
- package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
- package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
- package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
- package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
- package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
- package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
- package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
- package/dist/ui/src/components/auto-form/index.cjs +92 -0
- package/dist/ui/src/components/auto-form/index.mjs +86 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/ui/src/components/auto-form/types.cjs +11 -0
- package/dist/ui/src/components/auto-form/types.mjs +9 -0
- package/dist/ui/src/components/badge.cjs +42 -0
- package/dist/ui/src/components/badge.mjs +39 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/calendar.cjs +207 -0
- package/dist/ui/src/components/calendar.mjs +190 -0
- package/dist/ui/src/components/card.cjs +56 -0
- package/dist/ui/src/components/card.mjs +51 -0
- package/dist/ui/src/components/checkbox.cjs +48 -0
- package/dist/ui/src/components/checkbox.mjs +32 -0
- package/dist/ui/src/components/command.cjs +78 -0
- package/dist/ui/src/components/command.mjs +73 -0
- package/dist/ui/src/components/date-picker.cjs +41 -0
- package/dist/ui/src/components/date-picker.mjs +39 -0
- package/dist/ui/src/components/dialog.cjs +119 -0
- package/dist/ui/src/components/dialog.mjs +97 -0
- package/dist/ui/src/components/form.cjs +120 -0
- package/dist/ui/src/components/form.mjs +98 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/components/label.cjs +39 -0
- package/dist/ui/src/components/label.mjs +23 -0
- package/dist/ui/src/components/multi-select.cjs +555 -0
- package/dist/ui/src/components/multi-select.mjs +540 -0
- package/dist/ui/src/components/page-layout.cjs +25 -0
- package/dist/ui/src/components/page-layout.mjs +23 -0
- package/dist/ui/src/components/page-wrapper.cjs +20 -0
- package/dist/ui/src/components/page-wrapper.mjs +18 -0
- package/dist/ui/src/components/popover.cjs +60 -0
- package/dist/ui/src/components/popover.mjs +42 -0
- package/dist/ui/src/components/radio-group.cjs +62 -0
- package/dist/ui/src/components/radio-group.mjs +45 -0
- package/dist/ui/src/components/select.cjs +161 -0
- package/dist/ui/src/components/select.mjs +139 -0
- package/dist/ui/src/components/separator.cjs +43 -0
- package/dist/ui/src/components/separator.mjs +27 -0
- package/dist/ui/src/components/skeleton.cjs +17 -0
- package/dist/ui/src/components/skeleton.mjs +15 -0
- package/dist/ui/src/components/stack-attribution.cjs +24 -0
- package/dist/ui/src/components/stack-attribution.mjs +22 -0
- package/dist/ui/src/components/switch.cjs +48 -0
- package/dist/ui/src/components/switch.mjs +32 -0
- package/dist/ui/src/components/table.cjs +89 -0
- package/dist/ui/src/components/table.mjs +82 -0
- package/dist/ui/src/components/textarea.cjs +20 -0
- package/dist/ui/src/components/textarea.mjs +18 -0
- package/dist/ui/src/hooks/use-debounce.cjs +16 -0
- package/dist/ui/src/hooks/use-debounce.mjs +14 -0
- package/dist/ui/src/hooks/use-route-lifecycle.cjs +31 -0
- package/dist/ui/src/hooks/use-route-lifecycle.mjs +29 -0
- package/dist/ui/src/lib/schema-converter.cjs +133 -0
- package/dist/ui/src/lib/schema-converter.mjs +127 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/dist/utils.cjs +19 -0
- package/dist/utils.mjs +12 -0
- package/package.json +170 -3
- package/README.md +0 -3
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React__default, { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import AutoForm from './index.mjs';
|
|
6
|
+
import { Button } from '../button.mjs';
|
|
7
|
+
import { Separator } from '../separator.mjs';
|
|
8
|
+
import { cn } from '../../lib/utils.mjs';
|
|
9
|
+
|
|
10
|
+
function extractStepsFromSchema(schema) {
|
|
11
|
+
try {
|
|
12
|
+
const jsonSchema = schema.toJSONSchema();
|
|
13
|
+
if (jsonSchema.steps && Array.isArray(jsonSchema.steps)) {
|
|
14
|
+
return jsonSchema.steps;
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
function getFieldStepAssignments(schema) {
|
|
21
|
+
const assignments = /* @__PURE__ */ new Map();
|
|
22
|
+
try {
|
|
23
|
+
const jsonSchema = schema.toJSONSchema();
|
|
24
|
+
const stepGroupMap = jsonSchema.stepGroupMap;
|
|
25
|
+
if (stepGroupMap) {
|
|
26
|
+
for (const [fieldName, stepGroup] of Object.entries(stepGroupMap)) {
|
|
27
|
+
assignments.set(fieldName, stepGroup);
|
|
28
|
+
}
|
|
29
|
+
return assignments;
|
|
30
|
+
}
|
|
31
|
+
const properties = jsonSchema.properties;
|
|
32
|
+
if (properties) {
|
|
33
|
+
for (const [fieldName, fieldSchema] of Object.entries(properties)) {
|
|
34
|
+
const stepGroup = fieldSchema.stepGroup;
|
|
35
|
+
if (typeof stepGroup === "number") {
|
|
36
|
+
assignments.set(fieldName, stepGroup);
|
|
37
|
+
} else {
|
|
38
|
+
assignments.set(fieldName, 0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
return assignments;
|
|
45
|
+
}
|
|
46
|
+
function createStepSchema(fullSchema, stepIndex, fieldAssignments) {
|
|
47
|
+
const fieldsForStep = Array.from(fieldAssignments.entries()).filter(([, step]) => step === stepIndex).map(([field]) => field);
|
|
48
|
+
if (fieldsForStep.length === 0) {
|
|
49
|
+
return z.object({});
|
|
50
|
+
}
|
|
51
|
+
const pickObject = {};
|
|
52
|
+
for (const field of fieldsForStep) {
|
|
53
|
+
pickObject[field] = true;
|
|
54
|
+
}
|
|
55
|
+
return fullSchema.pick(pickObject);
|
|
56
|
+
}
|
|
57
|
+
function getObjectSchema(schema) {
|
|
58
|
+
if (schema instanceof z.ZodObject) {
|
|
59
|
+
return schema;
|
|
60
|
+
}
|
|
61
|
+
const schemaDef = schema._zod?.def ?? schema._def;
|
|
62
|
+
if (schemaDef) {
|
|
63
|
+
if (schemaDef.schema) {
|
|
64
|
+
return getObjectSchema(schemaDef.schema);
|
|
65
|
+
}
|
|
66
|
+
if (schemaDef.innerType) {
|
|
67
|
+
return getObjectSchema(schemaDef.innerType);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function DefaultStepper({
|
|
73
|
+
steps,
|
|
74
|
+
currentStepIndex,
|
|
75
|
+
onStepClick
|
|
76
|
+
}) {
|
|
77
|
+
return /* @__PURE__ */ jsx("nav", { "aria-label": "Form Steps", className: "mb-6", children: /* @__PURE__ */ jsx("ol", { className: "flex items-center justify-between gap-2", children: steps.map((step, index) => /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
78
|
+
/* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 shrink-0", children: [
|
|
79
|
+
/* @__PURE__ */ jsx(
|
|
80
|
+
Button,
|
|
81
|
+
{
|
|
82
|
+
type: "button",
|
|
83
|
+
variant: index <= currentStepIndex ? "default" : "secondary",
|
|
84
|
+
"aria-current": currentStepIndex === index ? "step" : void 0,
|
|
85
|
+
"aria-posinset": index + 1,
|
|
86
|
+
"aria-setsize": steps.length,
|
|
87
|
+
className: "size-10 rounded-full p-0",
|
|
88
|
+
onClick: () => onStepClick?.(step.id),
|
|
89
|
+
children: index + 1
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium hidden sm:inline", children: step.label })
|
|
93
|
+
] }),
|
|
94
|
+
index < steps.length - 1 && /* @__PURE__ */ jsx(
|
|
95
|
+
Separator,
|
|
96
|
+
{
|
|
97
|
+
className: cn(
|
|
98
|
+
"flex-1 min-w-4",
|
|
99
|
+
index < currentStepIndex ? "bg-primary" : "bg-muted"
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
] }, step.id)) }) });
|
|
104
|
+
}
|
|
105
|
+
function SteppedAutoForm({
|
|
106
|
+
formSchema,
|
|
107
|
+
values: initialValues,
|
|
108
|
+
onValuesChange,
|
|
109
|
+
onSubmit,
|
|
110
|
+
fieldConfig,
|
|
111
|
+
children,
|
|
112
|
+
className,
|
|
113
|
+
nextButtonText = "Next",
|
|
114
|
+
backButtonText = "Back",
|
|
115
|
+
submitButtonText = "Submit",
|
|
116
|
+
StepperComponent = DefaultStepper,
|
|
117
|
+
isSubmitting = false
|
|
118
|
+
}) {
|
|
119
|
+
const steps = useMemo(() => extractStepsFromSchema(formSchema), [formSchema]);
|
|
120
|
+
const hasMultipleSteps = steps.length > 1;
|
|
121
|
+
const fieldAssignments = useMemo(
|
|
122
|
+
() => getFieldStepAssignments(formSchema),
|
|
123
|
+
[formSchema]
|
|
124
|
+
);
|
|
125
|
+
const [currentStepIndex, setCurrentStepIndex] = useState(0);
|
|
126
|
+
const [accumulatedValues, setAccumulatedValues] = useState(
|
|
127
|
+
initialValues ?? {}
|
|
128
|
+
);
|
|
129
|
+
const [completedSteps, setCompletedSteps] = useState(/* @__PURE__ */ new Set());
|
|
130
|
+
const [schemaErrors, setSchemaErrors] = useState(null);
|
|
131
|
+
const accumulatedValuesRef = useRef(accumulatedValues);
|
|
132
|
+
const onValuesChangeRef = useRef(onValuesChange);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
accumulatedValuesRef.current = accumulatedValues;
|
|
135
|
+
}, [accumulatedValues]);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
onValuesChangeRef.current = onValuesChange;
|
|
138
|
+
}, [onValuesChange]);
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (initialValues) {
|
|
141
|
+
const newValues = {
|
|
142
|
+
...accumulatedValuesRef.current,
|
|
143
|
+
...initialValues
|
|
144
|
+
};
|
|
145
|
+
accumulatedValuesRef.current = newValues;
|
|
146
|
+
setAccumulatedValues(newValues);
|
|
147
|
+
}
|
|
148
|
+
}, [initialValues]);
|
|
149
|
+
const objectSchema = useMemo(() => getObjectSchema(formSchema), [formSchema]);
|
|
150
|
+
const stepSchemas = useMemo(() => {
|
|
151
|
+
if (!hasMultipleSteps || !objectSchema) return [];
|
|
152
|
+
return steps.map(
|
|
153
|
+
(_, index) => createStepSchema(objectSchema, index, fieldAssignments)
|
|
154
|
+
);
|
|
155
|
+
}, [hasMultipleSteps, objectSchema, steps, fieldAssignments]);
|
|
156
|
+
const currentStep = steps[currentStepIndex];
|
|
157
|
+
const currentStepSchema = stepSchemas[currentStepIndex];
|
|
158
|
+
const isFirst = currentStepIndex === 0;
|
|
159
|
+
const isLast = currentStepIndex === steps.length - 1;
|
|
160
|
+
const currentStepFieldConfig = useMemo(() => {
|
|
161
|
+
if (!fieldConfig) return void 0;
|
|
162
|
+
const stepFields = Array.from(fieldAssignments.entries()).filter(([, step]) => step === currentStepIndex).map(([field]) => field);
|
|
163
|
+
const filtered = {};
|
|
164
|
+
for (const field of stepFields) {
|
|
165
|
+
if (field in fieldConfig) {
|
|
166
|
+
filtered[field] = fieldConfig[field];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return filtered;
|
|
170
|
+
}, [fieldConfig, fieldAssignments, currentStepIndex]);
|
|
171
|
+
const currentStepValues = useMemo(() => {
|
|
172
|
+
const stepFields = Array.from(fieldAssignments.entries()).filter(([, step]) => step === currentStepIndex).map(([field]) => field);
|
|
173
|
+
const values = {};
|
|
174
|
+
for (const field of stepFields) {
|
|
175
|
+
if (field in accumulatedValues) {
|
|
176
|
+
values[field] = accumulatedValues[field];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return values;
|
|
180
|
+
}, [fieldAssignments, currentStepIndex, accumulatedValues]);
|
|
181
|
+
const handleStepClick = useCallback(
|
|
182
|
+
(stepId) => {
|
|
183
|
+
const stepIndex = steps.findIndex((s) => s.id === stepId);
|
|
184
|
+
if (stepIndex === -1) return;
|
|
185
|
+
const canNavigate = stepIndex === currentStepIndex || completedSteps.has(stepIndex) || stepIndex === currentStepIndex + 1 && completedSteps.has(currentStepIndex);
|
|
186
|
+
if (canNavigate) {
|
|
187
|
+
setCurrentStepIndex(stepIndex);
|
|
188
|
+
setSchemaErrors(null);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
[steps, currentStepIndex, completedSteps]
|
|
192
|
+
);
|
|
193
|
+
const handleStepValuesChange = useCallback(
|
|
194
|
+
(stepValues, form) => {
|
|
195
|
+
const newAccumulated = { ...accumulatedValuesRef.current, ...stepValues };
|
|
196
|
+
accumulatedValuesRef.current = newAccumulated;
|
|
197
|
+
setAccumulatedValues(newAccumulated);
|
|
198
|
+
onValuesChangeRef.current?.(newAccumulated, form);
|
|
199
|
+
},
|
|
200
|
+
[]
|
|
201
|
+
);
|
|
202
|
+
const handleStepSubmit = useCallback(
|
|
203
|
+
(stepValues) => {
|
|
204
|
+
const newAccumulated = { ...accumulatedValuesRef.current, ...stepValues };
|
|
205
|
+
accumulatedValuesRef.current = newAccumulated;
|
|
206
|
+
setAccumulatedValues(newAccumulated);
|
|
207
|
+
onValuesChangeRef.current?.(newAccumulated, void 0);
|
|
208
|
+
setCompletedSteps((prev) => /* @__PURE__ */ new Set([...prev, currentStepIndex]));
|
|
209
|
+
if (isLast) {
|
|
210
|
+
const allStepsCompleted = steps.every(
|
|
211
|
+
(_, index) => index === currentStepIndex || completedSteps.has(index)
|
|
212
|
+
);
|
|
213
|
+
if (!allStepsCompleted) {
|
|
214
|
+
const firstIncompleteStep = steps.findIndex(
|
|
215
|
+
(_, index) => index !== currentStepIndex && !completedSteps.has(index)
|
|
216
|
+
);
|
|
217
|
+
if (firstIncompleteStep !== -1) {
|
|
218
|
+
setCurrentStepIndex(firstIncompleteStep);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const parseResult = formSchema.safeParse(newAccumulated);
|
|
223
|
+
if (parseResult.success) {
|
|
224
|
+
setSchemaErrors(null);
|
|
225
|
+
onSubmit?.(parseResult.data);
|
|
226
|
+
} else {
|
|
227
|
+
setSchemaErrors(parseResult.error);
|
|
228
|
+
const firstErrorPath = parseResult.error.issues[0]?.path[0];
|
|
229
|
+
if (typeof firstErrorPath === "string") {
|
|
230
|
+
const errorFieldStep = fieldAssignments.get(firstErrorPath);
|
|
231
|
+
if (errorFieldStep !== void 0 && errorFieldStep !== currentStepIndex) {
|
|
232
|
+
setCurrentStepIndex(errorFieldStep);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
setCurrentStepIndex((prev) => prev + 1);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
[isLast, onSubmit, currentStepIndex, steps, completedSteps, formSchema, fieldAssignments]
|
|
241
|
+
);
|
|
242
|
+
const handleBack = useCallback(() => {
|
|
243
|
+
if (!isFirst) {
|
|
244
|
+
setCurrentStepIndex((prev) => prev - 1);
|
|
245
|
+
setSchemaErrors(null);
|
|
246
|
+
}
|
|
247
|
+
}, [isFirst]);
|
|
248
|
+
if (!hasMultipleSteps) {
|
|
249
|
+
return /* @__PURE__ */ jsxs(
|
|
250
|
+
AutoForm,
|
|
251
|
+
{
|
|
252
|
+
formSchema,
|
|
253
|
+
values: initialValues,
|
|
254
|
+
onValuesChange,
|
|
255
|
+
onSubmit,
|
|
256
|
+
fieldConfig,
|
|
257
|
+
className,
|
|
258
|
+
children: [
|
|
259
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSubmitting, className: "w-full mt-4", children: submitButtonText }),
|
|
260
|
+
children
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (!currentStepSchema || !currentStep) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
|
|
269
|
+
/* @__PURE__ */ jsx(
|
|
270
|
+
StepperComponent,
|
|
271
|
+
{
|
|
272
|
+
steps: steps.map((s) => ({ id: s.id, label: s.title })),
|
|
273
|
+
currentStepIndex,
|
|
274
|
+
currentStepId: currentStep.id,
|
|
275
|
+
onStepClick: handleStepClick,
|
|
276
|
+
isFirst,
|
|
277
|
+
isLast
|
|
278
|
+
}
|
|
279
|
+
),
|
|
280
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
|
|
281
|
+
/* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: currentStep.title }),
|
|
282
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
|
|
283
|
+
"Step ",
|
|
284
|
+
currentStepIndex + 1,
|
|
285
|
+
" of ",
|
|
286
|
+
steps.length
|
|
287
|
+
] })
|
|
288
|
+
] }),
|
|
289
|
+
schemaErrors && schemaErrors.issues.length > 0 && /* @__PURE__ */ jsx(
|
|
290
|
+
"div",
|
|
291
|
+
{
|
|
292
|
+
role: "alert",
|
|
293
|
+
"aria-live": "assertive",
|
|
294
|
+
className: "rounded-md border border-destructive/50 bg-destructive/10 p-4 mb-4",
|
|
295
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
296
|
+
/* @__PURE__ */ jsx(
|
|
297
|
+
"svg",
|
|
298
|
+
{
|
|
299
|
+
className: "h-5 w-5 text-destructive shrink-0 mt-0.5",
|
|
300
|
+
fill: "none",
|
|
301
|
+
viewBox: "0 0 24 24",
|
|
302
|
+
stroke: "currentColor",
|
|
303
|
+
strokeWidth: 2,
|
|
304
|
+
children: /* @__PURE__ */ jsx(
|
|
305
|
+
"path",
|
|
306
|
+
{
|
|
307
|
+
strokeLinecap: "round",
|
|
308
|
+
strokeLinejoin: "round",
|
|
309
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
310
|
+
}
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
),
|
|
314
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
315
|
+
/* @__PURE__ */ jsx("h4", { className: "text-sm font-medium text-destructive", children: "Validation Failed" }),
|
|
316
|
+
/* @__PURE__ */ jsx("ul", { className: "mt-2 text-sm text-destructive/90 list-disc list-inside space-y-1", children: schemaErrors.issues.map((issue, index) => /* @__PURE__ */ jsxs("li", { children: [
|
|
317
|
+
issue.path.length > 0 && /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
318
|
+
issue.path.join("."),
|
|
319
|
+
": "
|
|
320
|
+
] }),
|
|
321
|
+
issue.message
|
|
322
|
+
] }, index)) })
|
|
323
|
+
] }),
|
|
324
|
+
/* @__PURE__ */ jsx(
|
|
325
|
+
"button",
|
|
326
|
+
{
|
|
327
|
+
type: "button",
|
|
328
|
+
onClick: () => setSchemaErrors(null),
|
|
329
|
+
className: "text-destructive/70 hover:text-destructive shrink-0",
|
|
330
|
+
"aria-label": "Dismiss errors",
|
|
331
|
+
children: /* @__PURE__ */ jsx("svg", { className: "h-4 w-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) })
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
] })
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
/* @__PURE__ */ jsxs(
|
|
338
|
+
AutoForm,
|
|
339
|
+
{
|
|
340
|
+
formSchema: currentStepSchema,
|
|
341
|
+
values: currentStepValues,
|
|
342
|
+
onValuesChange: handleStepValuesChange,
|
|
343
|
+
onSubmit: handleStepSubmit,
|
|
344
|
+
fieldConfig: currentStepFieldConfig,
|
|
345
|
+
className: "space-y-4",
|
|
346
|
+
children: [
|
|
347
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between pt-4", children: [
|
|
348
|
+
/* @__PURE__ */ jsx(
|
|
349
|
+
Button,
|
|
350
|
+
{
|
|
351
|
+
type: "button",
|
|
352
|
+
variant: "outline",
|
|
353
|
+
onClick: handleBack,
|
|
354
|
+
disabled: isFirst || isSubmitting,
|
|
355
|
+
children: backButtonText
|
|
356
|
+
}
|
|
357
|
+
),
|
|
358
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSubmitting, children: isLast ? submitButtonText : nextButtonText })
|
|
359
|
+
] }),
|
|
360
|
+
children
|
|
361
|
+
]
|
|
362
|
+
},
|
|
363
|
+
currentStep.id
|
|
364
|
+
)
|
|
365
|
+
] });
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export { SteppedAutoForm };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var DependencyType = /* @__PURE__ */ ((DependencyType2) => {
|
|
4
|
+
DependencyType2[DependencyType2["DISABLES"] = 0] = "DISABLES";
|
|
5
|
+
DependencyType2[DependencyType2["REQUIRES"] = 1] = "REQUIRES";
|
|
6
|
+
DependencyType2[DependencyType2["HIDES"] = 2] = "HIDES";
|
|
7
|
+
DependencyType2[DependencyType2["SETS_OPTIONS"] = 3] = "SETS_OPTIONS";
|
|
8
|
+
return DependencyType2;
|
|
9
|
+
})(DependencyType || {});
|
|
10
|
+
|
|
11
|
+
exports.DependencyType = DependencyType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var DependencyType = /* @__PURE__ */ ((DependencyType2) => {
|
|
2
|
+
DependencyType2[DependencyType2["DISABLES"] = 0] = "DISABLES";
|
|
3
|
+
DependencyType2[DependencyType2["REQUIRES"] = 1] = "REQUIRES";
|
|
4
|
+
DependencyType2[DependencyType2["HIDES"] = 2] = "HIDES";
|
|
5
|
+
DependencyType2[DependencyType2["SETS_OPTIONS"] = 3] = "SETS_OPTIONS";
|
|
6
|
+
return DependencyType2;
|
|
7
|
+
})(DependencyType || {});
|
|
8
|
+
|
|
9
|
+
export { DependencyType };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const reactSlot = require('@radix-ui/react-slot');
|
|
5
|
+
const classVarianceAuthority = require('class-variance-authority');
|
|
6
|
+
const utils = require('../lib/utils.cjs');
|
|
7
|
+
|
|
8
|
+
const badgeVariants = classVarianceAuthority.cva(
|
|
9
|
+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
14
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
15
|
+
destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
16
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: "default"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
function Badge({
|
|
25
|
+
className,
|
|
26
|
+
variant,
|
|
27
|
+
asChild = false,
|
|
28
|
+
...props
|
|
29
|
+
}) {
|
|
30
|
+
const Comp = asChild ? reactSlot.Slot : "span";
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
32
|
+
Comp,
|
|
33
|
+
{
|
|
34
|
+
"data-slot": "badge",
|
|
35
|
+
className: utils.cn(badgeVariants({ variant }), className),
|
|
36
|
+
...props
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.Badge = Badge;
|
|
42
|
+
exports.badgeVariants = badgeVariants;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { cn } from '../lib/utils.mjs';
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
12
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
13
|
+
destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
14
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
variant: "default"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
function Badge({
|
|
23
|
+
className,
|
|
24
|
+
variant,
|
|
25
|
+
asChild = false,
|
|
26
|
+
...props
|
|
27
|
+
}) {
|
|
28
|
+
const Comp = asChild ? Slot : "span";
|
|
29
|
+
return /* @__PURE__ */ jsx(
|
|
30
|
+
Comp,
|
|
31
|
+
{
|
|
32
|
+
"data-slot": "badge",
|
|
33
|
+
className: cn(badgeVariants({ variant }), className),
|
|
34
|
+
...props
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Badge, badgeVariants };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const reactSlot = require('@radix-ui/react-slot');
|
|
5
|
+
const classVarianceAuthority = require('class-variance-authority');
|
|
6
|
+
const utils = require('../lib/utils.cjs');
|
|
7
|
+
|
|
8
|
+
const buttonVariants = classVarianceAuthority.cva(
|
|
9
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
14
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
15
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
16
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
17
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
18
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
22
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
23
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
24
|
+
icon: "size-9",
|
|
25
|
+
"icon-sm": "size-8",
|
|
26
|
+
"icon-lg": "size-10"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
variant: "default",
|
|
31
|
+
size: "default"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
function Button({
|
|
36
|
+
className,
|
|
37
|
+
variant = "default",
|
|
38
|
+
size = "default",
|
|
39
|
+
asChild = false,
|
|
40
|
+
...props
|
|
41
|
+
}) {
|
|
42
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
Comp,
|
|
45
|
+
{
|
|
46
|
+
"data-slot": "button",
|
|
47
|
+
"data-variant": variant,
|
|
48
|
+
"data-size": size,
|
|
49
|
+
className: utils.cn(buttonVariants({ variant, size, className })),
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.Button = Button;
|
|
56
|
+
exports.buttonVariants = buttonVariants;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { cn } from '../lib/utils.mjs';
|
|
5
|
+
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
12
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
13
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
14
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
15
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
16
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
20
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
21
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
22
|
+
icon: "size-9",
|
|
23
|
+
"icon-sm": "size-8",
|
|
24
|
+
"icon-lg": "size-10"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: "default",
|
|
29
|
+
size: "default"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
function Button({
|
|
34
|
+
className,
|
|
35
|
+
variant = "default",
|
|
36
|
+
size = "default",
|
|
37
|
+
asChild = false,
|
|
38
|
+
...props
|
|
39
|
+
}) {
|
|
40
|
+
const Comp = asChild ? Slot : "button";
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
Comp,
|
|
43
|
+
{
|
|
44
|
+
"data-slot": "button",
|
|
45
|
+
"data-variant": variant,
|
|
46
|
+
"data-size": size,
|
|
47
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
48
|
+
...props
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { Button, buttonVariants };
|