@saastro/forms 0.6.0 → 0.6.2

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.ts CHANGED
@@ -3439,6 +3439,22 @@ declare function useFormLayout(layout?: FormLayout): {
3439
3439
  gridStyle: React$1.CSSProperties;
3440
3440
  };
3441
3441
 
3442
+ /**
3443
+ * Minimal "value is present" schema for a field that declares
3444
+ * `required: true` at the top level but ships NO explicit `schema`.
3445
+ *
3446
+ * The builder stores `required` at the top level (it drives the asterisk +
3447
+ * the native `required` attribute). Until now `useFormState` only built
3448
+ * validation from `field.schema`, so a `required: true` field without a
3449
+ * schema skipped validation entirely — empty submissions sailed through.
3450
+ *
3451
+ * Kept value-type-agnostic (`z.any()` + refine) on purpose so it never
3452
+ * fights the stored value shape: number inputs hold strings, checkboxes
3453
+ * hold booleans, multi-selects hold arrays. It only enforces presence; rich
3454
+ * per-type rules (email format, min/max, …) still come from an explicit
3455
+ * `schema`/`ValidationRules`.
3456
+ */
3457
+ declare function buildRequiredOnlySchema(fieldType: string): z.ZodTypeAny;
3442
3458
  declare function useFormState({ config: rawConfig, fields: rawFields, steps: rawSteps, }: {
3443
3459
  config: FormConfig;
3444
3460
  fields: Fields;
@@ -3933,4 +3949,4 @@ declare function getFieldClass(formLayout?: {
3933
3949
  */
3934
3950
  declare function getHiddenClasses(hidden?: Partial<Record<Breakpoint, 'visible' | 'hidden'>>): string;
3935
3951
 
3936
- export { type AccordionContentProps, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, BUILD_METHODS, BUILTIN_RESOLVERS, type BaseFieldProps, type Breakpoint$1 as Breakpoint, type BuiltinTransform, type ButtonCardFieldProps, type ButtonCardOption, type ButtonCheckboxFieldProps, type ButtonConfig, type ButtonProps, type ButtonRadioFieldProps, COMMON_CLASSES, COMMON_METHODS, COMMON_STRINGS, type CalendarProps, type CheckboxFieldProps, type CheckboxGroupFieldProps, type CheckboxProps, type ColumnsValue, type ComboboxFieldProps, type CommandEmptyProps, type CommandFieldProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, type ComponentName, type ComponentOverrides, ComponentProvider, type ComponentProviderProps, type ComponentRegistry, type ComponentRegistryInput, ComponentResolver, type ComponentResolverConfig, type Condition, type ConditionGroup, type ConditionOperator, type CreateHubFormSubmitOptions, type CurrencyFieldProps, type CustomSubmitAction, type CustomSubmitConfig, DEFAULT_HUB_URL, type DatabowlConfig, type DateFieldProps, type DateRangeFieldProps, type DefaultSubmitConfig, type DefinePlugin, type DialogContentProps, type DialogDescriptionProps, type DialogHeaderProps, type DialogProps, type DialogTitleProps, type DialogTriggerProps, type EmailProvider, type EmailSubmitAction, type EndpointConfig, FIELD_DEFAULTS, FieldBuilder, type FieldConfig, type FieldDescriptionProps, type FieldErrorProps, type FieldLabelProps, type FieldLayoutConfig, type FieldMapEntry, type FieldMapping, type FieldMappingConfig, type FieldProps, FieldRenderer, type FieldResolver, type FieldTransformFn, type Fields, type FileFieldProps, Form, FormBuilder, type FormButtonProps, type FormButtons, FormComponentsProvider, type FormComponentsProviderProps, type FormConfig, type FormControlProps, type FormFieldProps, type FormLayout, type FormPlugin, type FormProps, type FormRef, type FormStepsInfo, type GapValue, type GlobModules, type HiddenFieldProps, type HtmlFieldProps, type HttpAuthConfig, type HttpBodyConfig, type HttpEndpointConfig, type HttpRetryConfig, type HttpSubmitAction, HubForm, type HubFormProps, type InputGroupFieldProps, type InputOTPGroupProps, type InputOTPProps, type InputOTPSlotProps, type InputProps, type InputSize, type IntegrationSubmitAction, InternalComponentProvider, type InternalComponentProviderProps, type LabelProps, MissingComponentFallback, type MissingComponentFallbackProps, type NativeSelectFieldProps, type NativeSelectProps, OPTION_BASED_TYPES, type Option, type OtpFieldProps, type PartialComponentRegistry, PluginManager, type PopoverContentProps, type PopoverProps, type PopoverTriggerProps, type PropertyMapping, type RadioFieldProps, type RadioGroupItemProps, type RadioGroupProps, type RangeFieldProps, type RecaptchaConfig, type RecaptchaPluginConfig, type RepeaterFieldProps, type ResolvedComponents, SUSPENSE_CONFIG, type SchemaType, type SelectContentProps, type SelectFieldProps, type SelectItemProps, type SelectProps, type SelectTriggerProps, type SelectValueProps, type SeparatorProps, type SerializableFieldResolver, type SerializationHint, type SliderFieldProps, type SliderProps, type Step, type StepCondition, type StepInfo, type StepStatus, type Steps, StepsAccordion, StepsNavigation, StepsProgress, type SubmitAction, type SubmitActionCondition, type SubmitActionNode, type SubmitActionResult, type SubmitActionType, type SubmitActionsResult, type SubmitConfig, type SubmitConfirmationConfig, type SubmitExecutionConfig, type SubmitTrigger, type SubmitTriggerType, type SubmitType, type SwitchFieldProps, type SwitchGroupFieldProps, type SwitchProps, TYPE_SPECIFIC_PROPERTIES, type TestDataLocale, type TestDataOptions, type TextFieldProps, type TextareaFieldProps, type TextareaProps, type TooltipContentProps, type TooltipProps, type TooltipProviderProps, type TooltipTriggerProps, type TurnstilePluginConfig, type UseSubmitConfirmationReturn, VALIDATION_METHODS, type ValidateComponentRegistry, type ValidationContext, type ValidationPresetMeta, type ValidationRules, type WebhookSubmitAction, analyticsPlugin, applyBuiltinTransform, applyFieldMapping, applyFieldMappingSync, applyFieldTransforms, applyTransform, autosavePlugin, compileValidationRules, configureComponents, coreComponents, createComponentRegistry, createHubFormSubmit, createMissingComponentPlaceholder, createShadcnRegistry, databowlAction, databowlPlugin, defaultSubmit, definePlugin, detectLocale, executeCustomAction, executeEmailAction, executeHttpAction, executeSubmitAction, executeSubmitActions, executeSubmitActionsByTrigger, executeWebhookAction, fieldTypeComponents, generateFieldValue, generateTestData, getActionsByTrigger, getAllKnownMethods, getAvailablePresets, getComponentResolver, getFieldClass, getFormGridClass, getHiddenClasses, getInstallCommand, getMinDelayMs, getMissingComponents, getRequiredComponents, globalPluginManager, groupMissingByPackage, iconVariants, iconVariantsConfig, inputVariants, inputVariantsConfig, isAdvancedMapping, isValidationRules, isZodSchema, localStoragePlugin, mergeComponentRegistries, parseGlobModules, pxToRem, recaptchaPlugin, registerPreset, resolvePreset, resolveValue, resolveValueSync, textareaVariants, textareaVariantsConfig, turnstilePlugin, useComponentMode, useComponents, useComputedFields, useFormLayout, useFormState, useFormStepsInfo, useHasComponentProvider, useHiddenFieldResolvers, usePartialComponents, useRecaptcha, useSubmitActionTriggers, useSubmitConfirmation, withComponents };
3952
+ export { type AccordionContentProps, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, BUILD_METHODS, BUILTIN_RESOLVERS, type BaseFieldProps, type Breakpoint$1 as Breakpoint, type BuiltinTransform, type ButtonCardFieldProps, type ButtonCardOption, type ButtonCheckboxFieldProps, type ButtonConfig, type ButtonProps, type ButtonRadioFieldProps, COMMON_CLASSES, COMMON_METHODS, COMMON_STRINGS, type CalendarProps, type CheckboxFieldProps, type CheckboxGroupFieldProps, type CheckboxProps, type ColumnsValue, type ComboboxFieldProps, type CommandEmptyProps, type CommandFieldProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, type ComponentName, type ComponentOverrides, ComponentProvider, type ComponentProviderProps, type ComponentRegistry, type ComponentRegistryInput, ComponentResolver, type ComponentResolverConfig, type Condition, type ConditionGroup, type ConditionOperator, type CreateHubFormSubmitOptions, type CurrencyFieldProps, type CustomSubmitAction, type CustomSubmitConfig, DEFAULT_HUB_URL, type DatabowlConfig, type DateFieldProps, type DateRangeFieldProps, type DefaultSubmitConfig, type DefinePlugin, type DialogContentProps, type DialogDescriptionProps, type DialogHeaderProps, type DialogProps, type DialogTitleProps, type DialogTriggerProps, type EmailProvider, type EmailSubmitAction, type EndpointConfig, FIELD_DEFAULTS, FieldBuilder, type FieldConfig, type FieldDescriptionProps, type FieldErrorProps, type FieldLabelProps, type FieldLayoutConfig, type FieldMapEntry, type FieldMapping, type FieldMappingConfig, type FieldProps, FieldRenderer, type FieldResolver, type FieldTransformFn, type Fields, type FileFieldProps, Form, FormBuilder, type FormButtonProps, type FormButtons, FormComponentsProvider, type FormComponentsProviderProps, type FormConfig, type FormControlProps, type FormFieldProps, type FormLayout, type FormPlugin, type FormProps, type FormRef, type FormStepsInfo, type GapValue, type GlobModules, type HiddenFieldProps, type HtmlFieldProps, type HttpAuthConfig, type HttpBodyConfig, type HttpEndpointConfig, type HttpRetryConfig, type HttpSubmitAction, HubForm, type HubFormProps, type InputGroupFieldProps, type InputOTPGroupProps, type InputOTPProps, type InputOTPSlotProps, type InputProps, type InputSize, type IntegrationSubmitAction, InternalComponentProvider, type InternalComponentProviderProps, type LabelProps, MissingComponentFallback, type MissingComponentFallbackProps, type NativeSelectFieldProps, type NativeSelectProps, OPTION_BASED_TYPES, type Option, type OtpFieldProps, type PartialComponentRegistry, PluginManager, type PopoverContentProps, type PopoverProps, type PopoverTriggerProps, type PropertyMapping, type RadioFieldProps, type RadioGroupItemProps, type RadioGroupProps, type RangeFieldProps, type RecaptchaConfig, type RecaptchaPluginConfig, type RepeaterFieldProps, type ResolvedComponents, SUSPENSE_CONFIG, type SchemaType, type SelectContentProps, type SelectFieldProps, type SelectItemProps, type SelectProps, type SelectTriggerProps, type SelectValueProps, type SeparatorProps, type SerializableFieldResolver, type SerializationHint, type SliderFieldProps, type SliderProps, type Step, type StepCondition, type StepInfo, type StepStatus, type Steps, StepsAccordion, StepsNavigation, StepsProgress, type SubmitAction, type SubmitActionCondition, type SubmitActionNode, type SubmitActionResult, type SubmitActionType, type SubmitActionsResult, type SubmitConfig, type SubmitConfirmationConfig, type SubmitExecutionConfig, type SubmitTrigger, type SubmitTriggerType, type SubmitType, type SwitchFieldProps, type SwitchGroupFieldProps, type SwitchProps, TYPE_SPECIFIC_PROPERTIES, type TestDataLocale, type TestDataOptions, type TextFieldProps, type TextareaFieldProps, type TextareaProps, type TooltipContentProps, type TooltipProps, type TooltipProviderProps, type TooltipTriggerProps, type TurnstilePluginConfig, type UseSubmitConfirmationReturn, VALIDATION_METHODS, type ValidateComponentRegistry, type ValidationContext, type ValidationPresetMeta, type ValidationRules, type WebhookSubmitAction, analyticsPlugin, applyBuiltinTransform, applyFieldMapping, applyFieldMappingSync, applyFieldTransforms, applyTransform, autosavePlugin, buildRequiredOnlySchema, compileValidationRules, configureComponents, coreComponents, createComponentRegistry, createHubFormSubmit, createMissingComponentPlaceholder, createShadcnRegistry, databowlAction, databowlPlugin, defaultSubmit, definePlugin, detectLocale, executeCustomAction, executeEmailAction, executeHttpAction, executeSubmitAction, executeSubmitActions, executeSubmitActionsByTrigger, executeWebhookAction, fieldTypeComponents, generateFieldValue, generateTestData, getActionsByTrigger, getAllKnownMethods, getAvailablePresets, getComponentResolver, getFieldClass, getFormGridClass, getHiddenClasses, getInstallCommand, getMinDelayMs, getMissingComponents, getRequiredComponents, globalPluginManager, groupMissingByPackage, iconVariants, iconVariantsConfig, inputVariants, inputVariantsConfig, isAdvancedMapping, isValidationRules, isZodSchema, localStoragePlugin, mergeComponentRegistries, parseGlobModules, pxToRem, recaptchaPlugin, registerPreset, resolvePreset, resolveValue, resolveValueSync, textareaVariants, textareaVariantsConfig, turnstilePlugin, useComponentMode, useComponents, useComputedFields, useFormLayout, useFormState, useFormStepsInfo, useHasComponentProvider, useHiddenFieldResolvers, usePartialComponents, useRecaptcha, useSubmitActionTriggers, useSubmitConfirmation, withComponents };
package/dist/index.js CHANGED
@@ -2912,6 +2912,27 @@ function useComputedFields(methods, fields) {
2912
2912
  }
2913
2913
 
2914
2914
  // src/hooks/useFormState.ts
2915
+ function buildRequiredOnlySchema(fieldType) {
2916
+ const message = "This field is required";
2917
+ if (fieldType === "checkbox" || fieldType === "switch") {
2918
+ return z2.any().refine((v) => v === true, {
2919
+ message: "You must accept this"
2920
+ });
2921
+ }
2922
+ if (fieldType === "checkbox-group" || fieldType === "switch-group" || fieldType === "button-checkbox" || fieldType === "button-card") {
2923
+ return z2.any().refine((v) => Array.isArray(v) && v.length > 0, { message });
2924
+ }
2925
+ if (fieldType === "daterange") {
2926
+ return z2.any().refine(
2927
+ (v) => !!v && typeof v === "object" && !!v.from,
2928
+ { message }
2929
+ );
2930
+ }
2931
+ return z2.any().refine(
2932
+ (v) => v !== void 0 && v !== null && v !== "" && !(typeof v === "number" && Number.isNaN(v)),
2933
+ { message }
2934
+ );
2935
+ }
2915
2936
  function useFormState({
2916
2937
  config: rawConfig,
2917
2938
  fields: rawFields,
@@ -2967,6 +2988,8 @@ function useFormState({
2967
2988
  });
2968
2989
  }
2969
2990
  schema[name] = fieldSchema;
2991
+ } else if (cfg.required) {
2992
+ schema[name] = buildRequiredOnlySchema(cfg.type);
2970
2993
  }
2971
2994
  defaults[name] = cfg.value ?? (() => {
2972
2995
  switch (cfg.type) {
@@ -6106,19 +6129,31 @@ function turnstilePlugin(config) {
6106
6129
  } = config;
6107
6130
  let scriptElement = null;
6108
6131
  let createdContainer = null;
6132
+ let renderedEl = null;
6109
6133
  let widgetId;
6110
6134
  let lastToken = null;
6111
6135
  let pending = null;
6136
+ const markNoTranslate = (el) => {
6137
+ el.setAttribute("translate", "no");
6138
+ el.classList.add("notranslate");
6139
+ };
6112
6140
  const resolveContainer = () => {
6113
6141
  if (container) {
6114
6142
  const found = document.querySelector(container);
6115
- if (found) return found;
6143
+ if (found) {
6144
+ markNoTranslate(found);
6145
+ return found;
6146
+ }
6116
6147
  }
6117
6148
  const byData = document.querySelector("[data-saastro-turnstile]");
6118
- if (byData) return byData;
6119
- if (!createdContainer) {
6149
+ if (byData) {
6150
+ markNoTranslate(byData);
6151
+ return byData;
6152
+ }
6153
+ if (!createdContainer || !document.body.contains(createdContainer)) {
6120
6154
  createdContainer = document.createElement("div");
6121
6155
  createdContainer.setAttribute("data-saastro-turnstile-fallback", "");
6156
+ markNoTranslate(createdContainer);
6122
6157
  createdContainer.style.position = "fixed";
6123
6158
  createdContainer.style.bottom = "12px";
6124
6159
  createdContainer.style.right = "12px";
@@ -6127,10 +6162,19 @@ function turnstilePlugin(config) {
6127
6162
  }
6128
6163
  return createdContainer;
6129
6164
  };
6165
+ const widgetAlive = () => widgetId !== void 0 && !!renderedEl && document.contains(renderedEl) && renderedEl.childElementCount > 0;
6130
6166
  const ensureWidget = async () => {
6131
6167
  const api = await waitForTurnstile();
6132
- if (widgetId === void 0) {
6168
+ if (!widgetAlive()) {
6169
+ if (widgetId !== void 0) {
6170
+ try {
6171
+ api.remove(widgetId);
6172
+ } catch {
6173
+ }
6174
+ widgetId = void 0;
6175
+ }
6133
6176
  const el = resolveContainer();
6177
+ renderedEl = el;
6134
6178
  widgetId = api.render(el, {
6135
6179
  sitekey: siteKey,
6136
6180
  appearance,
@@ -6207,6 +6251,7 @@ function turnstilePlugin(config) {
6207
6251
  }
6208
6252
  }
6209
6253
  widgetId = void 0;
6254
+ renderedEl = null;
6210
6255
  lastToken = null;
6211
6256
  pending = null;
6212
6257
  if (createdContainer?.parentNode) {
@@ -7164,7 +7209,7 @@ function HubForm({
7164
7209
  };
7165
7210
  return /* @__PURE__ */ jsxs11(Fragment3, { children: [
7166
7211
  /* @__PURE__ */ jsx14(Form, { ...formProps, config }),
7167
- captcha?.provider === "turnstile" ? /* @__PURE__ */ jsx14("div", { "data-saastro-turnstile": true }) : null
7212
+ captcha?.provider === "turnstile" ? /* @__PURE__ */ jsx14("div", { "data-saastro-turnstile": true, translate: "no", className: "notranslate" }) : null
7168
7213
  ] });
7169
7214
  }
7170
7215
  var loadingStyle = {
@@ -7452,6 +7497,7 @@ export {
7452
7497
  applyFieldTransforms,
7453
7498
  applyTransform,
7454
7499
  autosavePlugin,
7500
+ buildRequiredOnlySchema,
7455
7501
  compileValidationRules,
7456
7502
  configureComponents,
7457
7503
  coreComponents,