@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/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-BdyRQakk.cjs';
4
- export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-BdyRQakk.cjs';
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
- dirName?: string;
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-BdyRQakk.js';
4
- export { b as FormConfig, S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-BdyRQakk.js';
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
- dirName?: string;
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-4XK6HAJ2.js';
2
- export { SmartCheckbox, SmartCombobox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-4XK6HAJ2.js';
3
- import { SmartFormProvider, useSmartForm, FieldDetectionContext, useFormField, useFieldDetection, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, Textarea, cn } from './chunk-6VKQ7EMR.js';
4
- export { SmartFormProvider, SmartInput, useFieldDetection, useFormField, useSmartForm } from './chunk-6VKQ7EMR.js';
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), ...props, children: props.children })
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
- allErrors[field] = error.issues[0]?.message || `Invalid ${field}`;
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
- allErrors[field] = error.issues[0]?.message || `Invalid ${field}`;
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
- dirName,
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 (validation && !hasRegistered.current) {
1660
+ if (schemaToRegister && !hasRegistered.current) {
1652
1661
  hasRegistered.current = true;
1653
- registerValidation(field, validation);
1662
+ registerValidation(field, schemaToRegister, { label: displayName });
1654
1663
  }
1655
- }, [validation, field, registerValidation]);
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
  ),