formanitor 0.0.3 → 0.0.5
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/dist/index.cjs +86 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -9
- package/dist/index.d.ts +18 -9
- package/dist/index.mjs +86 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -90,6 +90,7 @@ function validateField(value, field) {
|
|
|
90
90
|
function validateForm(values, fields) {
|
|
91
91
|
const errors = {};
|
|
92
92
|
for (const [key, field] of Object.entries(fields)) {
|
|
93
|
+
if (field.type === "static_text") continue;
|
|
93
94
|
const error = validateField(values[key], field);
|
|
94
95
|
if (error) {
|
|
95
96
|
errors[key] = error;
|
|
@@ -237,6 +238,7 @@ var FormStore = class {
|
|
|
237
238
|
initializeDefaults() {
|
|
238
239
|
const values = {};
|
|
239
240
|
this.schema.fields.forEach((field) => {
|
|
241
|
+
if (field.type === "static_text") return;
|
|
240
242
|
if (field.defaultValue !== void 0) {
|
|
241
243
|
values[field.id] = field.defaultValue;
|
|
242
244
|
} else {
|
|
@@ -344,6 +346,10 @@ var FormStore = class {
|
|
|
344
346
|
serializeValuesForSubmission(values) {
|
|
345
347
|
const result = { ...values };
|
|
346
348
|
this.schema.fields.forEach((field) => {
|
|
349
|
+
if (field.type === "static_text") {
|
|
350
|
+
delete result[field.id];
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
347
353
|
if (field.type === "image_upload" || field.type === "signature") {
|
|
348
354
|
const raw = values[field.id];
|
|
349
355
|
if (raw !== void 0 && raw !== null && raw !== "") {
|
|
@@ -595,15 +601,17 @@ var Label = React11__namespace.forwardRef(({ className, ...props }, ref) => /* @
|
|
|
595
601
|
));
|
|
596
602
|
Label.displayName = LabelPrimitive__namespace.Root.displayName;
|
|
597
603
|
var Textarea = React11__namespace.forwardRef(
|
|
598
|
-
({ className, ...props }, ref) => {
|
|
604
|
+
({ className, height, style, ...props }, ref) => {
|
|
599
605
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
600
606
|
"textarea",
|
|
601
607
|
{
|
|
602
608
|
className: cn(
|
|
603
|
-
"flex
|
|
609
|
+
"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
610
|
+
height == null && "min-h-[80px]",
|
|
604
611
|
className
|
|
605
612
|
),
|
|
606
613
|
ref,
|
|
614
|
+
style: height != null ? { ...style, height: `${height}px` } : style,
|
|
607
615
|
...props
|
|
608
616
|
}
|
|
609
617
|
);
|
|
@@ -616,6 +624,8 @@ var TextWidget = ({ fieldId }) => {
|
|
|
616
624
|
const showError = !!error && (touched || state.submitAttempted);
|
|
617
625
|
if (!fieldDef) return null;
|
|
618
626
|
const Component = fieldDef.type === "textarea" || fieldDef.type === "richtext" ? Textarea : Input;
|
|
627
|
+
const isTextarea = fieldDef.type === "textarea" || fieldDef.type === "richtext";
|
|
628
|
+
const height = isTextarea && "height" in fieldDef ? fieldDef.height : void 0;
|
|
619
629
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
620
630
|
/* @__PURE__ */ jsxRuntime.jsxs(Label, { htmlFor: fieldId, children: [
|
|
621
631
|
fieldDef.label,
|
|
@@ -631,7 +641,8 @@ var TextWidget = ({ fieldId }) => {
|
|
|
631
641
|
onBlur: setTouched,
|
|
632
642
|
disabled,
|
|
633
643
|
type: fieldDef.type === "number" ? "number" : "text",
|
|
634
|
-
className: showError ? "border-red-500" : ""
|
|
644
|
+
className: showError ? "border-red-500" : "",
|
|
645
|
+
...isTextarea && { height }
|
|
635
646
|
}
|
|
636
647
|
),
|
|
637
648
|
showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
|
|
@@ -2150,6 +2161,16 @@ var FieldRenderer = ({ fieldId }) => {
|
|
|
2150
2161
|
return /* @__PURE__ */ jsxRuntime.jsx(SignatureUploadWidget, { fieldId });
|
|
2151
2162
|
case "editable_table":
|
|
2152
2163
|
return /* @__PURE__ */ jsxRuntime.jsx(EditableTableWidget, { fieldId });
|
|
2164
|
+
case "static_text": {
|
|
2165
|
+
const def = fieldDef;
|
|
2166
|
+
const size = def.size ?? "regular";
|
|
2167
|
+
const labelClass = size === "large" ? "text-base" : "text-sm";
|
|
2168
|
+
const descClass = size === "large" ? "text-sm" : "text-xs";
|
|
2169
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${labelClass} text-muted-foreground`, children: [
|
|
2170
|
+
def.label,
|
|
2171
|
+
def.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: `mt-1 ${descClass} opacity-90`, children: def.description })
|
|
2172
|
+
] });
|
|
2173
|
+
}
|
|
2153
2174
|
default:
|
|
2154
2175
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-red-500", children: [
|
|
2155
2176
|
"Unknown field type: ",
|
|
@@ -2211,7 +2232,17 @@ var DynamicForm = () => {
|
|
|
2211
2232
|
] }),
|
|
2212
2233
|
schema.layout.map((node) => {
|
|
2213
2234
|
if (node.type === "section") {
|
|
2214
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: node.title, children: node.children.map(
|
|
2235
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: node.title, children: node.children.map(
|
|
2236
|
+
(child, index) => typeof child === "string" ? /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId: child }, child) : child.type === "column_layout" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2237
|
+
ColumnLayout,
|
|
2238
|
+
{
|
|
2239
|
+
columns: child.columns,
|
|
2240
|
+
label: child.label,
|
|
2241
|
+
children: child.children.map((fieldId) => /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId }, fieldId))
|
|
2242
|
+
},
|
|
2243
|
+
child.id
|
|
2244
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(React11__namespace.default.Fragment, {}, child.id ?? index)
|
|
2245
|
+
) }, node.id);
|
|
2215
2246
|
}
|
|
2216
2247
|
if (node.type === "column_layout") {
|
|
2217
2248
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2553,6 +2584,16 @@ var ReadOnlyFieldRenderer = ({ fieldDef, value }) => {
|
|
|
2553
2584
|
return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlySignature, { fieldDef, value });
|
|
2554
2585
|
case "editable_table":
|
|
2555
2586
|
return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlyTable, { fieldDef, value });
|
|
2587
|
+
case "static_text": {
|
|
2588
|
+
const def = fieldDef;
|
|
2589
|
+
const size = def.size ?? "regular";
|
|
2590
|
+
const labelClass = size === "large" ? "text-base" : "text-sm";
|
|
2591
|
+
const descClass = size === "large" ? "text-sm" : "text-xs";
|
|
2592
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${labelClass} text-muted-foreground`, children: [
|
|
2593
|
+
def.label,
|
|
2594
|
+
def.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: `mt-1 ${descClass} opacity-90`, children: def.description })
|
|
2595
|
+
] });
|
|
2596
|
+
}
|
|
2556
2597
|
default:
|
|
2557
2598
|
return /* @__PURE__ */ jsxRuntime.jsx(ReadOnlyText, { fieldDef, value });
|
|
2558
2599
|
}
|
|
@@ -2582,19 +2623,47 @@ var ReadOnlyForm = ({ schema, submission }) => {
|
|
|
2582
2623
|
] }),
|
|
2583
2624
|
schema.layout.map((node) => {
|
|
2584
2625
|
if (node.type === "section") {
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2626
|
+
const renderSectionChild = (child, index) => {
|
|
2627
|
+
if (typeof child === "string") {
|
|
2628
|
+
const fieldDef = fieldMap.get(child);
|
|
2629
|
+
return fieldDef ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2630
|
+
ReadOnlyFieldRenderer,
|
|
2631
|
+
{
|
|
2632
|
+
fieldDef,
|
|
2633
|
+
value: formData[child]
|
|
2634
|
+
},
|
|
2635
|
+
child
|
|
2636
|
+
) : null;
|
|
2637
|
+
}
|
|
2638
|
+
if (child.type === "column_layout" && child.children) {
|
|
2639
|
+
const visibleFields = child.children.map((fieldId) => {
|
|
2640
|
+
const fieldDef = fieldMap.get(fieldId);
|
|
2641
|
+
return fieldDef ? { fieldId, fieldDef } : null;
|
|
2642
|
+
}).filter((f) => f !== null);
|
|
2643
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2644
|
+
ColumnLayout,
|
|
2645
|
+
{
|
|
2646
|
+
columns: child.columns ?? 1,
|
|
2647
|
+
label: child.label,
|
|
2648
|
+
children: visibleFields.map(({ fieldId, fieldDef }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2649
|
+
ReadOnlyFieldRenderer,
|
|
2650
|
+
{
|
|
2651
|
+
fieldDef,
|
|
2652
|
+
value: formData[fieldId]
|
|
2653
|
+
},
|
|
2654
|
+
fieldId
|
|
2655
|
+
))
|
|
2656
|
+
},
|
|
2657
|
+
child.id
|
|
2658
|
+
);
|
|
2659
|
+
}
|
|
2660
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React11__namespace.default.Fragment, {}, child.id ?? index);
|
|
2661
|
+
};
|
|
2662
|
+
const hasContent = node.children.some(
|
|
2663
|
+
(child) => typeof child === "string" ? fieldMap.has(child) : child.type === "column_layout" && child.children?.some((id) => fieldMap.has(id))
|
|
2664
|
+
);
|
|
2665
|
+
if (!hasContent) return null;
|
|
2666
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: node.title, children: node.children.map((child, index) => renderSectionChild(child, index)) }, node.id);
|
|
2598
2667
|
}
|
|
2599
2668
|
if (node.type === "column_layout") {
|
|
2600
2669
|
const visibleFields = node.children.map((fieldId) => {
|