1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 |
|
10 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
11 |
|
12 | var createFieldArrayProps = function createFieldArrayProps(_ref2, name, form, sectionPrefix, getValue, _ref) {
|
13 | var getIn = _ref2.getIn;
|
14 | var arrayInsert = _ref.arrayInsert,
|
15 | arrayMove = _ref.arrayMove,
|
16 | arrayPop = _ref.arrayPop,
|
17 | arrayPush = _ref.arrayPush,
|
18 | arrayRemove = _ref.arrayRemove,
|
19 | arrayRemoveAll = _ref.arrayRemoveAll,
|
20 | arrayShift = _ref.arrayShift,
|
21 | arraySplice = _ref.arraySplice,
|
22 | arraySwap = _ref.arraySwap,
|
23 | arrayUnshift = _ref.arrayUnshift,
|
24 | asyncError = _ref.asyncError,
|
25 | dirty = _ref.dirty,
|
26 | length = _ref.length,
|
27 | pristine = _ref.pristine,
|
28 | submitError = _ref.submitError,
|
29 | state = _ref.state,
|
30 | submitFailed = _ref.submitFailed,
|
31 | submitting = _ref.submitting,
|
32 | syncError = _ref.syncError,
|
33 | syncWarning = _ref.syncWarning,
|
34 | value = _ref.value,
|
35 | props = _ref.props,
|
36 | rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "length", "pristine", "submitError", "state", "submitFailed", "submitting", "syncError", "syncWarning", "value", "props"]);
|
37 | var error = syncError || asyncError || submitError;
|
38 | var warning = syncWarning;
|
39 | var fieldName = sectionPrefix ? name.replace(sectionPrefix + ".", '') : name;
|
40 | var finalProps = (0, _extends2["default"])({
|
41 | fields: {
|
42 | _isFieldArray: true,
|
43 | forEach: function forEach(callback) {
|
44 | return (value || []).forEach(function (item, index) {
|
45 | return callback(fieldName + "[" + index + "]", index, finalProps.fields);
|
46 | });
|
47 | },
|
48 | get: getValue,
|
49 | getAll: function getAll() {
|
50 | return value;
|
51 | },
|
52 | insert: arrayInsert,
|
53 | length: length,
|
54 | map: function map(callback) {
|
55 | return (value || []).map(function (item, index) {
|
56 | return callback(fieldName + "[" + index + "]", index, finalProps.fields);
|
57 | });
|
58 | },
|
59 | move: arrayMove,
|
60 | name: name,
|
61 | pop: function pop() {
|
62 | arrayPop();
|
63 | return getIn(value, String(length - 1));
|
64 | },
|
65 | push: arrayPush,
|
66 | reduce: function reduce(callback, initial) {
|
67 | return (value || []).reduce(function (accumulator, item, index) {
|
68 | return callback(accumulator, fieldName + "[" + index + "]", index, finalProps.fields);
|
69 | }, initial);
|
70 | },
|
71 | remove: arrayRemove,
|
72 | removeAll: arrayRemoveAll,
|
73 | shift: function shift() {
|
74 | arrayShift();
|
75 | return getIn(value, '0');
|
76 | },
|
77 | splice: arraySplice,
|
78 | swap: arraySwap,
|
79 | unshift: arrayUnshift
|
80 | },
|
81 | meta: {
|
82 | dirty: dirty,
|
83 | error: error,
|
84 | form: form,
|
85 | warning: warning,
|
86 | invalid: !!error,
|
87 | pristine: pristine,
|
88 | submitting: submitting,
|
89 | submitFailed: submitFailed,
|
90 | valid: !error
|
91 | }
|
92 | }, props, {}, rest);
|
93 | return finalProps;
|
94 | };
|
95 |
|
96 | var _default = createFieldArrayProps;
|
97 | exports["default"] = _default; |
\ | No newline at end of file |