@saas-ui/forms 3.0.0-alpha.0 → 3.0.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 3.0.0-alpha.1
4
+
5
+ ### Major Changes
6
+
7
+ - 550e5a6: Upgrade to Chakra v3
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [550e5a6]
12
+ - @saas-ui/react@3.0.0-alpha.1
13
+ - @saas-ui/core@3.0.0-alpha.1
14
+
3
15
  ## 3.0.0-alpha.0
4
16
 
5
17
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -5,7 +5,6 @@ import { MaybeRenderProp } from '@saas-ui/core/utils';
5
5
  import * as react_hook_form from 'react-hook-form';
6
6
  import { FieldValues, FieldPath, UseFormReturn as UseFormReturn$1, UseFieldArrayReturn, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, ResolverOptions, ResolverResult, RegisterOptions, FormProviderProps as FormProviderProps$1 } from 'react-hook-form';
7
7
  export { ArrayPath, BatchFieldArrayUpdate, BrowserNativeObject, ChangeHandler, Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, CriteriaMode, CustomElement, DeepMap, DeepPartial, DeepPartialSkipArrayKey, DeepRequired, DefaultValues, DelayCallback, EmptyObject, ErrorOption, EventType, ExtractObjects, FieldArray, FieldArrayMethodProps, FieldArrayPath, FieldArrayPathValue, FieldArrayWithId, Field as FieldDef, FieldElement, FieldError, FieldErrors, FieldErrorsImpl, FieldName, FieldNamesMarkedBoolean, FieldPath, FieldPathByValue, FieldPathValue, FieldPathValues, FieldRefs, FieldValue, FieldValues, FormProviderProps, FormState, FormStateProxy, FormStateSubjectRef, GetIsDirty, InternalFieldErrors, InternalFieldName, InternalNameSet, IsAny, IsFlatObject, KeepStateOptions, LiteralUnion, Message, Mode, MultipleFieldErrors, Names, NativeFieldValue, NestedValue, NonUndefined, Noop, Primitive, ReadFormState, Ref, RefCallBack, RegisterOptions, Resolver, ResolverError, ResolverOptions, ResolverResult, ResolverSuccess, SetFieldValue, SetValueConfig, Subjects, SubmitErrorHandler, SubmitHandler, TriggerConfig, UnpackNestedValue, UseControllerProps, UseControllerReturn, UseFieldArrayProps, UseFieldArrayReturn, UseFormClearErrors, UseFormGetValues, UseFormHandleSubmit, UseFormProps, UseFormRegister, UseFormRegisterReturn, UseFormReset, UseFormResetField, UseFormReturn, UseFormSetError, UseFormSetFocus, UseFormSetValue, UseFormStateProps, UseFormStateReturn, UseFormTrigger, UseFormUnregister, UseFormWatch, UseWatchProps, Validate, ValidateResult, ValidationMode, ValidationRule, ValidationValue, ValidationValueMessage, WatchInternal, WatchObserver, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
8
- import { MaybeRenderProp as MaybeRenderProp$1 } from '@chakra-ui/utils';
9
8
  import { CheckboxProps } from '@saas-ui/react/checkbox';
10
9
  import { NumberInputProps } from '@saas-ui/react/number-input';
11
10
  import { PasswordInputProps } from '@saas-ui/react/password-input';
@@ -352,7 +351,7 @@ type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues,
352
351
  } : never;
353
352
  }>;
354
353
  type FieldProps<TFieldValues extends FieldValues = FieldValues, TExtraFieldProps extends object = object> = MergeFieldProps<DefaultFields, TFieldValues, TExtraFieldProps>;
