shadcn-zod-formkit 3.5.4 → 3.6.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 +70 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +71 -93
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-3.6.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-3.5.4.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -9229,7 +9229,7 @@ var require_leaflet_src = __commonJS({
|
|
|
9229
9229
|
// Amount of pixels to pan when pressing an arrow key.
|
|
9230
9230
|
keyboardPanDelta: 80
|
|
9231
9231
|
});
|
|
9232
|
-
var
|
|
9232
|
+
var Keyboard3 = Handler.extend({
|
|
9233
9233
|
keyCodes: {
|
|
9234
9234
|
left: [37],
|
|
9235
9235
|
right: [39],
|
|
@@ -9347,7 +9347,7 @@ var require_leaflet_src = __commonJS({
|
|
|
9347
9347
|
stop(e);
|
|
9348
9348
|
}
|
|
9349
9349
|
});
|
|
9350
|
-
Map2.addInitHook("addHandler", "keyboard",
|
|
9350
|
+
Map2.addInitHook("addHandler", "keyboard", Keyboard3);
|
|
9351
9351
|
Map2.mergeOptions({
|
|
9352
9352
|
// @section Mouse wheel options
|
|
9353
9353
|
// @option scrollWheelZoom: Boolean|String = true
|
|
@@ -9565,7 +9565,7 @@ var require_leaflet_src = __commonJS({
|
|
|
9565
9565
|
Map2.BoxZoom = BoxZoom;
|
|
9566
9566
|
Map2.DoubleClickZoom = DoubleClickZoom;
|
|
9567
9567
|
Map2.Drag = Drag;
|
|
9568
|
-
Map2.Keyboard =
|
|
9568
|
+
Map2.Keyboard = Keyboard3;
|
|
9569
9569
|
Map2.ScrollWheelZoom = ScrollWheelZoom;
|
|
9570
9570
|
Map2.TapHold = TapHold;
|
|
9571
9571
|
Map2.TouchZoom = TouchZoom;
|
|
@@ -13161,64 +13161,28 @@ var CurrencyInput = class extends BaseInput {
|
|
|
13161
13161
|
}
|
|
13162
13162
|
};
|
|
13163
13163
|
var FieldCurrency = ({ form, input, isSubmitting }) => {
|
|
13164
|
-
const
|
|
13165
|
-
|
|
13166
|
-
const
|
|
13164
|
+
const setIsOpen = useKeyboardStore((state) => state.setIsOpen);
|
|
13165
|
+
const setCurrentInputField = useKeyboardStore((state) => state.setCurrentInputField);
|
|
13166
|
+
const withKeyboard = input.withKeyboard;
|
|
13167
|
+
const autoValidate = input.inputGroupConfig?.autoValidIcons;
|
|
13167
13168
|
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
13168
13169
|
const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
|
|
13169
13170
|
const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
|
|
13170
|
-
const [isValid, setIsValid] = React3.useState(() => {
|
|
13171
|
-
const value = form.getValues(input.name);
|
|
13172
|
-
const fieldState = form.getFieldState(input.name);
|
|
13173
|
-
return !fieldState.error && value !== void 0 && value !== "";
|
|
13174
|
-
});
|
|
13175
|
-
const defaultCurrencyFormat = {
|
|
13176
|
-
style: "currency",
|
|
13177
|
-
currency: "USD",
|
|
13178
|
-
minimumFractionDigits: 2,
|
|
13179
|
-
maximumFractionDigits: 2
|
|
13180
|
-
};
|
|
13181
|
-
const mask = input?.mask;
|
|
13182
|
-
const currencyFormat = input?.currencyFormat ?? defaultCurrencyFormat;
|
|
13183
|
-
const [rawValue, setRawValue] = React3.useState(form.getValues(input.name) ?? "");
|
|
13184
13171
|
const formatter = React3.useMemo(() => {
|
|
13185
|
-
return new Intl.NumberFormat("es-DO",
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13172
|
+
return new Intl.NumberFormat("es-DO", {
|
|
13173
|
+
style: "currency",
|
|
13174
|
+
currency: input?.currencyFormat?.currency ?? "USD",
|
|
13175
|
+
minimumFractionDigits: 2,
|
|
13176
|
+
maximumFractionDigits: 2
|
|
13177
|
+
});
|
|
13178
|
+
}, [input?.currencyFormat]);
|
|
13179
|
+
const parseValue = (val) => {
|
|
13180
|
+
const numeric = parseFloat(val.replace(/[^0-9.-]/g, ""));
|
|
13189
13181
|
return isNaN(numeric) ? null : numeric;
|
|
13190
13182
|
};
|
|
13191
|
-
const formatValue = (
|
|
13192
|
-
if (
|
|
13193
|
-
|
|
13194
|
-
if (isNaN(numeric)) return "";
|
|
13195
|
-
if (typeof mask === "string") {
|
|
13196
|
-
return mask.replace(/0+(?:[.,]0+)?/, formatter.format(numeric).replace(/[^\d.,]/g, ""));
|
|
13197
|
-
}
|
|
13198
|
-
if (mask instanceof RegExp) {
|
|
13199
|
-
const valid = mask.test(value);
|
|
13200
|
-
return valid ? value : rawValue;
|
|
13201
|
-
}
|
|
13202
|
-
return formatter.format(numeric);
|
|
13203
|
-
};
|
|
13204
|
-
const handleKeyDown = (e) => {
|
|
13205
|
-
const allowedKeys = [
|
|
13206
|
-
"Backspace",
|
|
13207
|
-
"Delete",
|
|
13208
|
-
"Tab",
|
|
13209
|
-
"ArrowLeft",
|
|
13210
|
-
"ArrowRight",
|
|
13211
|
-
"Home",
|
|
13212
|
-
"End"
|
|
13213
|
-
];
|
|
13214
|
-
if (allowedKeys.includes(e.key)) return;
|
|
13215
|
-
if (!/^[0-9.]$/.test(e.key)) {
|
|
13216
|
-
e.preventDefault();
|
|
13217
|
-
return;
|
|
13218
|
-
}
|
|
13219
|
-
if (e.key === "." && rawValue.includes(".")) {
|
|
13220
|
-
e.preventDefault();
|
|
13221
|
-
}
|
|
13183
|
+
const formatValue = (val) => {
|
|
13184
|
+
if (val === null || val === void 0) return "";
|
|
13185
|
+
return formatter.format(val);
|
|
13222
13186
|
};
|
|
13223
13187
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
13224
13188
|
FormField,
|
|
@@ -13226,44 +13190,55 @@ var FieldCurrency = ({ form, input, isSubmitting }) => {
|
|
|
13226
13190
|
control: form.control,
|
|
13227
13191
|
name: input.name,
|
|
13228
13192
|
render: ({ field, fieldState }) => {
|
|
13229
|
-
const
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13193
|
+
const [displayValue, setDisplayValue] = React3.useState(() => {
|
|
13194
|
+
return field.value ? formatValue(field.value) : "";
|
|
13195
|
+
});
|
|
13196
|
+
const isValid = !fieldState.error && field.value !== void 0 && field.value !== "";
|
|
13197
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: `${input.withLateralLabel ? "flex items-center gap-2" : ""} ${input.className}`, children: [
|
|
13198
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { className: `${input.withLateralLabel ? "w-32 text-right" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
13233
13199
|
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
|
|
13234
|
-
/* @__PURE__ */ jsxRuntime.
|
|
13235
|
-
/* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: "$" }),
|
|
13236
|
-
input.inputGroupConfig?.textLeft && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: input.inputGroupConfig.textLeft })
|
|
13237
|
-
] }),
|
|
13200
|
+
/* @__PURE__ */ jsxRuntime.jsx(InputGroupAddon, { children: /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: "$" }) }),
|
|
13238
13201
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13239
13202
|
InputGroupInput,
|
|
13240
13203
|
{
|
|
13241
|
-
|
|
13204
|
+
ref: field.ref,
|
|
13205
|
+
name: field.name,
|
|
13242
13206
|
disabled: input.disabled || isSubmitting,
|
|
13243
|
-
placeholder:
|
|
13207
|
+
placeholder: "0.00",
|
|
13244
13208
|
inputMode: "decimal",
|
|
13245
|
-
value:
|
|
13246
|
-
|
|
13209
|
+
value: displayValue,
|
|
13210
|
+
onFocus: (e) => {
|
|
13211
|
+
const raw = field.value ? String(field.value) : "";
|
|
13212
|
+
setDisplayValue(raw);
|
|
13213
|
+
setCurrentInputField({ input, field });
|
|
13214
|
+
},
|
|
13247
13215
|
onChange: (e) => {
|
|
13248
|
-
const
|
|
13249
|
-
|
|
13250
|
-
const parsed = parseValue(
|
|
13251
|
-
|
|
13216
|
+
const val = e.target.value;
|
|
13217
|
+
setDisplayValue(val);
|
|
13218
|
+
const parsed = parseValue(val);
|
|
13219
|
+
field.onChange(parsed);
|
|
13252
13220
|
handleOnChage(parsed, input, field);
|
|
13253
13221
|
},
|
|
13254
|
-
onBlur: (
|
|
13255
|
-
const formatted = formatValue(
|
|
13256
|
-
|
|
13257
|
-
},
|
|
13258
|
-
onFocus: (e) => {
|
|
13259
|
-
const numeric = e.target.value.replace(/[^0-9.-]/g, "");
|
|
13260
|
-
setRawValue(numeric);
|
|
13222
|
+
onBlur: () => {
|
|
13223
|
+
const formatted = formatValue(field.value);
|
|
13224
|
+
setDisplayValue(formatted);
|
|
13261
13225
|
}
|
|
13262
13226
|
}
|
|
13263
13227
|
),
|
|
13264
13228
|
/* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
|
|
13265
|
-
/* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: currencyFormat
|
|
13266
|
-
|
|
13229
|
+
/* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: input?.currencyFormat?.currency ?? "USD" }),
|
|
13230
|
+
withKeyboard && /* @__PURE__ */ jsxRuntime.jsx(
|
|
13231
|
+
"button",
|
|
13232
|
+
{
|
|
13233
|
+
type: "button",
|
|
13234
|
+
className: "text-2xl",
|
|
13235
|
+
onClick: () => {
|
|
13236
|
+
setIsOpen();
|
|
13237
|
+
setCurrentInputField({ input, field });
|
|
13238
|
+
},
|
|
13239
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Keyboard, {})
|
|
13240
|
+
}
|
|
13241
|
+
),
|
|
13267
13242
|
autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid ? iconValidState : iconInvalidState })
|
|
13268
13243
|
] })
|
|
13269
13244
|
] }) }),
|
|
@@ -13603,9 +13578,9 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
|
|
|
13603
13578
|
name: input.name,
|
|
13604
13579
|
render: ({ field }) => {
|
|
13605
13580
|
setIsValid(isValidField(input, form));
|
|
13606
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className
|
|
13607
|
-
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
13608
|
-
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { className:
|
|
13581
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: `${input.withLateralLabel ? "flex items-center gap-2 flex-row" : ""} ${input.className}`, children: [
|
|
13582
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { className: `${input.withLateralLabel ? "text-right" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
13583
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { className: `shadow-lg ${input.withLateralLabel ? " text-right" : ""}`, children: CustomInputGroup({
|
|
13609
13584
|
input,
|
|
13610
13585
|
isSubmitting,
|
|
13611
13586
|
field,
|
|
@@ -13646,7 +13621,7 @@ var CustomInputGroup = ({
|
|
|
13646
13621
|
const [showPassword, setShowPassword] = React3.useState(false);
|
|
13647
13622
|
const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
|
|
13648
13623
|
const isNumberField = input.keyboardType === "number" /* NUMBER */;
|
|
13649
|
-
const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
|
|
13624
|
+
const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField || withKeyboard;
|
|
13650
13625
|
const setIsOpen = useKeyboardStore((state) => state.setIsOpen);
|
|
13651
13626
|
const setCurrentInputField = useKeyboardStore((state) => state.setCurrentInputField);
|
|
13652
13627
|
const applyMask = (value2, mask) => {
|
|
@@ -13728,6 +13703,7 @@ var CustomInputGroup = ({
|
|
|
13728
13703
|
onChange(e);
|
|
13729
13704
|
}
|
|
13730
13705
|
let value2 = e.target.value;
|
|
13706
|
+
console.log("Valor raw del input:", value2);
|
|
13731
13707
|
if (isNumberField) {
|
|
13732
13708
|
const numConfig = input.inputNumberConfig;
|
|
13733
13709
|
const cleanValue = value2.replace(/[^\d.-]/g, "");
|
|
@@ -14887,12 +14863,12 @@ function FieldTextArea({ form, input, isSubmitting }) {
|
|
|
14887
14863
|
{
|
|
14888
14864
|
control: form.control,
|
|
14889
14865
|
name: input.name,
|
|
14890
|
-
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className:
|
|
14891
|
-
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
14866
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: `shadow-lg ${input.withLateralLabel ? "flex items-center gap-2" : ""} ${input.className}`, children: [
|
|
14867
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { className: `${input.withLateralLabel ? "w-32 text-right" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
14892
14868
|
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
14893
14869
|
Textarea,
|
|
14894
14870
|
{
|
|
14895
|
-
className: "min-w-[260px]
|
|
14871
|
+
className: "min-w-[260px]",
|
|
14896
14872
|
placeholder: input.placeHolder,
|
|
14897
14873
|
...field,
|
|
14898
14874
|
onChange: (event) => {
|
|
@@ -16620,7 +16596,8 @@ var FormFieldsGrid = ({
|
|
|
16620
16596
|
isPending,
|
|
16621
16597
|
readOnly,
|
|
16622
16598
|
className = "",
|
|
16623
|
-
gap = "gap-2"
|
|
16599
|
+
gap = "gap-2",
|
|
16600
|
+
py = "py-1"
|
|
16624
16601
|
}) => {
|
|
16625
16602
|
const values = form.watch();
|
|
16626
16603
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
@@ -16632,7 +16609,7 @@ var FormFieldsGrid = ({
|
|
|
16632
16609
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
16633
16610
|
"div",
|
|
16634
16611
|
{
|
|
16635
|
-
className:
|
|
16612
|
+
className: `w-full flex flex-row items-start gap-4 ${py}`,
|
|
16636
16613
|
children: visibleFields.map((field, subIdx) => {
|
|
16637
16614
|
const fieldCopy2 = {
|
|
16638
16615
|
...field,
|
|
@@ -16933,7 +16910,8 @@ var DynamicForm = ({
|
|
|
16933
16910
|
{
|
|
16934
16911
|
fields,
|
|
16935
16912
|
form,
|
|
16936
|
-
readOnly
|
|
16913
|
+
readOnly,
|
|
16914
|
+
gap: "gap-1"
|
|
16937
16915
|
}
|
|
16938
16916
|
),
|
|
16939
16917
|
children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
|
|
@@ -16985,7 +16963,7 @@ var DynamicForm = ({
|
|
|
16985
16963
|
formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
|
|
16986
16964
|
] })
|
|
16987
16965
|
] }),
|
|
16988
|
-
childrenHeader && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-
|
|
16966
|
+
childrenHeader && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-1 w-full h-full", children: childrenHeader })
|
|
16989
16967
|
] }),
|
|
16990
16968
|
withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
16991
16969
|
FormErrorsAlert,
|
|
@@ -17021,7 +16999,7 @@ var FormWrapper = ({ form, handleSubmit, children, readOnly, debug, isWrapInWiza
|
|
|
17021
16999
|
"form",
|
|
17022
17000
|
{
|
|
17023
17001
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
17024
|
-
className: `flex flex-col gap-
|
|
17002
|
+
className: `flex flex-col gap-1 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
17025
17003
|
children: [
|
|
17026
17004
|
children,
|
|
17027
17005
|
debug && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|