UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

89 lines (85 loc) 3.1 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; export default function createFieldArrayProps(_ref2, name, form, sectionPrefix, getValue, _ref) { var getIn = _ref2.getIn; var arrayInsert = _ref.arrayInsert, arrayMove = _ref.arrayMove, arrayPop = _ref.arrayPop, arrayPush = _ref.arrayPush, arrayRemove = _ref.arrayRemove, arrayRemoveAll = _ref.arrayRemoveAll, arrayShift = _ref.arrayShift, arraySplice = _ref.arraySplice, arraySwap = _ref.arraySwap, arrayUnshift = _ref.arrayUnshift, asyncError = _ref.asyncError, dirty = _ref.dirty, length = _ref.length, pristine = _ref.pristine, submitError = _ref.submitError, state = _ref.state, submitFailed = _ref.submitFailed, submitting = _ref.submitting, syncError = _ref.syncError, syncWarning = _ref.syncWarning, value = _ref.value, props = _ref.props, rest = _objectWithoutPropertiesLoose(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "length", "pristine", "submitError", "state", "submitFailed", "submitting", "syncError", "syncWarning", "value", "props"]); var error = syncError || asyncError || submitError; var warning = syncWarning; var fieldName = sectionPrefix ? name.replace(sectionPrefix + ".", '') : name; var finalProps = _extends({ fields: { _isFieldArray: true, forEach: function forEach(callback) { return (value || []).forEach(function (item, index) { return callback(fieldName + "[" + index + "]", index, finalProps.fields); }); }, get: getValue, getAll: function getAll() { return value; }, insert: arrayInsert, length: length, map: function map(callback) { return (value || []).map(function (item, index) { return callback(fieldName + "[" + index + "]", index, finalProps.fields); }); }, move: arrayMove, name: name, pop: function pop() { arrayPop(); return getIn(value, String(length - 1)); }, push: arrayPush, reduce: function reduce(callback, initial) { return (value || []).reduce(function (accumulator, item, index) { return callback(accumulator, fieldName + "[" + index + "]", index, finalProps.fields); }, initial); }, remove: arrayRemove, removeAll: arrayRemoveAll, shift: function shift() { arrayShift(); return getIn(value, '0'); }, splice: arraySplice, swap: arraySwap, unshift: arrayUnshift }, meta: { dirty: dirty, error: error, form: form, warning: warning, invalid: !!error, pristine: pristine, submitting: submitting, submitFailed: submitFailed, valid: !error } }, props, {}, rest); return finalProps; }