{"version":3,"file":"ArrayField.mjs","names":[],"sources":["../../src/react-hook-form/ArrayField.tsx"],"sourcesContent":["import React from \"react\";\nimport { useFieldArray } from \"react-hook-form\";\nimport { getLabel } from \"@autoform/core\";\nimport type { ParsedField } from \"@autoform/core\";\nimport { AutoFormField } from \"./AutoFormField\";\nimport { useAutoForm } from \"../context\";\nimport { useRegister } from \"./hooks\";\nimport { getArrayItemDefaultValue } from \"../utils\";\n\nexport const ArrayField: React.FC<{\n  id: string;\n  path: string[];\n  inputProps: any;\n  parsedField: ParsedField;\n  error?: string | undefined;\n}> = ({ id, path, inputProps, error, parsedField }) => {\n  const { uiComponents } = useAutoForm();\n  const { fields, append, remove } = useFieldArray({\n    name: path.join(\".\"),\n  });\n  const ref = useRegister(path.join(\".\")).ref;\n  const ArrayWrapper =\n    parsedField.fieldConfig?.arrayWrapper || uiComponents.ArrayWrapper;\n  const ArrayElementWrapper =\n    parsedField.fieldConfig?.arrayElementWrapper ||\n    uiComponents.ArrayElementWrapper;\n  const defaultValue = getArrayItemDefaultValue(parsedField);\n\n  return (\n    <ArrayWrapper\n      error={error}\n      parsedField={parsedField}\n      inputProps={{\n        key: `${id}-input`,\n        ...inputProps,\n        ref: ref,\n      }}\n      label={getLabel(parsedField)}\n      onAddItem={() => append(defaultValue)}\n    >\n      {fields.map((item, index) => (\n        <ArrayElementWrapper\n          key={item.id}\n          onRemove={() => remove(index)}\n          index={index}\n        >\n          <AutoFormField\n            parsedField={parsedField.schema![0]!}\n            path={[...path, index.toString()]}\n          />\n        </ArrayElementWrapper>\n      ))}\n    </ArrayWrapper>\n  );\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,cAMP,EAAE,IAAI,MAAM,YAAY,OAAO,kBAAkB;CACrD,MAAM,EAAE,iBAAiB,YAAY;CACrC,MAAM,EAAE,QAAQ,QAAQ,WAAW,cAAc,EAC/C,MAAM,KAAK,KAAK,GAAG,EACrB,CAAC;CACD,MAAM,MAAM,YAAY,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC;CACxC,MAAM,eACJ,YAAY,aAAa,gBAAgB,aAAa;CACxD,MAAM,sBACJ,YAAY,aAAa,uBACzB,aAAa;CACf,MAAM,eAAe,yBAAyB,WAAW;CAEzD,OACE,oBAAC,cAAD;EACS;EACM;EACb,YAAY;GACV,KAAK,GAAG,GAAG;GACX,GAAG;GACE;EACP;EACA,OAAO,SAAS,WAAW;EAC3B,iBAAiB,OAAO,YAAY;YAEnC,OAAO,KAAK,MAAM,UACjB,oBAAC,qBAAD;GAEE,gBAAgB,OAAO,KAAK;GACrB;aAEP,oBAAC,eAAD;IACE,aAAa,YAAY,OAAQ;IACjC,MAAM,CAAC,GAAG,MAAM,MAAM,SAAS,CAAC;GACjC,CAAA;EACkB,GARd,KAAK,EAQS,CACtB;CACW,CAAA;AAElB"}