355
- type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TExtraFieldProps extends object = object> = MaybeRenderProp$1<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues, TExtraFieldProps>>>;
354
+ type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TExtraFieldProps extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues, TExtraFieldProps>>>;
356
355
  type DefaultFieldOverrides = {
357
356
  submit?: SubmitButtonProps;
358
357
  [key: string]: any;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,6 @@ import { MaybeRenderProp } from '@saas-ui/core/utils';
5
5
  import * as react_hook_form from 'react-hook-form';
6
6
  import { FieldValues, FieldPath, UseFormReturn as UseFormReturn$1, UseFieldArrayReturn, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, ResolverOptions, ResolverResult, RegisterOptions, FormProviderProps as FormProviderProps$1 } from 'react-hook-form';
7
7
  export { ArrayPath, BatchFieldArrayUpdate, BrowserNativeObject, ChangeHandler, Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, CriteriaMode, CustomElement, DeepMap, DeepPartial, DeepPartialSkipArrayKey, DeepRequired, DefaultValues, DelayCallback, EmptyObject, ErrorOption, EventType, ExtractObjects, FieldArray, FieldArrayMethodProps, FieldArrayPath, FieldArrayPathValue, FieldArrayWithId, Field as FieldDef, FieldElement, FieldError, FieldErrors, FieldErrorsImpl, FieldName, FieldNamesMarkedBoolean, FieldPath, FieldPathByValue, FieldPathValue, FieldPathValues, FieldRefs, FieldValue, FieldValues, FormProviderProps, FormState, FormStateProxy, FormStateSubjectRef, GetIsDirty, InternalFieldErrors, InternalFieldName, InternalNameSet, IsAny, IsFlatObject, KeepStateOptions, LiteralUnion, Message, Mode, MultipleFieldErrors, Names, NativeFieldValue, NestedValue, NonUndefined, Noop, Primitive, ReadFormState, Ref, RefCallBack, RegisterOptions, Resolver, ResolverError, ResolverOptions, ResolverResult, ResolverSuccess, SetFieldValue, SetValueConfig, Subjects, SubmitErrorHandler, SubmitHandler, TriggerConfig, UnpackNestedValue, UseControllerProps, UseControllerReturn, UseFieldArrayProps, UseFieldArrayReturn, UseFormClearErrors, UseFormGetValues, UseFormHandleSubmit, UseFormProps, UseFormRegister, UseFormRegisterReturn, UseFormReset, UseFormResetField, UseFormReturn, UseFormSetError, UseFormSetFocus, UseFormSetValue, UseFormStateProps, UseFormStateReturn, UseFormTrigger, UseFormUnregister, UseFormWatch, UseWatchProps, Validate, ValidateResult, ValidationMode, ValidationRule, ValidationValue, ValidationValueMessage, WatchInternal, WatchObserver, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
8
- import { MaybeRenderProp as MaybeRenderProp$1 } from '@chakra-ui/utils';
9
8
  import { CheckboxProps } from '@saas-ui/react/checkbox';
10
9
  import { NumberInputProps } from '@saas-ui/react/number-input';
11
10
  import { PasswordInputProps } from '@saas-ui/react/password-input';
@@ -352,7 +351,7 @@ type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues,
352
351
  } : never;
353
352
  }>;
354
353
  type FieldProps<TFieldValues extends FieldValues = FieldValues, TExtraFieldProps extends object = object> = MergeFieldProps<DefaultFields, TFieldValues, TExtraFieldProps>;
