zod-auto-form
Version:
Auto-generate typed React forms from Zod schemas
1 lines • 53.7 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../package/@auto-form.react-zod/context/useComponentContext.tsx","../package/@auto-form.react-zod/base-components/GroupedFieldsWrapper.tsx","../package/@auto-form.react-zod/base-components/ArrayField.tsx","../package/@auto-form.react-zod/base-components/ArrayInputFieldWrapper.tsx","../package/@auto-form.react-zod/context/useAppFormHook.ts","../package/@auto-form.react-zod/base-components/GenericFormField.tsx","../package/@auto-form.react-zod/base-components/ObjectWrapper.tsx","../package/@auto-form.react-zod/base-components/ArrayWrapper.tsx","../package/@auto-form.react-zod/core/utils.ts","../package/@auto-form.react-zod/form/hooks/useFromData.tsx","../package/@auto-form.react-zod/form/utils/componentKeyMapper.ts","../package/@auto-form.react-zod/form/renderField.tsx","../package/@auto-form.react-zod/form/Index.tsx","../package/@auto-form.react-zod/utils/ComponentRegistry.tsx"],"sourcesContent":["/* eslint-disable react-refresh/only-export-components */\r\nimport { type ReactNode, createContext, useContext } from \"react\";\r\n\r\nimport type { ComponentContextType } from \"../types/base-components\";\r\n\r\nconst defaultComponents: ComponentContextType = {\r\n\tInput: () => null,\r\n\tSelect: () => null,\r\n\tMultiSelect: () => null,\r\n\tRadioGroup: () => null,\r\n\tNumberInput: () => null,\r\n\tCheckbox: () => null,\r\n\tSwitch: () => null,\r\n\tTextArea: () => null,\r\n\tDateTimePicker: () => null,\r\n\tObjectWrapper: () => null,\r\n\tArrayWrapper: () => null,\r\n\tForm: () => null,\r\n\tSubmitButton: () => null,\r\n\tGroupedFieldsWrapper: () => null,\r\n\tArrayInputFieldWrapper: () => null,\r\n\tarrayString: () => null,\r\n\tarrayNumber: () => null,\r\n\tarrayBoolean: () => null,\r\n\tarrayDate: () => null,\r\n};\r\nconst ComponentContext = createContext<ComponentContextType>(defaultComponents);\r\n\r\nexport const useComponentContext = () => useContext(ComponentContext);\r\n\r\ntype ComponentProviderProps = {\r\n\tchildren: ReactNode;\r\n\tcomponents?: Partial<ComponentContextType>;\r\n};\r\n\r\nexport const AutoFormComponentsProvider = ({\r\n\tchildren,\r\n\tcomponents,\r\n}: ComponentProviderProps) => {\r\n\tconst value = {\r\n\t\t...defaultComponents,\r\n\t\t...components,\r\n\t};\r\n\r\n\treturn (\r\n\t\t<ComponentContext.Provider value={value}>\r\n\t\t\t{children}\r\n\t\t</ComponentContext.Provider>\r\n\t);\r\n};\r\n","import { useComponentContext } from \"../context/useComponentContext\";\r\nimport type { GroupedFieldsWrapperType } from \"../types/base-components\";\r\n\r\nexport default function GroupedFieldsWrapper({\r\n\tchildren,\r\n\tgroupName,\r\n}: GroupedFieldsWrapperType) {\r\n\tconst { GroupedFieldsWrapper: GroupedFieldsComponent } =\r\n\t\tuseComponentContext();\r\n\treturn (\r\n\t\t<GroupedFieldsComponent groupName={groupName}>\r\n\t\t\t{children}\r\n\t\t</GroupedFieldsComponent>\r\n\t);\r\n}\r\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { useEffect, useRef, useState } from \"react\";\nimport { useFieldContext } from \"../context/useAppFormHook\";\nimport type { ArrayFieldItem } from \"../types/array-field-types\";\nimport type { ArrayFieldComponentProps } from \"../types/array-field-types\";\n\n// Helper to generate a unique key\nconst generateRandomKey = () => {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n};\n\ntype SchemaField = {\n name: string;\n type: string;\n fields?: SchemaField[]; // for nested objects, if any\n};\n\nfunction generateEmptyData(fields: SchemaField[]): Record<string, any> {\n const data: Record<string, any> = {};\n console.log(fields, \"fields\");\n console.log(data, \"data\");\n\n for (const field of fields) {\n console.log(field, \"field\");\n switch (field.type) {\n case \"string\":\n // @ts-ignore\n data[field.name] = field.defaultValue || \"\";\n break;\n case \"boolean\":\n // @ts-ignore\n data[field.name] = field.defaultValue || false;\n break;\n case \"number\":\n // @ts-ignore\n data[field.name] = Number(field.defaultValue ?? 0) || 0;\n break;\n case \"object\":\n // @ts-ignore\n data[field.name] = generateEmptyData(field.fields || []);\n break;\n case \"array\":\n // @ts-ignore\n data[field.name] = field.defaultValue || [];\n break;\n default:\n console.log(field, \"default of unknown\");\n // @ts-ignore\n data[field.name] = field.defaultValue || null;\n }\n }\n console.log(data, \"datafinal\");\n\n return data;\n}\n\nexport function ArrayFieldForArrayOfStrings({\n children,\n}: ArrayFieldComponentProps) {\n const field = useFieldContext<unknown[]>();\n const [fields, setFields] = useState<ArrayFieldItem[]>([]);\n\n // Hydrate fields with keys and wrap primitives\n useEffect(() => {\n if (Array.isArray(field.state.value)) {\n const mapped = field.state.value.map((value) => {\n if (\n typeof value === \"object\" &&\n value !== null &&\n !(value instanceof Date)\n ) {\n // For objects (excluding Date)\n return {\n j1sjhghgtytfjiu971: generateRandomKey(),\n ...value,\n };\n }\n // For primitives or Date\n return {\n j1sjhghgtytfjiu971: generateRandomKey(),\n value,\n };\n });\n setFields(mapped);\n }\n }, [field.state.value]);\n\n // Append new item (supports all primitive + object + Date)\n const append = (value: unknown) => {\n const newItem =\n typeof value === \"object\" && value !== null && !(value instanceof Date)\n ? { j1sjhghgtytfjiu971: generateRandomKey(), ...value }\n : { j1sjhghgtytfjiu971: generateRandomKey(), value };\n\n const newFields = [...fields, newItem];\n setFields(newFields);\n field.handleChange(\n newFields.map((item) => (\"value\" in item ? item.value : item))\n );\n };\n\n // Remove by index\n const remove = (index: number) => {\n const newFields = [...fields];\n newFields.splice(index, 1);\n setFields(newFields);\n field.handleChange(\n newFields.map((item) => (\"value\" in item ? item.value : item))\n );\n };\n\n return children({ fields, append, remove });\n}\n\nexport function ArrayFieldForArrayOfObjects({\n children,\n}: ArrayFieldComponentProps) {\n const field = useFieldContext<unknown[]>();\n const [fields, setFields] = useState<ArrayFieldItem[]>([]);\n const previousValuesRef = useRef<unknown[]>([]);\n const fieldsRef = useRef<ArrayFieldItem[]>([]);\n\n // Keep fieldsRef in sync with fields\n useEffect(() => {\n fieldsRef.current = fields;\n }, [fields]);\n\n // Sync form values with local state whenever they change\n // biome-ignore lint/correctness/useExhaustiveDependencies: Intentionally omitting some dependencies to prevent infinite loops\n useEffect(() => {\n const newValue = field.state.value;\n if (!Array.isArray(newValue)) return;\n\n // Only update if the values have actually changed\n if (\n JSON.stringify(newValue) === JSON.stringify(previousValuesRef.current)\n ) {\n return;\n }\n\n // Always update fields to ensure complete synchronization\n const newFields = newValue.map((val, index) => {\n // Try to preserve existing keys to avoid re-renders\n const prev = fieldsRef.current[index];\n const key = prev?.j1sjhghgtytfjiu971 || generateRandomKey();\n\n if (typeof val === \"object\" && val !== null && !(val instanceof Date)) {\n return {\n j1sjhghgtytfjiu971: key,\n ...val,\n };\n }\n\n return {\n j1sjhghgtytfjiu971: key,\n value: val,\n };\n });\n\n setFields(newFields);\n previousValuesRef.current = newValue;\n }, [field.state.value]);\n\n const append = (valueX: any) => {\n const value = generateEmptyData(valueX);\n const newItem =\n typeof value === \"object\" && value !== null && !(value instanceof Date)\n ? { j1sjhghgtytfjiu971: generateRandomKey(), ...value }\n : { j1sjhghgtytfjiu971: generateRandomKey(), value };\n\n const newFields = [...fields, newItem];\n setFields(newFields);\n const updatedValues = newFields.map((item) =>\n \"value\" in item ? item.value : item\n );\n field.handleChange(updatedValues);\n previousValuesRef.current = updatedValues;\n };\n\n const remove = (index: number) => {\n const newFields = [...fields];\n newFields.splice(index, 1);\n setFields(newFields);\n const updatedValues = newFields.map((item) =>\n \"value\" in item ? item.value : item\n );\n field.handleChange(updatedValues);\n previousValuesRef.current = updatedValues;\n };\n\n return children({ fields, append, remove });\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\n/* eslint-disable @typescript-eslint/ban-ts-comment */\r\nimport { useEffect, useState } from \"react\";\r\nimport { useFieldContext } from \"../context/useAppFormHook\";\r\nimport { useComponentContext } from \"../context/useComponentContext\";\r\nimport type { ArrayFieldItem } from \"../types/array-field-types\";\r\nimport type { InternalArrayFieldComponents } from \"../types/internal-components\";\r\n\r\n// Type of values we support\r\ntype SupportedValue = string | number | boolean | Date;\r\n// You can pass in this function or put it inside your component file\r\nfunction getArrayFieldError(\r\n\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\r\n\tformErrors: Record<string, any>[] | undefined,\r\n\tfieldName: string,\r\n\tindex: number,\r\n): string | undefined {\r\n\tif (!Array.isArray(formErrors)) return;\r\n\r\n\tconst fullKey = `${fieldName}[${index}]`;\r\n\r\n\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\r\n\tconst findErrorDeep = (errors: any): string | undefined => {\r\n\t\tif (typeof errors !== \"object\" || errors === null) return;\r\n\r\n\t\tfor (const key in errors) {\r\n\t\t\tif (key === fullKey) {\r\n\t\t\t\tconst val = errors[key];\r\n\t\t\t\tif (Array.isArray(val) && val[0]?.message) {\r\n\t\t\t\t\treturn val[0].message;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// 🔍 Recursively go deeper\r\n\t\t\tconst nested = errors[key];\r\n\t\t\tconst result = findErrorDeep(nested);\r\n\t\t\tif (result) return result;\r\n\t\t}\r\n\r\n\t\treturn;\r\n\t};\r\n\r\n\tfor (const errorObj of formErrors) {\r\n\t\tconst error = findErrorDeep(errorObj);\r\n\t\tif (error) return error;\r\n\t}\r\n\r\n\treturn undefined;\r\n}\r\n\r\nexport default function ArrayInputFieldWrapper({\r\n\tlabel,\r\n\ttitle,\r\n\tdescription,\r\n\tonAddField,\r\n\tonRemoveField,\r\n\tdisabled,\r\n\tplaceholder,\r\n\tfields,\r\n\tcomponentKey,\r\n\tall_errors,\r\n\tpath,\r\n}: InternalArrayFieldComponents) {\r\n\tconst context = useFieldContext<SupportedValue[]>();\r\n\tconst [values, setValues] = useState<SupportedValue[]>([]);\r\n\tconst [touchedFields, setTouchedFields] = useState<Record<number, boolean>>(\r\n\t\t{},\r\n\t);\r\n\r\n\t// Sync form values with local state\r\n\tuseEffect(() => {\r\n\t\tif (Array.isArray(context.state.value)) {\r\n\t\t\tsetValues(context.state.value);\r\n\t\t}\r\n\t}, [context.state.value]);\r\n\r\n\tconst { ArrayInputFieldWrapper: WrapperComponent, ...components } =\r\n\t\tuseComponentContext();\r\n\t// @ts-ignore\r\n\tconst Component = components[componentKey] as React.FC<{\r\n\t\tid?: string;\r\n\t\tvalue: SupportedValue;\r\n\t\tonChange: (value: SupportedValue) => void;\r\n\t\tonBlur: () => void;\r\n\t\tlabel?: string;\r\n\t\ttitle?: string;\r\n\t\tdescription?: string;\r\n\t\tdisabled?: boolean;\r\n\t\tplaceholder?: string;\r\n\t\terrorMessages?: string[];\r\n\t\tisError?: boolean;\r\n\t}>;\r\n\r\n\tconst handleChange = (index: number, value: SupportedValue) => {\r\n\t\tconst updated = [...values];\r\n\t\tupdated[index] = value;\r\n\t\tsetValues(updated);\r\n\t\tcontext.handleChange(updated);\r\n\t};\r\n\r\n\tconst getFieldValue = (\r\n\t\tfield: ArrayFieldItem,\r\n\t\tindex: number,\r\n\t\tvalues: SupportedValue[],\r\n\t): SupportedValue => {\r\n\t\tlet val: SupportedValue | undefined = undefined;\r\n\r\n\t\tif (field?.value !== undefined) {\r\n\t\t\tval = field.value as SupportedValue;\r\n\t\t} else {\r\n\t\t\tval = values[index];\r\n\t\t}\r\n\r\n\t\t// Convert Date to ISO format for input compatibility\r\n\t\tif (val instanceof Date) {\r\n\t\t\treturn val;\r\n\t\t}\r\n\r\n\t\treturn val !== undefined ? val : \"\";\r\n\t};\r\n\tuseEffect(() => {\r\n\t\t// When form is re-validated (on submit), clear touched state\r\n\t\tif (all_errors?.form?.errors) {\r\n\t\t\tsetTouchedFields({});\r\n\t\t}\r\n\t}, [all_errors?.form?.errors]);\r\n\r\n\treturn (\r\n\t\t<WrapperComponent\r\n\t\t\tonAddField={onAddField}\r\n\t\t\tonRemoveField={onRemoveField}\r\n\t\t\tdescription={description}\r\n\t\t\tlabel={label}\r\n\t\t\ttitle={title}\r\n\t\t>\r\n\t\t\t{fields.map((field, index) => {\r\n\t\t\t\tconst currentError = getArrayFieldError(\r\n\t\t\t\t\tall_errors?.form?.errors,\r\n\t\t\t\t\tpath ?? \"\",\r\n\t\t\t\t\tindex,\r\n\t\t\t\t);\r\n\t\t\t\tconst shouldShowError = currentError && !touchedFields[index];\r\n\r\n\t\t\t\treturn (\r\n\t\t\t\t\t<Component\r\n\t\t\t\t\t\tid={field.id as string}\r\n\t\t\t\t\t\t// @ts-ignore\r\n\t\t\t\t\t\tkey={field.id ?? index}\r\n\t\t\t\t\t\tvalue={getFieldValue(field, index, values)}\r\n\t\t\t\t\t\tonChange={(value) => {\r\n\t\t\t\t\t\t\thandleChange(index, value);\r\n\t\t\t\t\t\t\tsetTouchedFields((prev) => ({ ...prev, [index]: true }));\r\n\t\t\t\t\t\t}}\r\n\t\t\t\t\t\tonBlur={() => {\r\n\t\t\t\t\t\t\tcontext.handleChange(values);\r\n\t\t\t\t\t\t}}\r\n\t\t\t\t\t\t// @ts-ignore\r\n\t\t\t\t\t\terrorMessages={\r\n\t\t\t\t\t\t\tshouldShowError\r\n\t\t\t\t\t\t\t\t? [\r\n\t\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t\tmessage:\r\n\t\t\t\t\t\t\t\t\t\t\t\tgetArrayFieldError(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tall_errors?.form?.errors,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tpath ?? \"\",\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tindex,\r\n\t\t\t\t\t\t\t\t\t\t\t\t) || \"\",\r\n\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t]\r\n\t\t\t\t\t\t\t\t: []\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tisError={!!shouldShowError}\r\n\t\t\t\t\t\tlabel={label}\r\n\t\t\t\t\t\ttitle={title}\r\n\t\t\t\t\t\tdescription={description}\r\n\t\t\t\t\t\tdisabled={disabled}\r\n\t\t\t\t\t\tplaceholder={placeholder}\r\n\t\t\t\t\t/>\r\n\t\t\t\t);\r\n\t\t\t})}\r\n\t\t</WrapperComponent>\r\n\t);\r\n}\r\n","import { createFormHook, createFormHookContexts } from \"@tanstack/react-form\";\nimport {\n\tArrayFieldForArrayOfObjects,\n\tArrayFieldForArrayOfStrings,\n} from \"../base-components/ArrayField\";\nimport ArrayInputFieldWrapper from \"../base-components/ArrayInputFieldWrapper\";\nimport ArrayWrapper from \"../base-components/ArrayWrapper\";\nimport GenericFormField from \"../base-components/GenericFormField\";\nimport GroupedFieldsWrapper from \"../base-components/GroupedFieldsWrapper\";\nimport ObjectWrapper from \"../base-components/ObjectWrapper\";\nexport const { fieldContext, formContext, useFieldContext, useFormContext } =\n\tcreateFormHookContexts();\nconst FieldComponents = {\n\tFieldComponent: GenericFormField, // can provide a in value\n\tArrayField: ArrayFieldForArrayOfObjects, // can provide a in array value\n\tArrayFieldForArrayOfStrings: ArrayFieldForArrayOfStrings, // can provide a in array value\n\tObjectWrapper: ObjectWrapper,\n\tArrayWrapper: ArrayWrapper,\n\tGroupedFieldsWrapper: GroupedFieldsWrapper,\n\tArrayInputFieldWrapper: ArrayInputFieldWrapper,\n};\n\n// Exported from your own library with pre-bound components for your forms.\nexport const { useAppForm, withForm } = createFormHook({\n\tfieldComponents: FieldComponents,\n\tformComponents: {},\n\tfieldContext,\n\tformContext,\n});\n\nexport type FormFieldKeys = keyof typeof FieldComponents;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\n// components/GenericFormField.tsx\r\n\r\nimport { useFieldContext } from \"../context/useAppFormHook\";\r\nimport { useComponentContext } from \"../context/useComponentContext\";\r\nimport type { ComponentContextType } from \"../types/base-components\";\r\nimport type { InternalFieldComponents } from \"../types/internal-components\";\r\n\r\ninterface GenericFormFieldProps extends InternalFieldComponents {\r\n\tcomponentKey: keyof ComponentContextType;\r\n}\r\n\r\nexport default function GenericFormField({\r\n\tcomponentKey,\r\n\t...rest\r\n}: GenericFormFieldProps) {\r\n\tconst field = useFieldContext();\r\n\tconst components = useComponentContext();\r\n\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\r\n\tconst Component = components[componentKey] as any;\r\n\tconst isError =\r\n\t\tfield.state.meta.isTouched && field.state.meta.errors.length > 0;\r\n\treturn (\r\n\t\t<Component\r\n\t\t\tid={field.name}\r\n\t\t\tonChange={field.handleChange}\r\n\t\t\tvalue={field.state.value}\r\n\t\t\terrorMessages={field.state.meta.errors}\r\n\t\t\tisError={isError}\r\n\t\t\tonBlur={field.handleBlur}\r\n\t\t\t{...rest}\r\n\t\t/>\r\n\t);\r\n}\r\n","import { useComponentContext } from \"../context/useComponentContext\";\r\nimport type { ObjectWrapperType } from \"../types/base-components\";\r\n\r\nexport default function ObjectWrapper({\r\n\tchildren,\r\n\ttitle,\r\n\tdescription,\r\n\tlabel,\r\n\trequired,\r\n}: ObjectWrapperType) {\r\n\tconst { ObjectWrapper: ObjectWrapperComponent } = useComponentContext();\r\n\treturn (\r\n\t\t<ObjectWrapperComponent\r\n\t\t\ttitle={title}\r\n\t\t\tdescription={description}\r\n\t\t\tlabel={label}\r\n\t\t\trequired={required}\r\n\t\t>\r\n\t\t\t{children}\r\n\t\t</ObjectWrapperComponent>\r\n\t);\r\n}\r\n","import { useComponentContext } from \"../context/useComponentContext\";\r\nimport type { ArrayWrapperType } from \"../types/base-components\";\r\n\r\nexport default function ArrayWrapper({\r\n\tchildren,\r\n\tlabel,\r\n\ttitle,\r\n\tdescription,\r\n\tonAddField,\r\n\tonRemoveField,\r\n}: ArrayWrapperType) {\r\n\tconst { ArrayWrapper: ArrayWrapperComponent } = useComponentContext();\r\n\treturn (\r\n\t\t<ArrayWrapperComponent\r\n\t\t\tlabel={label}\r\n\t\t\ttitle={title}\r\n\t\t\tdescription={description}\r\n\t\t\tonAddField={onAddField}\r\n\t\t\tonRemoveField={onRemoveField}\r\n\t\t>\r\n\t\t\t{children}\r\n\t\t</ArrayWrapperComponent>\r\n\t);\r\n}\r\n","import type { z } from \"zod\";\nimport type { FieldVisibilityRule } from \"../types/visibility-rules\";\n\n// Helper function to get nested value from object using path\nconst getNestedValue = (\n\tobj: Record<string, unknown>,\n\tpath: string | string[],\n): unknown => {\n\t// Handle array path format: convert \"items[0].name\" or \"items.[0].name\" to [\"items\", \"0\", \"name\"]\n\tconst pathArray = Array.isArray(path)\n\t\t? path\n\t\t: path\n\t\t\t\t.replace(/\\.\\[/g, \"[\") // First normalize \".[\" to \"[\"\n\t\t\t\t.replace(/\\[(\\d+)\\]/g, \".$1\") // Then convert \"[0]\" to \".0\"\n\t\t\t\t.split(\".\")\n\t\t\t\t.filter(Boolean);\n\n\treturn pathArray.reduce<unknown>((acc, key) => {\n\t\tif (acc === undefined || acc === null) return undefined;\n\n\t\tif (typeof acc === \"object\") {\n\t\t\t// Handle both array and object cases\n\t\t\tif (Array.isArray(acc)) {\n\t\t\t\tconst index = Number(key);\n\t\t\t\tif (Number.isInteger(index) && index >= 0 && index < acc.length) {\n\t\t\t\t\treturn acc[index];\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// Handle object case\n\t\t\tif (key in acc) {\n\t\t\t\treturn (acc as Record<string, unknown>)[key];\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}, obj);\n};\n\n// Helper function to check if field should be visible/disabled\nconst shouldApplyRule = <T extends z.ZodSchema>(\n\trule: FieldVisibilityRule<T>,\n\tformValues: Record<string, unknown>,\n): boolean => {\n\tconst sourceValues = rule.sourceFields.map((field) =>\n\t\tgetNestedValue(formValues, field),\n\t);\n\tconst values = Object.fromEntries(\n\t\trule.sourceFields.map((field: string | string[], index: number) => [\n\t\t\tArray.isArray(field) ? field.join(\".\") : field,\n\t\t\tsourceValues[index],\n\t\t]),\n\t);\n\treturn rule.when(values as Record<string, unknown>);\n};\n\n// Helper function to clean path for comparison\nconst cleanPath = (path: string): string => {\n\t// First handle array notation with dots (e.g., \"address.[0].street\")\n\tconst normalizedPath = path.replace(/\\.\\[/g, \"[\");\n\t// Then standardize all array notations to dot notation\n\treturn normalizedPath.replace(/\\[(\\d+)\\]/g, \".$1\");\n};\n\n// Helper function to merge default values\nconst mergeDefaultValues = (\n\tuserDefaults: Record<string, unknown>,\n\tzodDefaults: Record<string, unknown>,\n): Record<string, unknown> => {\n\tconst merged = { ...zodDefaults };\n\n\tfor (const [key, value] of Object.entries(userDefaults)) {\n\t\tif (\n\t\t\tvalue &&\n\t\t\ttypeof value === \"object\" &&\n\t\t\t!Array.isArray(value) &&\n\t\t\tmerged[key] &&\n\t\t\ttypeof merged[key] === \"object\" &&\n\t\t\t!Array.isArray(merged[key])\n\t\t) {\n\t\t\tmerged[key] = mergeDefaultValues(\n\t\t\t\tvalue as Record<string, unknown>,\n\t\t\t\tmerged[key] as Record<string, unknown>,\n\t\t\t);\n\t\t} else {\n\t\t\tmerged[key] = value;\n\t\t}\n\t}\n\n\treturn merged;\n};\n\n// Helper function to recursively remove null values from objects and arrays\nfunction removeNullValues<T>(obj: T): T {\n\tif (Array.isArray(obj)) {\n\t\treturn obj\n\t\t\t.map((item) => removeNullValues(item))\n\t\t\t.filter((item) => item !== null) as unknown as T;\n\t}\n\tif (obj !== null && typeof obj === \"object\") {\n\t\treturn Object.entries(obj)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.reduce((acc, [key, value]) => {\n\t\t\t\t(acc as Record<string, unknown>)[key] = removeNullValues(value);\n\t\t\t\treturn acc;\n\t\t\t}, Array.isArray(obj) ? [] : {}) as T;\n\t}\n\treturn obj;\n}\n\nexport { cleanPath, getNestedValue, mergeDefaultValues, shouldApplyRule, removeNullValues };\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { z } from \"zod\";\nimport { ZodFormClassed, extractZodErrorMessages } from \"zod-helper\";\nimport { useAppForm } from \"../../context/useAppFormHook\";\nimport {\n\tcleanPath,\n\tmergeDefaultValues,\n\tshouldApplyRule,\n\tremoveNullValues,\n} from \"../../core/utils\";\nimport type {\n\tAutoFormProps,\n\tFieldOverrideType,\n\tZodSchema,\n} from \"../../types/auto-form-type\";\nimport type { ZodErrorItem } from \"../../types/zod-types\";\n\ntype VisibilityState = {\n\thidden: boolean;\n\tdisabled: boolean;\n};\nconst AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;\n\nfunction isAsync(fn: unknown): boolean {\n\treturn fn instanceof AsyncFunction;\n}\n\nexport default function useFormData<T extends ZodSchema>({\n\tschema,\n\tchangePositionOfFields,\n\tfieldTypeOverrides,\n\tgroupByZodKeys,\n\tvisibilityRules,\n\tdefaultValues,\n\tonSubmit,\n\tonSubmitError,\n\tonValuesChange,\n\tisRemoveNullValues,\n}: AutoFormProps<T> & { onValuesChange?: (values: Record<string, unknown>) => void }) {\n\tconst [formVersion, setFormVersion] = useState(0);\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst formSubmittedRef = useRef(false);\n\n\t// Memoized ZodFormClassed instance with all transformations applied\n\tconst zodFormData = useMemo(() => {\n\t\tconst formData = new ZodFormClassed(schema);\n\n\t\tif (changePositionOfFields) {\n\t\t\tformData.changeJsonFieldPositions(changePositionOfFields);\n\t\t}\n\n\t\tif (fieldTypeOverrides) {\n\t\t\tformData.overrideFieldTypes(\n\t\t\t\t// @ts-ignore\n\t\t\t\tfieldTypeOverrides as Record<string, FieldOverrideType>,\n\t\t\t);\n\t\t}\n\n\t\tif (groupByZodKeys) {\n\t\t\tformData.groupByZodKeys(groupByZodKeys);\n\t\t}\n\n\t\treturn formData;\n\t}, [schema, fieldTypeOverrides, changePositionOfFields, groupByZodKeys]);\n\n\tconst mergedDefaultValues = useMemo(\n\t\t() =>\n\t\t\tmergeDefaultValues(\n\t\t\t\tdefaultValues || {},\n\t\t\t\tzodFormData.getZodDefaultValues() || {},\n\t\t\t),\n\t\t[defaultValues, zodFormData]\n\t);\n\n\t// Handle form submission with proper error handling\n\tconst handleSubmit = useCallback(\n\t\t(props: { value: unknown }) => {\n\t\t\tsetIsLoading(true);\n\t\t\ttry {\n\t\t\t\tif (!onSubmit) {\n\t\t\t\t\tthrow new Error(\"onSubmit is required\");\n\t\t\t\t}\n\t\t\t\tformSubmittedRef.current = true;\n\t\t\t\tlet dataToParse = props.value;\n\t\t\t\tif (isRemoveNullValues) {\n\t\t\t\t\tdataToParse = removeNullValues(dataToParse);\n\t\t\t\t}\n\t\t\t\tconst parsedData = schema.parse(dataToParse);\n\t\t\t\t// onSubmit?.(parsedData);\n\t\t\t\tif (isAsync(onSubmit)) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tonSubmit(parsedData)\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t.then(() => {\n\t\t\t\t\t\t\tsetIsLoading(false);\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n\t\t\t\t\t\t.catch((error: any) => {\n\t\t\t\t\t\t\tconsole.error(\"Unexpected error during form submission:\", error);\n\t\t\t\t\t\t\tsetIsLoading(false);\n\t\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tonSubmit?.(parsedData);\n\t\t\t\t\tsetIsLoading(false);\n\t\t\t\t}\n\t\t\t\treturn parsedData;\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\tonSubmitError?.(\n\t\t\t\t\t\terror,\n\t\t\t\t\t\textractZodErrorMessages(error.errors as unknown as ZodErrorItem[]),\n\t\t\t\t\t\tprops.value as z.infer<T>,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error(\"Unexpected error during form submission:\", error);\n\t\t\t\t}\n\t\t\t\tsetIsLoading(false);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\t[schema, onSubmit, onSubmitError, isRemoveNullValues],\n\t);\n\n\t// Initialize form with app context\n\tconst appForm = useAppForm({\n\t\tdefaultState: {\n\t\t\tvalues: mergedDefaultValues,\n\t\t},\n\t\tonSubmit: handleSubmit,\n\t\tonSubmitInvalid: (props) => {\n\t\t\tonSubmitError?.(\n\t\t\t\tprops.formApi.state.errors as unknown as z.ZodError,\n\t\t\t\textractZodErrorMessages(\n\t\t\t\t\tprops.formApi.state.errors as unknown as ZodErrorItem[],\n\t\t\t\t),\n\t\t\t\tprops.value as z.infer<T>,\n\t\t\t);\n\t\t},\n\t\tvalidators: {\n\t\t\tonSubmit: schema,\n\t\t\tonChange: (props) => {\n\t\t\t\tif (visibilityRules?.length) {\n\t\t\t\t\tsetFormVersion((prev) => prev + 1);\n\t\t\t\t}\n\t\t\t\tif (onValuesChange) {\n\t\t\t\t\tonValuesChange(props.value);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\n\t// Memoized visibility state calculator\n\tconst getFieldVisibilityState = useCallback(\n\t\t(\n\t\t\tfieldPath: string,\n\t\t\tformValues: Record<string, unknown>,\n\t\t): VisibilityState => {\n\t\t\tif (!visibilityRules?.length) {\n\t\t\t\treturn { hidden: false, disabled: false };\n\t\t\t}\n\n\t\t\tconst applicableRules = visibilityRules.filter((rule) => {\n\t\t\t\tif (Array.isArray(rule.targetField)) {\n\t\t\t\t\treturn rule.targetField.some(targetField => \n\t\t\t\t\t\tcleanPath(targetField) === cleanPath(fieldPath)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn cleanPath(rule.targetField) === cleanPath(fieldPath);\n\t\t\t});\n\n\t\t\tif (!applicableRules.length) {\n\t\t\t\treturn { hidden: false, disabled: false };\n\t\t\t}\n\n\t\t\tconst hidden = applicableRules.some(\n\t\t\t\t(rule) => rule.type === \"hide\" && shouldApplyRule(rule, formValues),\n\t\t\t);\n\n\t\t\tconst disabled = applicableRules.some(\n\t\t\t\t(rule) => rule.type === \"disable\" && shouldApplyRule(rule, formValues),\n\t\t\t);\n\n\t\t\tconst shown = applicableRules.some(\n\t\t\t\t(rule) => rule.type === \"show\" && shouldApplyRule(rule, formValues),\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\thidden:\n\t\t\t\t\thidden ||\n\t\t\t\t\t(!shown && applicableRules.some((rule) => rule.type === \"show\")),\n\t\t\t\tdisabled,\n\t\t\t};\n\t\t},\n\t\t[visibilityRules],\n\t);\n\n\treturn {\n\t\tzodFormData,\n\t\tformVersion,\n\t\tsetFormVersion,\n\t\tmergedDefaultValues,\n\t\tformSubmittedRef,\n\t\thandleSubmit,\n\t\tappForm,\n\t\tgetFieldVisibilityState,\n\t\tisLoading,\n\t\tall_errors: appForm.getAllErrors(),\n\t};\n}\n","import type { ComponentContextTypeKeys } from \"../../types/base-components\";\r\n\r\nexport type SupportedFieldType =\r\n\t| \"string\"\r\n\t| \"number\"\r\n\t| \"boolean\"\r\n\t| \"array\"\r\n\t| \"object\"\r\n\t| \"select\"\r\n\t| \"multi-select\"\r\n\t| \"date\"\r\n\t| \"textarea\"\r\n\t| \"switch\"\r\n\t| \"radio\"\r\n\t| \"array-string\"\r\n\t| \"array-number\"\r\n\t| \"array-boolean\"\r\n\t| \"array-date\";\r\n\r\nexport function getComponentKey(\r\n\ttype: SupportedFieldType,\r\n): ComponentContextTypeKeys {\r\n\tswitch (type) {\r\n\t\tcase \"string\":\r\n\t\t\treturn \"Input\";\r\n\t\tcase \"number\":\r\n\t\t\treturn \"NumberInput\";\r\n\t\tcase \"boolean\":\r\n\t\t\treturn \"Checkbox\";\r\n\t\tcase \"select\":\r\n\t\t\treturn \"Select\";\r\n\t\tcase \"multi-select\":\r\n\t\t\treturn \"MultiSelect\";\r\n\t\tcase \"date\":\r\n\t\t\treturn \"DateTimePicker\";\r\n\t\tcase \"textarea\":\r\n\t\t\treturn \"TextArea\";\r\n\t\tcase \"switch\":\r\n\t\t\treturn \"Switch\";\r\n\t\tcase \"radio\":\r\n\t\t\treturn \"RadioGroup\";\r\n\t\tcase \"array-string\":\r\n\t\t\treturn \"arrayString\";\r\n\t\tcase \"array-number\":\r\n\t\t\treturn \"arrayNumber\";\r\n\t\tcase \"array-boolean\":\r\n\t\t\treturn \"arrayBoolean\";\r\n\t\tcase \"array-date\":\r\n\t\t\treturn \"arrayDate\";\r\n\t\tdefault:\r\n\t\t\treturn \"Input\";\r\n\t}\r\n}\r\n","\"use client\";\nimport React from \"react\";\nimport type { BaseField } from \"../types/auto-form-type\";\nimport type { InternalFieldComponents } from \"../types/internal-components\";\nimport type useFormData from \"./hooks/useFromData\";\nimport { getComponentKey } from \"./utils/componentKeyMapper\";\ntype returnTypeOfHook = ReturnType<typeof useFormData>;\nconst RenderField = ({\n field,\n fieldPath,\n getFieldVisibilityState,\n form,\n all_errors,\n}: {\n field: BaseField;\n fieldPath: string;\n getFieldVisibilityState: (\n fieldPath: string,\n formValues: Record<string, unknown>\n ) => { hidden: boolean; disabled: boolean };\n form: returnTypeOfHook[\"appForm\"];\n all_errors: returnTypeOfHook[\"all_errors\"];\n}) => {\n const currentPath = fieldPath ? `${fieldPath}.${field.name}` : field.name;\n const { hidden, disabled } = getFieldVisibilityState(\n currentPath,\n form.state.values as Record<string, unknown>\n );\n\n if (hidden) return null;\n\n const baseProps: InternalFieldComponents = {\n label: field.label,\n placeholder: field.placeholder,\n title: field.title,\n description: field.description,\n disabled,\n required: field.required,\n selectOptions: field?.selectOptions,\n };\n return (\n <form.AppField key={field.name} name={currentPath}>\n {(fieldApi) => {\n const base = (\n <fieldApi.FieldComponent\n componentKey={getComponentKey(field.type)}\n {...baseProps}\n {...(field.type === \"multi-select\"\n ? {\n value: Array.isArray(fieldApi.state.value)\n ? fieldApi.state.value\n : [],\n }\n : {})}\n />\n );\n\n if (field.type === \"object\") {\n return (\n <fieldApi.ObjectWrapper\n label={field.label}\n title={field.title}\n description={field.description}\n required={field.required}\n >\n {field.fields.map((nestedField: BaseField) =>\n RenderField({\n field: nestedField,\n fieldPath: currentPath,\n getFieldVisibilityState,\n form,\n all_errors,\n })\n )}\n </fieldApi.ObjectWrapper>\n );\n }\n\n if (field.type === \"array\") {\n return (\n <fieldApi.ArrayField>\n {({ fields, append, remove }) => (\n <fieldApi.ArrayWrapper\n label={field.label}\n title={field.title}\n description={field.description}\n onAddField={() => {\n // @ts-ignore\n append(field.fields);\n }}\n onRemoveField={(index: number) => remove(index)}\n >\n {fields.map((item, index) => (\n <React.Fragment key={item.j1sjhghgtytfjiu971}>\n {field.fields?.map((nestedField) =>\n RenderField({\n field: nestedField,\n fieldPath: `${currentPath}[${index}]`,\n getFieldVisibilityState,\n form,\n all_errors,\n })\n )}\n </React.Fragment>\n ))}\n </fieldApi.ArrayWrapper>\n )}\n </fieldApi.ArrayField>\n );\n }\n\n if (field.type.includes(\"array-\")) {\n return (\n <fieldApi.ArrayFieldForArrayOfStrings>\n {({ fields, append, remove }) => {\n return (\n <fieldApi.ArrayInputFieldWrapper\n path={currentPath}\n name={field.name}\n componentKey={getComponentKey(field.type)}\n label={field.label}\n title={field.title}\n description={field.description}\n disabled={disabled}\n required={field.required}\n placeholder={field.placeholder}\n selectOptions={field?.selectOptions}\n all_errors={all_errors}\n onAddField={() =>\n append({\n value:\n field.type === \"array-date\"\n ? new Date()\n : field.type === \"array-boolean\"\n ? false\n : field.type === \"array-string\"\n ? \"\"\n : field.type === \"array-number\"\n ? 0\n : \"\",\n })\n }\n onRemoveField={(index: number) => remove(index)}\n fields={fields}\n />\n );\n }}\n </fieldApi.ArrayFieldForArrayOfStrings>\n );\n }\n\n // Default fallback for primitives\n return base;\n }}\n </form.AppField>\n );\n};\n\nexport default RenderField;\n","\"use client\";\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport GroupedFieldsWrapper from \"../base-components/GroupedFieldsWrapper\";\nimport { useComponentContext } from \"../context/useComponentContext\";\nimport type {\n\tAutoFormProps,\n\tBaseField,\n\tZodSchema,\n} from \"../types/auto-form-type\";\nimport useFromData from \"./hooks/useFromData\";\nimport RenderField from \"./renderField\";\nexport default function AutoForm<T extends ZodSchema>(props: AutoFormProps<T>) {\n\tconst {\n\t\tzodFormData,\n\t\tappForm,\n\t\tgetFieldVisibilityState,\n\t\tisLoading,\n\t\tall_errors,\n\t} = useFromData(props);\n\tconst { SubmitButton, Form } = useComponentContext();\n\tif (!Form) {\n\t\tthrow new Error(\n\t\t\t\"Please provide a SubmitButton and Form component and all the components are required\",\n\t\t);\n\t}\n\tif (zodFormData.getGroupedFields && zodFormData.getGroupedFields.length > 0) {\n\t\treturn (\n\t\t\t<Form\n\t\t\t\tformId={props.formId}\n\t\t\t\tonSubmit={(e) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tappForm.handleSubmit();\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{zodFormData.getGroupedFields.map((group) => (\n\t\t\t\t\t<GroupedFieldsWrapper key={group.name} groupName={group.name}>\n\t\t\t\t\t\t{group.fields.map((field) =>\n\t\t\t\t\t\t\tRenderField({\n\t\t\t\t\t\t\t\t// @ts-ignore - Fixing type mismatch between different versions of the same type\n\t\t\t\t\t\t\t\tfield: field,\n\t\t\t\t\t\t\t\tfieldPath: \"\",\n\t\t\t\t\t\t\t\tgetFieldVisibilityState,\n\t\t\t\t\t\t\t\t// @ts-ignore - Fixing type mismatch between different versions of the same type\n\t\t\t\t\t\t\t\tform: appForm,\n\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n\t\t\t\t\t\t\t\tall_errors: all_errors as any,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</GroupedFieldsWrapper>\n\t\t\t\t))}\n\t\t\t\t{!props.hideSubmitButton && (\n\t\t\t\t\t<SubmitButton\n\t\t\t\t\t\tisLoading={props.isLoadingButton || isLoading}\n\t\t\t\t\t\tformId={props.formId}\n\t\t\t\t\t>\n\t\t\t\t\t\t{props?.submitButtonText || \"Submit\"}\n\t\t\t\t\t</SubmitButton>\n\t\t\t\t)}\n\t\t\t</Form>\n\t\t);\n\t}\n\treturn (\n\t\t<Form\n\t\t\tformId={props.formId}\n\t\t\tonSubmit={(e) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tappForm.handleSubmit();\n\t\t\t}}\n\t\t>\n\t\t\t{zodFormData.getInputFields.map((field) => (\n\t\t\t\t<RenderField\n\t\t\t\t\tkey={field.name}\n\t\t\t\t\tfield={field as BaseField}\n\t\t\t\t\tfieldPath={\"\"}\n\t\t\t\t\tgetFieldVisibilityState={getFieldVisibilityState}\n\t\t\t\t\t// @ts-ignore - Fixing type mismatch between different versions of the same type\n\t\t\t\t\tform={appForm}\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n\t\t\t\t\tall_errors={all_errors as any}\n\t\t\t\t/>\n\t\t\t))}\n\t\t\t{!props.hideSubmitButton && (\n\t\t\t\t<SubmitButton\n\t\t\t\t\tisLoading={props.isLoadingButton || isLoading}\n\t\t\t\t\tformId={props.formId}\n\t\t\t\t>\n\t\t\t\t\t{props?.submitButtonText || \"Submit\"}\n\t\t\t\t</SubmitButton>\n\t\t\t)}\n\t\t</Form>\n\t);\n}\n","// create a component registry function that will register components in the context\r\n\r\nimport type { ComponentContextType } from \"../types/base-components\";\r\n\r\nexport const ComponentRegistry = (components: ComponentContextType) => {\r\n\treturn components;\r\n};\r\n"],"names":["defaultComponents","Input","Select","MultiSelect","RadioGroup","NumberInput","Checkbox","Switch","TextArea","DateTimePicker","ObjectWrapper","ArrayWrapper","Form","SubmitButton","GroupedFieldsWrapper","ArrayInputFieldWrapper","arrayString","arrayNumber","arrayBoolean","arrayDate","ComponentContext","createContext","useComponentContext","useContext","AutoFormComponentsProvider","children","components","value","_jsx","Provider","groupName","GroupedFieldsComponent","generateRandomKey","crypto","randomUUID","Math","random","toString","substring","generateEmptyData","fields","data","field","type","name","defaultValue","Number","getArrayFieldError","formErrors","fieldName","index","Array","isArray","fullKey","findErrorDeep","errors","key","val","message","nested","result","errorObj","error","fieldContext","formContext","useFieldContext","useFormContext","createFormHookContexts","FieldComponents","FieldComponent","GenericFormField","componentKey","rest","Component","isError","state","meta","isTouched","length","id","onChange","handleChange","errorMessages","onBlur","handleBlur","ArrayField","ArrayFieldForArrayOfObjects","setFields","useState","previousValuesRef","useRef","fieldsRef","useEffect","current","newValue","JSON","stringify","newFields","map","prev","j1sjhghgtytfjiu971","Date","append","valueX","newItem","updatedValues","item","remove","splice","ArrayFieldForArrayOfStrings","mapped","title","description","label","required","ObjectWrapperComponent","onAddField","onRemoveField","ArrayWrapperComponent","disabled","placeholder","all_errors","path","context","values","setValues","touchedFields","setTouchedFields","WrapperComponent","getFieldValue","undefined","form","shouldShowError","updated","useAppForm","withForm","createFormHook","fieldComponents","formComponents","shouldApplyRule","rule","formValues","sourceValues","sourceFields","getNestedValue","obj","replace","split","filter","Boolean","reduce","acc","isInteger","Object","fromEntries","join","when","cleanPath","mergeDefaultValues","userDefaults","zodDefaults","merged","entries","removeNullValues","AsyncFunction","getPrototypeOf","async","constructor","useFormData","schema","changePositionOfFields","fieldTypeOverrides","groupByZodKeys","visibilityRules","defaultValues","onSubmit","onSubmitError","onValuesChange","isRemoveNullValues","formVersion","setFormVersion","isLoading","setIsLoading","formSubmittedRef","zodFormData","useMemo","formData","ZodFormClassed","changeJsonFieldPositions","overrideFieldTypes","mergedDefaultValues","getZodDefaultValues","handleSubmit","useCallback","props","Error","dataToParse","parsedData","parse","isAsync","fn","then","catch","z","ZodError","extractZodErrorMessages","appForm","defaultState","onSubmitInvalid","formApi","validators","getFieldVisibilityState","fieldPath","hidden","applicableRules","targetField","some","shown","getAllErrors","getComponentKey","RenderField","currentPath","baseProps","selectOptions","AppField","fieldApi","base","nestedField","React","Fragment","includes","AutoForm","useFromData","getGroupedFields","_jsxs","formId","e","preventDefault","group","hideSubmitButton","isLoadingButton","submitButtonText","getInputFields","ComponentRegistry"],"mappings":"qWAKA,MAAMA,EAA0C,CAC/CC,MAAO,IAAM,KACbC,OAAQ,IAAM,KACdC,YAAa,IAAM,KACnBC,WAAY,IAAM,KAClB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