@algodomain/smart-forms 0.1.10 → 0.1.12
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/{SmartFormProvider-BdyRQakk.d.cts → SmartFormProvider-DtK3qRsV.d.cts} +8 -2
- package/dist/{SmartFormProvider-BdyRQakk.d.ts → SmartFormProvider-DtK3qRsV.d.ts} +8 -2
- package/dist/{chunk-WUYS7DMR.cjs → chunk-AEN4A4ST.cjs} +49 -12
- package/dist/chunk-AEN4A4ST.cjs.map +1 -0
- package/dist/{chunk-6VKQ7EMR.js → chunk-DYTQTHGE.js} +50 -13
- package/dist/chunk-DYTQTHGE.js.map +1 -0
- package/dist/{chunk-4XK6HAJ2.js → chunk-N3SIQIJR.js} +48 -18
- package/dist/chunk-N3SIQIJR.js.map +1 -0
- package/dist/{chunk-DRMVY7TX.cjs → chunk-TX7JD2XS.cjs} +135 -105
- package/dist/chunk-TX7JD2XS.cjs.map +1 -0
- package/dist/fields.cjs +124 -114
- package/dist/fields.cjs.map +1 -1
- package/dist/fields.d.cts +1 -1
- package/dist/fields.d.ts +1 -1
- package/dist/fields.js +27 -17
- package/dist/fields.js.map +1 -1
- package/dist/index.cjs +79 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +32 -23
- package/dist/index.js.map +1 -1
- package/dist/opinionated.cjs +18 -18
- package/dist/opinionated.d.cts +1 -1
- package/dist/opinionated.d.ts +1 -1
- package/dist/opinionated.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-4XK6HAJ2.js.map +0 -1
- package/dist/chunk-6VKQ7EMR.js.map +0 -1
- package/dist/chunk-DRMVY7TX.cjs.map +0 -1
- package/dist/chunk-WUYS7DMR.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import React__default, { ReactNode } from 'react';
|
|
3
|
-
import { A as AuthenticationConfig, F as FormContextType } from './SmartFormProvider-
|
|
4
|
-
export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-
|
|
3
|
+
import { A as AuthenticationConfig, F as FormContextType } from './SmartFormProvider-DtK3qRsV.cjs';
|
|
4
|
+
export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-DtK3qRsV.cjs';
|
|
5
5
|
export { a as SmartCheckbox, d as SmartCombobox, k as SmartComboboxOption, j as SmartComboboxProps, e as SmartDatePicker, i as SmartDatePickerProps, S as SmartInput, g as SmartInputProps, b as SmartRadioGroup, c as SmartSelect, f as SmartTags } from './SmartTags-DEpmTDF5.cjs';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
|
|
@@ -200,7 +200,7 @@ interface SmartTextAreaProps {
|
|
|
200
200
|
maxLength?: number;
|
|
201
201
|
minLength?: number;
|
|
202
202
|
name?: string;
|
|
203
|
-
|
|
203
|
+
dirname?: string;
|
|
204
204
|
form?: string;
|
|
205
205
|
}
|
|
206
206
|
declare const SmartTextArea: React__default.FC<SmartTextAreaProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import React__default, { ReactNode } from 'react';
|
|
3
|
-
import { A as AuthenticationConfig, F as FormContextType } from './SmartFormProvider-
|
|
4
|
-
export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-
|
|
3
|
+
import { A as AuthenticationConfig, F as FormContextType } from './SmartFormProvider-DtK3qRsV.js';
|
|
4
|
+
export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-DtK3qRsV.js';
|
|
5
5
|
export { a as SmartCheckbox, d as SmartCombobox, k as SmartComboboxOption, j as SmartComboboxProps, e as SmartDatePicker, i as SmartDatePickerProps, S as SmartInput, g as SmartInputProps, b as SmartRadioGroup, c as SmartSelect, f as SmartTags } from './SmartTags-DEpmTDF5.js';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
|
|
@@ -200,7 +200,7 @@ interface SmartTextAreaProps {
|
|
|
200
200
|
maxLength?: number;
|
|
201
201
|
minLength?: number;
|
|
202
202
|
name?: string;
|
|
203
|
-
|
|
203
|
+
dirname?: string;
|
|
204
204
|
form?: string;
|
|
205
205
|
}
|
|
206
206
|
declare const SmartTextArea: React__default.FC<SmartTextAreaProps>;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Button } from './chunk-
|
|
2
|
-
export { SmartCheckbox, SmartCombobox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-
|
|
3
|
-
import { SmartFormProvider, useSmartForm, FieldDetectionContext, useFormField, useFieldDetection, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, Textarea, cn } from './chunk-
|
|
4
|
-
export { SmartFormProvider, SmartInput, useFieldDetection, useFormField, useSmartForm } from './chunk-
|
|
1
|
+
import { Button } from './chunk-N3SIQIJR.js';
|
|
2
|
+
export { SmartCheckbox, SmartCombobox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-N3SIQIJR.js';
|
|
3
|
+
import { SmartFormProvider, useSmartForm, FieldDetectionContext, useFormField, useFieldDetection, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, Textarea, cn } from './chunk-DYTQTHGE.js';
|
|
4
|
+
export { SmartFormProvider, SmartInput, useFieldDetection, useFormField, useSmartForm } from './chunk-DYTQTHGE.js';
|
|
5
5
|
import * as React3 from 'react';
|
|
6
6
|
import React3__default, { createContext, isValidElement, useContext, useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
7
7
|
import { ToastContainer, Bounce } from 'react-toastify';
|
|
@@ -640,6 +640,7 @@ function Tabs({
|
|
|
640
640
|
if (!isControlled) setActiveValue(val);
|
|
641
641
|
else props.onValueChange?.(val);
|
|
642
642
|
};
|
|
643
|
+
const { onValueChange, ...divProps } = props;
|
|
643
644
|
return /* @__PURE__ */ jsx(TabsConfigContext.Provider, { value: config, children: /* @__PURE__ */ jsx(
|
|
644
645
|
TabsContext.Provider,
|
|
645
646
|
{
|
|
@@ -648,7 +649,7 @@ function Tabs({
|
|
|
648
649
|
handleValueChange,
|
|
649
650
|
registerTrigger
|
|
650
651
|
},
|
|
651
|
-
children: /* @__PURE__ */ jsx("div", { "data-slot": "tabs", className: cn("flex flex-col gap-2", className), ...
|
|
652
|
+
children: /* @__PURE__ */ jsx("div", { "data-slot": "tabs", className: cn("flex flex-col gap-2", className), ...divProps, children: props.children })
|
|
652
653
|
}
|
|
653
654
|
) });
|
|
654
655
|
}
|
|
@@ -1213,7 +1214,7 @@ var MultiTabFormContent = ({
|
|
|
1213
1214
|
maxUnlockedTab,
|
|
1214
1215
|
setMaxUnlockedTab
|
|
1215
1216
|
}) => {
|
|
1216
|
-
const { isLoading, isDraftSaving, submitForm, saveDraft, resetForm, validateFields, formData, validationRegistry, setErrors } = useSmartForm();
|
|
1217
|
+
const { isLoading, isDraftSaving, submitForm, saveDraft, resetForm, validateFields, formData, validationRegistry, setErrors, getValidationErrorMessage } = useSmartForm();
|
|
1217
1218
|
const debounce = (func, wait) => {
|
|
1218
1219
|
let timeout;
|
|
1219
1220
|
return function executedFunction(...args) {
|
|
@@ -1292,7 +1293,8 @@ var MultiTabFormContent = ({
|
|
|
1292
1293
|
validation.parse(formData[field]);
|
|
1293
1294
|
} catch (error) {
|
|
1294
1295
|
if (error instanceof z.ZodError) {
|
|
1295
|
-
|
|
1296
|
+
const msg = error.issues[0]?.message ?? "";
|
|
1297
|
+
allErrors[field] = getValidationErrorMessage(field, msg);
|
|
1296
1298
|
isValid = false;
|
|
1297
1299
|
}
|
|
1298
1300
|
}
|
|
@@ -1370,7 +1372,7 @@ var MultiTabFormContent = ({
|
|
|
1370
1372
|
onNext();
|
|
1371
1373
|
}
|
|
1372
1374
|
}
|
|
1373
|
-
}, [activeTab, getCombinedTabFields, validateFields, onNext, setCompletedTabs, setValidationErrorTabs, validationRegistry, formData, tabCallbacks, setProcessingTab, setProcessingError, setMaxUnlockedTab]);
|
|
1375
|
+
}, [activeTab, getCombinedTabFields, validateFields, onNext, setCompletedTabs, setValidationErrorTabs, validationRegistry, formData, tabCallbacks, setProcessingTab, setProcessingError, setMaxUnlockedTab, getValidationErrorMessage]);
|
|
1374
1376
|
const handleSubmitWithValidation = useCallback(async () => {
|
|
1375
1377
|
const allErrors = {};
|
|
1376
1378
|
let isValid = true;
|
|
@@ -1381,7 +1383,8 @@ var MultiTabFormContent = ({
|
|
|
1381
1383
|
validation.parse(formData[field]);
|
|
1382
1384
|
} catch (error) {
|
|
1383
1385
|
if (error instanceof z.ZodError) {
|
|
1384
|
-
|
|
1386
|
+
const msg = error.issues[0]?.message ?? "";
|
|
1387
|
+
allErrors[field] = getValidationErrorMessage(field, msg);
|
|
1385
1388
|
isValid = false;
|
|
1386
1389
|
}
|
|
1387
1390
|
}
|
|
@@ -1417,7 +1420,7 @@ var MultiTabFormContent = ({
|
|
|
1417
1420
|
}, 100);
|
|
1418
1421
|
}
|
|
1419
1422
|
}
|
|
1420
|
-
}, [submitForm, getCombinedTabFields, onTabChange, tabs.length, validationRegistry, formData, setErrors, setValidationErrorTabs]);
|
|
1423
|
+
}, [submitForm, getCombinedTabFields, onTabChange, tabs.length, validationRegistry, formData, setErrors, setValidationErrorTabs, getValidationErrorMessage]);
|
|
1421
1424
|
const activeTabValue = tabs[activeTab] || tabs[0] || "";
|
|
1422
1425
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1423
1426
|
/* @__PURE__ */ jsxs(
|
|
@@ -1462,14 +1465,7 @@ var MultiTabFormContent = ({
|
|
|
1462
1465
|
const hasProcessingOverlay = tabCallbacks[index]?.processingOverlay;
|
|
1463
1466
|
return /* @__PURE__ */ jsx(TabsContent, { value: tabProps.title, children: /* @__PURE__ */ jsx(TabIndexProvider, { tabIndex: index, children: /* @__PURE__ */ jsxs("div", { className: "space-y-6 relative", children: [
|
|
1464
1467
|
tabProps.children,
|
|
1465
|
-
isCurrentlyProcessing && hasProcessingOverlay && /* @__PURE__ */ jsx(
|
|
1466
|
-
"div",
|
|
1467
|
-
{
|
|
1468
|
-
className: "absolute inset-0 bg-white/80 backdrop-blur-sm z-50 flex items-center justify-center pointer-events-none",
|
|
1469
|
-
style: { minHeight: "200px" },
|
|
1470
|
-
children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", children: tabCallbacks[index].processingOverlay })
|
|
1471
|
-
}
|
|
1472
|
-
)
|
|
1468
|
+
isCurrentlyProcessing && hasProcessingOverlay && /* @__PURE__ */ jsx("div", { className: "fixed inset-0 bg-black/70 z-50 flex items-center justify-center pointer-events-none", children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", children: tabCallbacks[index].processingOverlay }) })
|
|
1473
1469
|
] }) }) }, index);
|
|
1474
1470
|
}
|
|
1475
1471
|
return null;
|
|
@@ -1636,7 +1632,7 @@ var SmartTextArea = ({
|
|
|
1636
1632
|
maxLength,
|
|
1637
1633
|
minLength,
|
|
1638
1634
|
name,
|
|
1639
|
-
|
|
1635
|
+
dirname,
|
|
1640
1636
|
form
|
|
1641
1637
|
}) => {
|
|
1642
1638
|
const { formData } = useSmartForm();
|
|
@@ -1647,12 +1643,25 @@ var SmartTextArea = ({
|
|
|
1647
1643
|
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
1648
1644
|
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
1649
1645
|
if (isHidden) return null;
|
|
1646
|
+
const displayName = label || field;
|
|
1647
|
+
const builtinValidation = useMemo(() => {
|
|
1648
|
+
if (validation) return void 0;
|
|
1649
|
+
const preprocess = (v) => v === void 0 || v === null ? "" : v;
|
|
1650
|
+
if (minLength != null) {
|
|
1651
|
+
return z.preprocess(preprocess, z.string().min(minLength, `${displayName} must be at least ${minLength} characters`));
|
|
1652
|
+
}
|
|
1653
|
+
if (required) {
|
|
1654
|
+
return z.preprocess(preprocess, z.string().min(1, `${displayName} is required`));
|
|
1655
|
+
}
|
|
1656
|
+
return void 0;
|
|
1657
|
+
}, [validation, minLength, required, displayName]);
|
|
1658
|
+
const schemaToRegister = validation ?? builtinValidation;
|
|
1650
1659
|
useEffect(() => {
|
|
1651
|
-
if (
|
|
1660
|
+
if (schemaToRegister && !hasRegistered.current) {
|
|
1652
1661
|
hasRegistered.current = true;
|
|
1653
|
-
registerValidation(field,
|
|
1662
|
+
registerValidation(field, schemaToRegister, { label: displayName });
|
|
1654
1663
|
}
|
|
1655
|
-
}, [
|
|
1664
|
+
}, [schemaToRegister, field, registerValidation, displayName]);
|
|
1656
1665
|
useEffect(() => {
|
|
1657
1666
|
if (fieldDetection?.registerField) {
|
|
1658
1667
|
fieldDetection.registerField(field);
|
|
@@ -1724,7 +1733,7 @@ var SmartTextArea = ({
|
|
|
1724
1733
|
maxLength,
|
|
1725
1734
|
minLength,
|
|
1726
1735
|
name,
|
|
1727
|
-
dirName,
|
|
1736
|
+
dirName: dirname,
|
|
1728
1737
|
form
|
|
1729
1738
|
}
|
|
1730
1739
|
),
|