355
- type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TExtraFieldProps extends object = object> = MaybeRenderProp$1<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues, TExtraFieldProps>>>;
354
+ type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TExtraFieldProps extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues, TExtraFieldProps>>>;
356
355
  type DefaultFieldOverrides = {
357
356
  submit?: SubmitButtonProps;
358
357
  [key: string]: any;
@@ -1,9 +1,11 @@
1
- import { FieldProps, WithFields, FormProps, GetBaseField, CreateFormProps } from '@saas-ui/forms';
1
+ import { WithFields, FormProps, GetBaseField, CreateFormProps } from '@saas-ui/forms';
2
2
  import * as z from 'zod';
3
3
  import { z as z$1 } from 'zod';
4
4
  import { zodResolver } from '@hookform/resolvers/zod';
5
5
  export { zodResolver } from '@hookform/resolvers/zod';
6
6
 
7
+ type FieldProps = any;
8
+
7
9
  /**
8
10
  * A helper function to render forms automatically based on a Yup schema
9
11
  *
@@ -13,8 +15,8 @@ export { zodResolver } from '@hookform/resolvers/zod';
13
15
  declare const getFieldsFromSchema: (schema: z.ZodTypeAny) => FieldProps[];
14
16
  declare const getNestedSchema: (schema: z.ZodTypeAny, path: string) => any;
15
17
  declare const zodFieldResolver: <T extends z.ZodTypeAny>(schema: T) => {
16
- getFields(): FieldProps[];
17
- getNestedFields(name: string): FieldProps[];
18
+ getFields(): any[];
19
+ getNestedFields(name: string): any[];
18
20
  };
19
21
  interface ZodMeta {
20
22
  /**
@@ -1,9 +1,11 @@
1
- import { FieldProps, WithFields, FormProps, GetBaseField, CreateFormProps } from '@saas-ui/forms';
1
+ import { WithFields, FormProps, GetBaseField, CreateFormProps } from '@saas-ui/forms';
2
2
  import * as z from 'zod';
3
3
  import { z as z$1 } from 'zod';
4
4
  import { zodResolver } from '@hookform/resolvers/zod';
5
5
  export { zodResolver } from '@hookform/resolvers/zod';
6
6
 
7
+ type FieldProps = any;
8
+
7
9
  /**
8
10
  * A helper function to render forms automatically based on a Yup schema
9
11
  *
@@ -13,8 +15,8 @@ export { zodResolver } from '@hookform/resolvers/zod';
13
15
  declare const getFieldsFromSchema: (schema: z.ZodTypeAny) => FieldProps[];
14
16
  declare const getNestedSchema: (schema: z.ZodTypeAny, path: string) => any;
15
17
  declare const zodFieldResolver: <T extends z.ZodTypeAny>(schema: T) => {
16
- getFields(): FieldProps[];
17
- getNestedFields(name: string): FieldProps[];
18
+ getFields(): any[];
19
+ getNestedFields(name: string): any[];
18
20
  };
19
21
  interface ZodMeta {
20
22
  /**
package/dist/zod/index.js CHANGED
@@ -37,7 +37,7 @@ var import_forms = require("@saas-ui/forms");
37
37
 
38
38
  // zod/src/zod-resolver.ts
39
39
  var import_zod = require("@hookform/resolvers/zod");
40
- var import_utils = require("@chakra-ui/utils");
40
+ var import_utils = require("@saas-ui/core/utils");
41
41
  var getType = (field) => {
42
42
  if (["ZodDefault", "ZodOptional"].includes(field._def.typeName)) {
43
43
  return getType(field._def.innerType);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../zod/src/index.ts","../../zod/src/create-zod-form.ts","../../zod/src/zod-resolver.ts"],"sourcesContent":["// export { createZodStepForm } from './create-zod-step-form'\nimport { createZodForm } from './create-zod-form'\n\nexport {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\n\n// import { createZodStepForm } from './create-zod-step-form'\n\nexport const Form = createZodForm()\n\n// export const StepForm = createZodStepForm()\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n GetBaseField,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<\n FieldDefs,\n TGetBaseField extends GetBaseField = GetBaseField,\n> extends CreateFormProps<FieldDefs, TGetBaseField> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraFieldProps extends object = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod',\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object,\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext, ExtraFieldProps>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <\n FieldDefs,\n TGetBaseField extends GetBaseField<any> = GetBaseField<any>,\n>(\n options?: CreateZodFormProps<FieldDefs, TGetBaseField>\n) => {\n type ExtraFieldProps =\n TGetBaseField extends GetBaseField<infer ExtraFieldProps>\n ? ExtraFieldProps\n : object\n\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs, object, ExtraFieldProps>\n}\n","import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type ExtraProps = {\n min?: number\n max?: number\n options?: { label: string; value: string }[]\n}\n\nconst getType = (\n field: z.ZodTypeAny\n): 'array' | 'object' | 'number' | 'date' | 'select' | 'text' => {\n if (['ZodDefault', 'ZodOptional'].includes(field._def.typeName)) {\n return getType(field._def.innerType)\n }\n\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodNativeEnum':\n case 'ZodEnum':\n return 'select'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const def =\n field._def.typeName === 'ZodDefault'\n ? field._def.innerType._def\n : field._def\n\n const props: ExtraProps = {}\n if (def.typeName === 'ZodArray') {\n props.min = getArrayOption(field, 'minLength')\n props.max = getArrayOption(field, 'maxLength')\n } else if (def.typeName === 'ZodEnum') {\n props.options = def.values.map((value: string) => {\n return { label: value, value }\n })\n } else if (def.typeName === 'ZodNativeEnum') {\n props.options = Object.entries(def.values).map(([label, value]) => ({\n label,\n value: value as string,\n }))\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n help: meta?.help,\n placeholder: meta?.placeholder,\n defaultValue: field._def.defaultValue?.(),\n ...props,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n /**\n * The label of the field\n */\n label: string\n\n /**\n * The type of the field\n */\n type?: string\n\n /**\n * The placeholder of the field\n */\n placeholder?: string\n\n /**\n * The help text of the field\n */\n help?: string\n\n /**\n * Object field column count\n */\n columns?: number\n\n /**\n * Array field min rows\n */\n min?: number\n\n /**\n * Array field max rows\n */\n max?: number\n\n [key: string]: any\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAMO;;;ACLP,iBAA4B;AAC5B,mBAAoB;AAWpB,IAAM,UAAU,CACd,UAC+D;AAC/D,MAAI,CAAC,cAAc,aAAa,EAAE,SAAS,MAAM,KAAK,QAAQ,GAAG;AAC/D,WAAO,QAAQ,MAAM,KAAK,SAAS;AAAA,EACrC;AAEA,UAAQ,MAAM,KAAK,UAAU;AAAA,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AAAA,MACV;AAAA,MACA,QAAO,6BAAM,UAAS,MAAM,eAAe;AAAA,MAC3C,OAAM,6BAAM,SAAQ,QAAQ,KAAK;AAAA,MACjC,MAAM,6BAAM;AAAA,MACZ,aAAa,6BAAM;AAAA,MACnB,eAAc,iBAAM,MAAK,iBAAX;AAAA,MACd,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAC,QAAsB,SAAiB;AACrE,aAAO,kBAAI,OAAO,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,mBAAmB,CAAyB,WAAc;AACrE,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AAyCO,IAAM,UAAU,CAAC,SAAkB;AACxC,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEO,IAAM,eAAe,CAAC,SAAiB;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;;;ADvHO,IAAM,gBAAgB,CAI3B,YACG;AAMH,QAAM,cAAU,yBAAW;AAAA,IACzB,UAAU,CAAC,eACT,wBAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,SAAO;AACT;;;ADjDO,IAAM,OAAO,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../zod/src/index.ts","../../zod/src/create-zod-form.ts","../../zod/src/zod-resolver.ts"],"sourcesContent":["// export { createZodStepForm } from './create-zod-step-form'\nimport { createZodForm } from './create-zod-form'\n\nexport {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\n\n// import { createZodStepForm } from './create-zod-step-form'\n\nexport const Form = createZodForm()\n\n// export const StepForm = createZodStepForm()\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n GetBaseField,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<\n FieldDefs,\n TGetBaseField extends GetBaseField = GetBaseField,\n> extends CreateFormProps<FieldDefs, TGetBaseField> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraFieldProps extends object = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod',\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object,\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext, ExtraFieldProps>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <\n FieldDefs,\n TGetBaseField extends GetBaseField<any> = GetBaseField<any>,\n>(\n options?: CreateZodFormProps<FieldDefs, TGetBaseField>\n) => {\n type ExtraFieldProps =\n TGetBaseField extends GetBaseField<infer ExtraFieldProps>\n ? ExtraFieldProps\n : object\n\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs, object, ExtraFieldProps>\n}\n","import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@saas-ui/core/utils'\n\n// import { FieldProps } from '@saas-ui/forms'\n\ntype FieldProps = any\n\nexport { zodResolver }\n\nexport type ExtraProps = {\n min?: number\n max?: number\n options?: { label: string; value: string }[]\n}\n\nconst getType = (\n field: z.ZodTypeAny,\n): 'array' | 'object' | 'number' | 'date' | 'select' | 'text' => {\n if (['ZodDefault', 'ZodOptional'].includes(field._def.typeName)) {\n return getType(field._def.innerType)\n }\n\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodNativeEnum':\n case 'ZodEnum':\n return 'select'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const def =\n field._def.typeName === 'ZodDefault'\n ? field._def.innerType._def\n : field._def\n\n const props: ExtraProps = {}\n if (def.typeName === 'ZodArray') {\n props.min = getArrayOption(field, 'minLength')\n props.max = getArrayOption(field, 'maxLength')\n } else if (def.typeName === 'ZodEnum') {\n props.options = def.values.map((value: string) => {\n return { label: value, value }\n })\n } else if (def.typeName === 'ZodNativeEnum') {\n props.options = Object.entries(def.values).map(([label, value]) => ({\n label,\n value: value as string,\n }))\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n help: meta?.help,\n placeholder: meta?.placeholder,\n defaultValue: field._def.defaultValue?.(),\n ...props,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n /**\n * The label of the field\n */\n label: string\n\n /**\n * The type of the field\n */\n type?: string\n\n /**\n * The placeholder of the field\n */\n placeholder?: string\n\n /**\n * The help text of the field\n */\n help?: string\n\n /**\n * Object field column count\n */\n columns?: number\n\n /**\n * Array field min rows\n */\n min?: number\n\n /**\n * Array field max rows\n */\n max?: number\n\n [key: string]: any\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAMO;;;ACLP,iBAA4B;AAC5B,mBAAoB;AAcpB,IAAM,UAAU,CACd,UAC+D;AAC/D,MAAI,CAAC,cAAc,aAAa,EAAE,SAAS,MAAM,KAAK,QAAQ,GAAG;AAC/D,WAAO,QAAQ,MAAM,KAAK,SAAS;AAAA,EACrC;AAEA,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AAzCrD;AA0CE,UAAO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kB,CAAC,QAAsB,SAAiB;AACrE,aAAO,kBAAI,OAAO,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,mBAAmB,CAAyB,WAAc;AACrE,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AAyCO,IAAM,UAAU,CAAC,SAAkB;AACxC,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEO,IAAM,eAAe,CAAC,SAAiB;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;;;AD1HO,IAAM,gBAAgB,CAI3B,YACG;AAMH,QAAM,cAAU,yBAAW;AAAA,IACzB,UAAU,CAAC,eACT,wBAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,SAAO;AACT;;;ADjDO,IAAM,OAAO,cAAc;","names":[]}
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  // zod/src/zod-resolver.ts
9
9
  import { zodResolver } from "@hookform/resolvers/zod";
10
- import { get } from "@chakra-ui/utils";
10
+ import { get } from "@saas-ui/core/utils";
11
11
  var getType = (field) => {
12
12
  if (["ZodDefault", "ZodOptional"].includes(field._def.typeName)) {
13
13
  return getType(field._def.innerType);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../zod/src/create-zod-form.ts","../../zod/src/zod-resolver.ts","../../zod/src/index.ts"],"sourcesContent":["import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n GetBaseField,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<\n FieldDefs,\n TGetBaseField extends GetBaseField = GetBaseField,\n> extends CreateFormProps<FieldDefs, TGetBaseField> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraFieldProps extends object = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod',\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object,\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext, ExtraFieldProps>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <\n FieldDefs,\n TGetBaseField extends GetBaseField<any> = GetBaseField<any>,\n>(\n options?: CreateZodFormProps<FieldDefs, TGetBaseField>\n) => {\n type ExtraFieldProps =\n TGetBaseField extends GetBaseField<infer ExtraFieldProps>\n ? ExtraFieldProps\n : object\n\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs, object, ExtraFieldProps>\n}\n","import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type ExtraProps = {\n min?: number\n max?: number\n options?: { label: string; value: string }[]\n}\n\nconst getType = (\n field: z.ZodTypeAny\n): 'array' | 'object' | 'number' | 'date' | 'select' | 'text' => {\n if (['ZodDefault', 'ZodOptional'].includes(field._def.typeName)) {\n return getType(field._def.innerType)\n }\n\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodNativeEnum':\n case 'ZodEnum':\n return 'select'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const def =\n field._def.typeName === 'ZodDefault'\n ? field._def.innerType._def\n : field._def\n\n const props: ExtraProps = {}\n if (def.typeName === 'ZodArray') {\n props.min = getArrayOption(field, 'minLength')\n props.max = getArrayOption(field, 'maxLength')\n } else if (def.typeName === 'ZodEnum') {\n props.options = def.values.map((value: string) => {\n return { label: value, value }\n })\n } else if (def.typeName === 'ZodNativeEnum') {\n props.options = Object.entries(def.values).map(([label, value]) => ({\n label,\n value: value as string,\n }))\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n help: meta?.help,\n placeholder: meta?.placeholder,\n defaultValue: field._def.defaultValue?.(),\n ...props,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n /**\n * The label of the field\n */\n label: string\n\n /**\n * The type of the field\n */\n type?: string\n\n /**\n * The placeholder of the field\n */\n placeholder?: string\n\n /**\n * The help text of the field\n */\n help?: string\n\n /**\n * Object field column count\n */\n columns?: number\n\n /**\n * Array field min rows\n */\n min?: number\n\n /**\n * Array field max rows\n */\n max?: number\n\n [key: string]: any\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","// export { createZodStepForm } from './create-zod-step-form'\nimport { createZodForm } from './create-zod-form'\n\nexport {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\n\n// import { createZodStepForm } from './create-zod-step-form'\n\nexport const Form = createZodForm()\n\n// export const StepForm = createZodStepForm()\n"],"mappings":";;;AAAA;AAAA,EACE;AAAA,OAKK;;;ACLP,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAWpB,IAAM,UAAU,CACd,UAC+D;AAC/D,MAAI,CAAC,cAAc,aAAa,EAAE,SAAS,MAAM,KAAK,QAAQ,GAAG;AAC/D,WAAO,QAAQ,MAAM,KAAK,SAAS;AAAA,EACrC;AAEA,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AAtCrD;AAuCE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AAhD3E;AAiDE,QAAM,SAAuB,CAAC;AAE9B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E,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AAyCO,IAAM,UAAU,CAAC,SAAkB;AACxC,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEO,IAAM,eAAe,CAAC,SAAiB;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;;;ADvHO,IAAM,gBAAgB,CAI3B,YACG;AAMH,QAAM,UAAU,WAAW;AAAA,IACzB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,SAAO;AACT;;;AEjDO,IAAM,OAAO,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../zod/src/create-zod-form.ts","../../zod/src/zod-resolver.ts","../../zod/src/index.ts"],"sourcesContent":["import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n GetBaseField,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<\n FieldDefs,\n TGetBaseField extends GetBaseField = GetBaseField,\n> extends CreateFormProps<FieldDefs, TGetBaseField> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraFieldProps extends object = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod',\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object,\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext, ExtraFieldProps>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <\n FieldDefs,\n TGetBaseField extends GetBaseField<any> = GetBaseField<any>,\n>(\n options?: CreateZodFormProps<FieldDefs, TGetBaseField>\n) => {\n type ExtraFieldProps =\n TGetBaseField extends GetBaseField<infer ExtraFieldProps>\n ? ExtraFieldProps\n : object\n\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs, object, ExtraFieldProps>\n}\n","import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@saas-ui/core/utils'\n\n// import { FieldProps } from '@saas-ui/forms'\n\ntype FieldProps = any\n\nexport { zodResolver }\n\nexport type ExtraProps = {\n min?: number\n max?: number\n options?: { label: string; value: string }[]\n}\n\nconst getType = (\n field: z.ZodTypeAny,\n): 'array' | 'object' | 'number' | 'date' | 'select' | 'text' => {\n if (['ZodDefault', 'ZodOptional'].includes(field._def.typeName)) {\n return getType(field._def.innerType)\n }\n\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodNativeEnum':\n case 'ZodEnum':\n return 'select'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const def =\n field._def.typeName === 'ZodDefault'\n ? field._def.innerType._def\n : field._def\n\n const props: ExtraProps = {}\n if (def.typeName === 'ZodArray') {\n props.min = getArrayOption(field, 'minLength')\n props.max = getArrayOption(field, 'maxLength')\n } else if (def.typeName === 'ZodEnum') {\n props.options = def.values.map((value: string) => {\n return { label: value, value }\n })\n } else if (def.typeName === 'ZodNativeEnum') {\n props.options = Object.entries(def.values).map(([label, value]) => ({\n label,\n value: value as string,\n }))\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n help: meta?.help,\n placeholder: meta?.placeholder,\n defaultValue: field._def.defaultValue?.(),\n ...props,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n /**\n * The label of the field\n */\n label: string\n\n /**\n * The type of the field\n */\n type?: string\n\n /**\n * The placeholder of the field\n */\n placeholder?: string\n\n /**\n * The help text of the field\n */\n help?: string\n\n /**\n * Object field column count\n */\n columns?: number\n\n /**\n * Array field min rows\n */\n min?: number\n\n /**\n * Array field max rows\n */\n max?: number\n\n [key: string]: any\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","// export { createZodStepForm } from './create-zod-step-form'\nimport { createZodForm } from './create-zod-form'\n\nexport {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\n\n// import { createZodStepForm } from './create-zod-step-form'\n\nexport const Form = createZodForm()\n\n// export const StepForm = createZodStepForm()\n"],"mappings":";;;AAAA;AAAA,EACE;AAAA,OAKK;;;ACLP,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAcpB,IAAM,UAAU,CACd,UAC+D;AAC/D,MAAI,CAAC,cAAc,aAAa,EAAE,SAAS,MAAM,KAAK,QAAQ,GAAG;AAC/D,WAAO,QAAQ,MAAM,KAAK,SAAS;AAAA,EACrC;AAEA,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AAzCrD;AA0CE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AAnD3E;AAoDE,QAAM,SAAuB,CAAC;AAE9B,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,KAAK,aAAa,YAAY;AACvC,mBAAe,OAAO,KAAK,KAAK;AAAA,EAClC,WAAW,OAAO,KAAK,aAAa,aAAa;AAC/C,mBAAe,OAAO,KAAK,MAAM;AAAA,EACnC,OAAO;AACL,WAAO;AAAA,EACT;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,MACJ,MAAM,KAAK,aAAa,eACpB,MAAM,KAAK,UAAU,OACrB,MAAM;AAEZ,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AO;AAAA,EACT;AACF;;;AD1HO,IAAM,gBAAgB,CAI3B,YACG;AAMH,QAAM,UAAU,WAAW;AAAA,IACzB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,SAAO;AACT;;;AEjDO,IAAM,OAAO,cAAc;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saas-ui/forms",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "Fully functional forms for Chakra UI.",
5
5
  "source": "src/index.ts",
6
6
  "exports": {
@@ -102,8 +102,8 @@
102
102
  },
103
103
  "dependencies": {
104
104
  "@hookform/resolvers": "^3.9.1",
105
- "@saas-ui/core": "3.0.0-alpha.0",
106
- "@saas-ui/react": "3.0.0-alpha.0",
105
+ "@saas-ui/core": "3.0.0-alpha.1",
106
+ "@saas-ui/react": "3.0.0-alpha.1",
107
107
  "react-hook-form": "^7.53.2"
108
108
  },
109
109
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, useMemo } from 'react'
2
2
 
3
- import { runIfFn } from '@chakra-ui/utils'
4
3
  import { StepperProvider } from '@saas-ui/core'
4
+ import { runIfFn } from '@saas-ui/core/utils'
5
5
 
6
6
  import {
7
7
  ArrayField,
package/src/step-form.tsx CHANGED
@@ -7,8 +7,8 @@ import {
7
7
  type StepsChangeDetails,
8
8
  chakra,
9
9
  } from '@chakra-ui/react'
10
- import { callAllHandlers, cx } from '@chakra-ui/utils'
11
10
  import { useStepperContext } from '@saas-ui/core'
11
+ import { callAll, cx } from '@saas-ui/core/utils'
12
12
  import { Steps } from '@saas-ui/react/steps'
13
13
  import { FieldValues } from 'react-hook-form'
14
14
 
@@ -156,7 +156,7 @@ export const PrevButton: React.FC<ButtonProps> = (props) => {
156
156
  children="Back"
157
157
  {...props}
158
158
  className={cx('sui-form__prev-button', props.className)}
159
- onClick={callAllHandlers(props.onClick, prevStep)}
159
+ onClick={callAll(props.onClick, prevStep)}
160
160
  />
161
161
  )
162
162
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MaybeRenderProp } from '@chakra-ui/utils'
1
+ import type { MaybeRenderProp } from '@saas-ui/core/utils'
2
2
  import type { FieldPath, FieldValues, RegisterOptions } from 'react-hook-form'
3
3
 
4
4
  import type { ArrayFieldProps } from './array-field'
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react'
2
2
 
3
- import { createContext } from '@chakra-ui/utils'
4
- import { FocusableElement } from '@chakra-ui/utils'
3
+ import { createContext } from '@chakra-ui/react'
5
4
  import {
6
5
  type UseStepperProps,
7
6
  type UseStepperReturn,
@@ -15,7 +14,7 @@ import { DisplayIfProps } from './display-if'
15
14
  import { FormProps } from './form'
16
15
  import { ObjectFieldProps } from './object-field'
17
16
  import { FormStepProps, StepsOptions } from './step-form'
18
- import { FieldProps, StepFormChildren } from './types'
17
+ import { FieldProps, type FocusableElement, StepFormChildren } from './types'
19
18
  import { UseArrayFieldReturn } from './use-array-field'
20
19
 
21
20
  export interface StepState {