shadcn-zod-formkit 1.30.1 → 1.31.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/dist/index.cjs +63 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.mjs +63 -41
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.31.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.30.1.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -6166,6 +6166,16 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
6166
6166
|
return foundField?.label ?? fieldErrorKey;
|
|
6167
6167
|
};
|
|
6168
6168
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
6169
|
+
var shouldShowField = (field, values) => {
|
|
6170
|
+
if (typeof field.showWhen === "function") {
|
|
6171
|
+
try {
|
|
6172
|
+
return !!field.showWhen(values);
|
|
6173
|
+
} catch {
|
|
6174
|
+
return true;
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
return true;
|
|
6178
|
+
};
|
|
6169
6179
|
var FormFieldsGrid = ({
|
|
6170
6180
|
fields,
|
|
6171
6181
|
form,
|
|
@@ -6174,47 +6184,54 @@ var FormFieldsGrid = ({
|
|
|
6174
6184
|
className = "",
|
|
6175
6185
|
gap = "gap-2"
|
|
6176
6186
|
}) => {
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6187
|
+
const values = form.watch();
|
|
6188
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
6189
|
+
if (Array.isArray(inputOrGroup)) {
|
|
6190
|
+
const visibleFields = inputOrGroup.filter(
|
|
6191
|
+
(f) => shouldShowField(f, values)
|
|
6192
|
+
);
|
|
6193
|
+
if (visibleFields.length === 0) return null;
|
|
6194
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6195
|
+
"div",
|
|
6196
|
+
{
|
|
6197
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
6198
|
+
children: visibleFields.map((field, subIdx) => {
|
|
6199
|
+
const fieldCopy2 = {
|
|
6200
|
+
...field,
|
|
6201
|
+
disabled: readOnly ? true : field.disabled
|
|
6202
|
+
};
|
|
6203
|
+
const renderUp2 = fieldCopy2.childrenPosition !== "down" && isRenderableChild(fieldCopy2.children);
|
|
6204
|
+
const renderDown2 = fieldCopy2.childrenPosition === "down" && isRenderableChild(fieldCopy2.children);
|
|
6205
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full px-2", children: [
|
|
6206
|
+
renderUp2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children }),
|
|
6207
|
+
InputFactory.create(fieldCopy2, form, isPending),
|
|
6208
|
+
renderDown2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children })
|
|
6209
|
+
] }, `field-${idx}-${subIdx}`);
|
|
6210
|
+
})
|
|
6211
|
+
},
|
|
6212
|
+
`field-group-${idx}`
|
|
6213
|
+
);
|
|
6214
|
+
}
|
|
6215
|
+
if (!shouldShowField(inputOrGroup, values)) return null;
|
|
6216
|
+
const fieldCopy = {
|
|
6217
|
+
...inputOrGroup,
|
|
6218
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
6219
|
+
};
|
|
6220
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6221
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6222
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6198
6223
|
"div",
|
|
6199
6224
|
{
|
|
6200
6225
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
6201
|
-
children:
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6207
|
-
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6208
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6209
|
-
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6210
|
-
InputFactory.create(fieldCopy, form, isPending),
|
|
6211
|
-
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6212
|
-
] });
|
|
6213
|
-
})()
|
|
6226
|
+
children: [
|
|
6227
|
+
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6228
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
6229
|
+
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6230
|
+
]
|
|
6214
6231
|
},
|
|
6215
6232
|
`field-single-${idx}`
|
|
6216
|
-
)
|
|
6217
|
-
) });
|
|
6233
|
+
);
|
|
6234
|
+
}) });
|
|
6218
6235
|
};
|
|
6219
6236
|
var DynamicForm = ({
|
|
6220
6237
|
formTitle,
|
|
@@ -6239,7 +6256,8 @@ var DynamicForm = ({
|
|
|
6239
6256
|
submitBtnLabelSubmiting = "Guardando...",
|
|
6240
6257
|
withFormWrapper = true,
|
|
6241
6258
|
btnGroupDirection = "flex-end",
|
|
6242
|
-
withSubmitBtn = true
|
|
6259
|
+
withSubmitBtn = true,
|
|
6260
|
+
debug = false
|
|
6243
6261
|
}) => {
|
|
6244
6262
|
const [isPending, startTransition] = React3.useTransition();
|
|
6245
6263
|
const schema = React3.useMemo(() => {
|
|
@@ -6266,7 +6284,7 @@ var DynamicForm = ({
|
|
|
6266
6284
|
if (!onClick) return;
|
|
6267
6285
|
const isValid2 = await form.trigger();
|
|
6268
6286
|
if (!isValid2) return;
|
|
6269
|
-
const data = form.
|
|
6287
|
+
const data = form.watch();
|
|
6270
6288
|
const resp = { data, form };
|
|
6271
6289
|
onClick(resp);
|
|
6272
6290
|
};
|
|
@@ -6351,13 +6369,17 @@ var DynamicForm = ({
|
|
|
6351
6369
|
if (!withCard) return formContent;
|
|
6352
6370
|
return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { children: formContent }) });
|
|
6353
6371
|
};
|
|
6354
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
6355
|
-
|
|
6372
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug }) => {
|
|
6373
|
+
const allValues = form.watch();
|
|
6374
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6356
6375
|
"form",
|
|
6357
6376
|
{
|
|
6358
6377
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
6359
6378
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
6360
|
-
children
|
|
6379
|
+
children: [
|
|
6380
|
+
children,
|
|
6381
|
+
debug && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|
|
6382
|
+
]
|
|
6361
6383
|
}
|
|
6362
6384
|
) });
|
|
6363
6385
|
};
|