Socket
Socket
Sign inDemoInstall

final-form-arrays

Package Overview
Dependencies
3
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.2 to 3.1.0

dist/final-form-arrays.cjs.js.flow

377

dist/final-form-arrays.cjs.js

@@ -32,16 +32,11 @@ 'use strict';

//
function moveFieldState(state, source, destKey, oldState) {
if (oldState === void 0) {
oldState = state;
}
delete state.fields[source.name];
state.fields[destKey] = _extends_1({}, source, {
name: destKey,
function copyField(oldFields, oldKey, newFields, newKey) {
newFields[newKey] = _extends_1({}, oldFields[oldKey], {
name: newKey,
// prevent functions from being overwritten
// if the state.fields[destKey] does not exist, it will be created
// if the newFields[newKey] does not exist, it will be created
// when that field gets registered, with its own change/blur/focus callbacks
change: oldState.fields[destKey] && oldState.fields[destKey].change,
blur: oldState.fields[destKey] && oldState.fields[destKey].blur,
focus: oldState.fields[destKey] && oldState.fields[destKey].focus,
change: oldFields[newKey] && oldFields[newKey].change,
blur: oldFields[newKey] && oldFields[newKey].blur,
focus: oldFields[newKey] && oldFields[newKey].focus,
lastFieldState: undefined // clearing lastFieldState forces renotification

@@ -51,12 +46,12 @@

if (!state.fields[destKey].change) {
delete state.fields[destKey].change;
if (!newFields[newKey].change) {
delete newFields[newKey].change;
}
if (!state.fields[destKey].blur) {
delete state.fields[destKey].blur;
if (!newFields[newKey].blur) {
delete newFields[newKey].blur;
}
if (!state.fields[destKey].focus) {
delete state.fields[destKey].focus;
if (!newFields[newKey].focus) {
delete newFields[newKey].focus;
}

@@ -71,2 +66,4 @@ }

//
var insert = function insert(_ref, state, _ref2) {

@@ -76,4 +73,3 @@ var name = _ref[0],

value = _ref[2];
var changeValue = _ref2.changeValue,
resetFieldState = _ref2.resetFieldState;
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {

@@ -83,11 +79,7 @@ var copy = [].concat(array || []);

return copy;
});
}); // now we have increment any higher indexes
var backup = _extends_1({}, state.fields); // now we have increment any higher indexes
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)"); // we need to increment high indices first so
// lower indices won't overlap
Object.keys(state.fields).sort().reverse().forEach(function (key) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);

@@ -99,8 +91,14 @@

if (fieldIndex >= index) {
// inc index one higher
// Shift all higher indices up
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2];
moveFieldState(state, backup[key], incrementedKey);
copyField(state.fields, key, newFields, incrementedKey);
return;
}
}
} // Keep this field that does not match the name,
// or has index smaller than what is being inserted
newFields[key] = state.fields[key];
});
state.fields = newFields;
};

@@ -120,37 +118,2 @@

function moveFields(name, matchPrefix, destIndex, state) {
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, matchPrefix.length) === matchPrefix) {
var suffix = key.substring(matchPrefix.length);
var destKey = name + "[" + destIndex + "]" + suffix;
moveFieldState(state, state.fields[key], destKey);
}
});
}
//
function restoreFunctions(state, backupState) {
Object.keys(state.fields).forEach(function (key) {
state.fields[key] = _extends_1({}, state.fields[key], {
change: state.fields[key].change || backupState.fields[key] && backupState.fields[key].change,
blur: state.fields[key].blur || backupState.fields[key] && backupState.fields[key].blur,
focus: state.fields[key].focus || backupState.fields[key] && backupState.fields[key].focus
});
if (!state.fields[key].change) {
delete state.fields[key].change;
}
if (!state.fields[key].blur) {
delete state.fields[key].blur;
}
if (!state.fields[key].focus) {
delete state.fields[key].focus;
}
});
}
var TMP = 'tmp';
var move = function move(_ref, state, _ref2) {

@@ -172,76 +135,49 @@ var name = _ref[0],

return copy;
}); //make a copy of a state for further functions restore
var backupState = _extends_1({}, state, {
fields: _extends_1({}, state.fields) // move this row to tmp index
});
var newFields = {};
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var lowest;
var highest;
var increment;
var fromPrefix = name + "[" + from + "]";
moveFields(name, fromPrefix, TMP, state);
if (from < to) {
// moving to a higher index
// decrement all indices between from and to
for (var i = from + 1; i <= to; i++) {
var innerFromPrefix = name + "[" + i + "]";
moveFields(name, innerFromPrefix, "" + (i - 1), state);
}
if (from > to) {
lowest = to;
highest = from;
increment = 1;
} else {
// moving to a lower index
// increment all indices between to and from
for (var _i = from - 1; _i >= to; _i--) {
var _innerFromPrefix = name + "[" + _i + "]";
lowest = from;
highest = to;
increment = -1;
}
moveFields(name, _innerFromPrefix, "" + (_i + 1), state);
}
} // move from tmp index to destination
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);
if (tokens) {
var fieldIndex = Number(tokens[1]);
var tmpPrefix = name + "[" + TMP + "]";
moveFields(name, tmpPrefix, to, state);
restoreFunctions(state, backupState);
};
//
var pop = function pop(_ref, state, _ref2) {
var name = _ref[0];
var changeValue = _ref2.changeValue;
var result;
var removedIndex;
changeValue(state, name, function (array) {
if (array) {
if (!array.length) {
return [];
if (fieldIndex === from) {
var newKey = name + "[" + to + "]" + tokens[2];
copyField(state.fields, key, newFields, newKey);
return;
}
removedIndex = array.length - 1;
result = array[removedIndex];
return array.slice(0, removedIndex);
}
}); // now we have to remove any subfields for our index,
if (lowest <= fieldIndex && fieldIndex <= highest) {
// Shift all indices
var _newKey = name + "[" + (fieldIndex + increment) + "]" + tokens[2];
if (removedIndex !== undefined) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[" + removedIndex + "].*");
Object.keys(state.fields).forEach(function (key) {
if (pattern.test(key)) {
delete state.fields[key];
copyField(state.fields, key, newFields, _newKey);
return;
}
});
}
} // Keep this field that does not match the name,
// or has index smaller or larger than affected range
return result;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
newFields[key] = state.fields[key];
});
state.fields = newFields;
};
//
var remove = function remove(_ref, state, _ref2) {

@@ -251,9 +187,14 @@ var name = _ref[0],

var changeValue = _ref2.changeValue,
renameField = _ref2.renameField;
getIn = _ref2.getIn,
setIn = _ref2.setIn;
var returnValue;
changeValue(state, name, function (array) {
var copy = [].concat(array || []);
if (!array) {
return array;
}
var copy = [].concat(array);
returnValue = copy[index];
copy.splice(index, 1);
return copy;
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our index,

@@ -263,7 +204,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var backup = _extends_1({}, state, {
fields: _extends_1({}, state.fields)
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -276,27 +213,77 @@ var tokens = pattern.exec(key);

if (fieldIndex === index) {
// delete any subfields for this array item
delete state.fields[key];
} else if (fieldIndex > index) {
// shift all higher ones down
delete state.fields[key];
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
// delete any submitErrors for this array item
// if the root key of the delete index
if (key === name + "[" + index + "]") {
var path = "formState.submitErrors." + name;
var submitErrors = getIn(state, path); // if has submitErrors for array
if (backup.fields[decrementedKey]) {
moveFieldState(state, backup.fields[key], decrementedKey, backup);
} else {
// take care of setting the correct change, blur, focus, validators on new field
renameField(state, key, decrementedKey);
if (Array.isArray(submitErrors)) {
submitErrors.splice(index, 1);
state = setIn(state, path, submitErrors);
}
}
return;
}
}
if (fieldIndex > index) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newFields;
return returnValue;
};
var countBelow = function countBelow(array, value) {
return array.reduce(function (count, item) {
return item < value ? count + 1 : count;
}, 0);
//
var pop = function pop(_ref, state, tools) {
var name = _ref[0];
var getIn = tools.getIn;
var array = getIn(state.formState.values, name);
return array && array.length > 0 ? remove([name, array.length - 1], state, tools) : undefined;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
});
};
//
var binarySearch = function binarySearch(list, value) {
// This algorithm assumes the items in list is unique
var first = 0;
var last = list.length - 1;
var middle = 0;
while (first <= last) {
middle = Math.floor((first + last) / 2);
if (list[middle] === value) {
return middle;
}
if (list[middle] > value) {
last = middle - 1;
} else {
first = middle + 1;
}
}
return ~first;
};
var removeBatch = function removeBatch(_ref, state, _ref2) {

@@ -306,8 +293,13 @@ var name = _ref[0],

var changeValue = _ref2.changeValue;
if (indexes.length === 0) {
return [];
}
var sortedIndexes = [].concat(indexes);
sortedIndexes.sort(); // remove duplicates
sortedIndexes.sort(); // Remove duplicates
for (var i = 0; i < sortedIndexes.length; i++) {
if (i > 0 && sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i--, 1);
for (var i = sortedIndexes.length - 1; i > 0; i -= 1) {
if (sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i, 1);
}

@@ -323,3 +315,3 @@ }

if (!array || !sortedIndexes.length) {
if (!array) {
return array;

@@ -329,8 +321,9 @@ }

var copy = [].concat(array);
var removed = [];
sortedIndexes.forEach(function (index) {
copy.splice(index - removed.length, 1);
removed.push(array && array[index]);
});
return copy;
for (var _i = sortedIndexes.length - 1; _i >= 0; _i -= 1) {
var index = sortedIndexes[_i];
copy.splice(index, 1);
}
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our indexes,

@@ -340,7 +333,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newState = _extends_1({}, state, {
fields: {}
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -351,14 +340,22 @@ var tokens = pattern.exec(key);

var fieldIndex = Number(tokens[1]);
var indexOfFieldIndex = binarySearch(sortedIndexes, fieldIndex);
if (!~sortedIndexes.indexOf(fieldIndex)) {
// not one of the removed indexes
// shift all higher ones down
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2];
moveFieldState(newState, state.fields[key], decrementedKey, state);
if (indexOfFieldIndex >= 0) {
// One of the removed indices
return;
}
} else {
newState.fields[key] = state.fields[key];
}
if (fieldIndex > sortedIndexes[0]) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - ~indexOfFieldIndex) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newState.fields;
state.fields = newFields;
return returnValue;

@@ -374,3 +371,3 @@ };

var TMP$1 = 'tmp';
//

@@ -393,16 +390,24 @@ var swap = function swap(_ref, state, _ref2) {

return copy;
}); //make a copy of a state for further functions restore
}); // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var backupState = _extends_1({}, state, {
fields: _extends_1({}, state.fields) // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, aPrefix.length) === aPrefix) {
var suffix = key.substring(aPrefix.length);
var newKey = bPrefix + suffix;
copyField(state.fields, key, newFields, newKey);
} else if (key.substring(0, bPrefix.length) === bPrefix) {
var _suffix = key.substring(bPrefix.length);
var _newKey = aPrefix + _suffix;
copyField(state.fields, key, newFields, _newKey);
} else {
// Keep this field that does not match the name
newFields[key] = state.fields[key];
}
});
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var tmpPrefix = name + "[" + TMP$1 + "]";
moveFields(name, aPrefix, TMP$1, state);
moveFields(name, bPrefix, indexA, state);
moveFields(name, tmpPrefix, indexB, state);
restoreFunctions(state, backupState);
state.fields = newFields;
};

@@ -409,0 +414,0 @@

@@ -20,16 +20,11 @@ function _extends() {

//
function moveFieldState(state, source, destKey, oldState) {
if (oldState === void 0) {
oldState = state;
}
delete state.fields[source.name];
state.fields[destKey] = _extends({}, source, {
name: destKey,
function copyField(oldFields, oldKey, newFields, newKey) {
newFields[newKey] = _extends({}, oldFields[oldKey], {
name: newKey,
// prevent functions from being overwritten
// if the state.fields[destKey] does not exist, it will be created
// if the newFields[newKey] does not exist, it will be created
// when that field gets registered, with its own change/blur/focus callbacks
change: oldState.fields[destKey] && oldState.fields[destKey].change,
blur: oldState.fields[destKey] && oldState.fields[destKey].blur,
focus: oldState.fields[destKey] && oldState.fields[destKey].focus,
change: oldFields[newKey] && oldFields[newKey].change,
blur: oldFields[newKey] && oldFields[newKey].blur,
focus: oldFields[newKey] && oldFields[newKey].focus,
lastFieldState: undefined // clearing lastFieldState forces renotification

@@ -39,12 +34,12 @@

if (!state.fields[destKey].change) {
delete state.fields[destKey].change;
if (!newFields[newKey].change) {
delete newFields[newKey].change;
}
if (!state.fields[destKey].blur) {
delete state.fields[destKey].blur;
if (!newFields[newKey].blur) {
delete newFields[newKey].blur;
}
if (!state.fields[destKey].focus) {
delete state.fields[destKey].focus;
if (!newFields[newKey].focus) {
delete newFields[newKey].focus;
}

@@ -59,2 +54,4 @@ }

//
var insert = function insert(_ref, state, _ref2) {

@@ -64,4 +61,3 @@ var name = _ref[0],

value = _ref[2];
var changeValue = _ref2.changeValue,
resetFieldState = _ref2.resetFieldState;
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {

@@ -71,11 +67,7 @@ var copy = [].concat(array || []);

return copy;
});
}); // now we have increment any higher indexes
var backup = _extends({}, state.fields); // now we have increment any higher indexes
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)"); // we need to increment high indices first so
// lower indices won't overlap
Object.keys(state.fields).sort().reverse().forEach(function (key) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);

@@ -87,8 +79,14 @@

if (fieldIndex >= index) {
// inc index one higher
// Shift all higher indices up
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2];
moveFieldState(state, backup[key], incrementedKey);
copyField(state.fields, key, newFields, incrementedKey);
return;
}
}
} // Keep this field that does not match the name,
// or has index smaller than what is being inserted
newFields[key] = state.fields[key];
});
state.fields = newFields;
};

@@ -108,37 +106,2 @@

function moveFields(name, matchPrefix, destIndex, state) {
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, matchPrefix.length) === matchPrefix) {
var suffix = key.substring(matchPrefix.length);
var destKey = name + "[" + destIndex + "]" + suffix;
moveFieldState(state, state.fields[key], destKey);
}
});
}
//
function restoreFunctions(state, backupState) {
Object.keys(state.fields).forEach(function (key) {
state.fields[key] = _extends({}, state.fields[key], {
change: state.fields[key].change || backupState.fields[key] && backupState.fields[key].change,
blur: state.fields[key].blur || backupState.fields[key] && backupState.fields[key].blur,
focus: state.fields[key].focus || backupState.fields[key] && backupState.fields[key].focus
});
if (!state.fields[key].change) {
delete state.fields[key].change;
}
if (!state.fields[key].blur) {
delete state.fields[key].blur;
}
if (!state.fields[key].focus) {
delete state.fields[key].focus;
}
});
}
var TMP = 'tmp';
var move = function move(_ref, state, _ref2) {

@@ -160,76 +123,49 @@ var name = _ref[0],

return copy;
}); //make a copy of a state for further functions restore
var backupState = _extends({}, state, {
fields: _extends({}, state.fields) // move this row to tmp index
});
var newFields = {};
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var lowest;
var highest;
var increment;
var fromPrefix = name + "[" + from + "]";
moveFields(name, fromPrefix, TMP, state);
if (from < to) {
// moving to a higher index
// decrement all indices between from and to
for (var i = from + 1; i <= to; i++) {
var innerFromPrefix = name + "[" + i + "]";
moveFields(name, innerFromPrefix, "" + (i - 1), state);
}
if (from > to) {
lowest = to;
highest = from;
increment = 1;
} else {
// moving to a lower index
// increment all indices between to and from
for (var _i = from - 1; _i >= to; _i--) {
var _innerFromPrefix = name + "[" + _i + "]";
lowest = from;
highest = to;
increment = -1;
}
moveFields(name, _innerFromPrefix, "" + (_i + 1), state);
}
} // move from tmp index to destination
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);
if (tokens) {
var fieldIndex = Number(tokens[1]);
var tmpPrefix = name + "[" + TMP + "]";
moveFields(name, tmpPrefix, to, state);
restoreFunctions(state, backupState);
};
//
var pop = function pop(_ref, state, _ref2) {
var name = _ref[0];
var changeValue = _ref2.changeValue;
var result;
var removedIndex;
changeValue(state, name, function (array) {
if (array) {
if (!array.length) {
return [];
if (fieldIndex === from) {
var newKey = name + "[" + to + "]" + tokens[2];
copyField(state.fields, key, newFields, newKey);
return;
}
removedIndex = array.length - 1;
result = array[removedIndex];
return array.slice(0, removedIndex);
}
}); // now we have to remove any subfields for our index,
if (lowest <= fieldIndex && fieldIndex <= highest) {
// Shift all indices
var _newKey = name + "[" + (fieldIndex + increment) + "]" + tokens[2];
if (removedIndex !== undefined) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[" + removedIndex + "].*");
Object.keys(state.fields).forEach(function (key) {
if (pattern.test(key)) {
delete state.fields[key];
copyField(state.fields, key, newFields, _newKey);
return;
}
});
}
} // Keep this field that does not match the name,
// or has index smaller or larger than affected range
return result;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
newFields[key] = state.fields[key];
});
state.fields = newFields;
};
//
var remove = function remove(_ref, state, _ref2) {

@@ -239,9 +175,14 @@ var name = _ref[0],

var changeValue = _ref2.changeValue,
renameField = _ref2.renameField;
getIn = _ref2.getIn,
setIn = _ref2.setIn;
var returnValue;
changeValue(state, name, function (array) {
var copy = [].concat(array || []);
if (!array) {
return array;
}
var copy = [].concat(array);
returnValue = copy[index];
copy.splice(index, 1);
return copy;
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our index,

@@ -251,7 +192,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var backup = _extends({}, state, {
fields: _extends({}, state.fields)
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -264,27 +201,77 @@ var tokens = pattern.exec(key);

if (fieldIndex === index) {
// delete any subfields for this array item
delete state.fields[key];
} else if (fieldIndex > index) {
// shift all higher ones down
delete state.fields[key];
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
// delete any submitErrors for this array item
// if the root key of the delete index
if (key === name + "[" + index + "]") {
var path = "formState.submitErrors." + name;
var submitErrors = getIn(state, path); // if has submitErrors for array
if (backup.fields[decrementedKey]) {
moveFieldState(state, backup.fields[key], decrementedKey, backup);
} else {
// take care of setting the correct change, blur, focus, validators on new field
renameField(state, key, decrementedKey);
if (Array.isArray(submitErrors)) {
submitErrors.splice(index, 1);
state = setIn(state, path, submitErrors);
}
}
return;
}
}
if (fieldIndex > index) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newFields;
return returnValue;
};
var countBelow = function countBelow(array, value) {
return array.reduce(function (count, item) {
return item < value ? count + 1 : count;
}, 0);
//
var pop = function pop(_ref, state, tools) {
var name = _ref[0];
var getIn = tools.getIn;
var array = getIn(state.formState.values, name);
return array && array.length > 0 ? remove([name, array.length - 1], state, tools) : undefined;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
});
};
//
var binarySearch = function binarySearch(list, value) {
// This algorithm assumes the items in list is unique
var first = 0;
var last = list.length - 1;
var middle = 0;
while (first <= last) {
middle = Math.floor((first + last) / 2);
if (list[middle] === value) {
return middle;
}
if (list[middle] > value) {
last = middle - 1;
} else {
first = middle + 1;
}
}
return ~first;
};
var removeBatch = function removeBatch(_ref, state, _ref2) {

@@ -294,8 +281,13 @@ var name = _ref[0],

var changeValue = _ref2.changeValue;
if (indexes.length === 0) {
return [];
}
var sortedIndexes = [].concat(indexes);
sortedIndexes.sort(); // remove duplicates
sortedIndexes.sort(); // Remove duplicates
for (var i = 0; i < sortedIndexes.length; i++) {
if (i > 0 && sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i--, 1);
for (var i = sortedIndexes.length - 1; i > 0; i -= 1) {
if (sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i, 1);
}

@@ -311,3 +303,3 @@ }

if (!array || !sortedIndexes.length) {
if (!array) {
return array;

@@ -317,8 +309,9 @@ }

var copy = [].concat(array);
var removed = [];
sortedIndexes.forEach(function (index) {
copy.splice(index - removed.length, 1);
removed.push(array && array[index]);
});
return copy;
for (var _i = sortedIndexes.length - 1; _i >= 0; _i -= 1) {
var index = sortedIndexes[_i];
copy.splice(index, 1);
}
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our indexes,

@@ -328,7 +321,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newState = _extends({}, state, {
fields: {}
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -339,14 +328,22 @@ var tokens = pattern.exec(key);

var fieldIndex = Number(tokens[1]);
var indexOfFieldIndex = binarySearch(sortedIndexes, fieldIndex);
if (!~sortedIndexes.indexOf(fieldIndex)) {
// not one of the removed indexes
// shift all higher ones down
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2];
moveFieldState(newState, state.fields[key], decrementedKey, state);
if (indexOfFieldIndex >= 0) {
// One of the removed indices
return;
}
} else {
newState.fields[key] = state.fields[key];
}
if (fieldIndex > sortedIndexes[0]) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - ~indexOfFieldIndex) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newState.fields;
state.fields = newFields;
return returnValue;

@@ -362,3 +359,3 @@ };

var TMP$1 = 'tmp';
//

@@ -381,16 +378,24 @@ var swap = function swap(_ref, state, _ref2) {

return copy;
}); //make a copy of a state for further functions restore
}); // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var backupState = _extends({}, state, {
fields: _extends({}, state.fields) // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, aPrefix.length) === aPrefix) {
var suffix = key.substring(aPrefix.length);
var newKey = bPrefix + suffix;
copyField(state.fields, key, newFields, newKey);
} else if (key.substring(0, bPrefix.length) === bPrefix) {
var _suffix = key.substring(bPrefix.length);
var _newKey = aPrefix + _suffix;
copyField(state.fields, key, newFields, _newKey);
} else {
// Keep this field that does not match the name
newFields[key] = state.fields[key];
}
});
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var tmpPrefix = name + "[" + TMP$1 + "]";
moveFields(name, aPrefix, TMP$1, state);
moveFields(name, bPrefix, indexA, state);
moveFields(name, tmpPrefix, indexB, state);
restoreFunctions(state, backupState);
state.fields = newFields;
};

@@ -397,0 +402,0 @@

@@ -26,16 +26,11 @@ (function (global, factory) {

//
function moveFieldState(state, source, destKey, oldState) {
if (oldState === void 0) {
oldState = state;
}
delete state.fields[source.name];
state.fields[destKey] = _extends({}, source, {
name: destKey,
function copyField(oldFields, oldKey, newFields, newKey) {
newFields[newKey] = _extends({}, oldFields[oldKey], {
name: newKey,
// prevent functions from being overwritten
// if the state.fields[destKey] does not exist, it will be created
// if the newFields[newKey] does not exist, it will be created
// when that field gets registered, with its own change/blur/focus callbacks
change: oldState.fields[destKey] && oldState.fields[destKey].change,
blur: oldState.fields[destKey] && oldState.fields[destKey].blur,
focus: oldState.fields[destKey] && oldState.fields[destKey].focus,
change: oldFields[newKey] && oldFields[newKey].change,
blur: oldFields[newKey] && oldFields[newKey].blur,
focus: oldFields[newKey] && oldFields[newKey].focus,
lastFieldState: undefined // clearing lastFieldState forces renotification

@@ -45,12 +40,12 @@

if (!state.fields[destKey].change) {
delete state.fields[destKey].change;
if (!newFields[newKey].change) {
delete newFields[newKey].change;
}
if (!state.fields[destKey].blur) {
delete state.fields[destKey].blur;
if (!newFields[newKey].blur) {
delete newFields[newKey].blur;
}
if (!state.fields[destKey].focus) {
delete state.fields[destKey].focus;
if (!newFields[newKey].focus) {
delete newFields[newKey].focus;
}

@@ -65,2 +60,4 @@ }

//
var insert = function insert(_ref, state, _ref2) {

@@ -70,4 +67,3 @@ var name = _ref[0],

value = _ref[2];
var changeValue = _ref2.changeValue,
resetFieldState = _ref2.resetFieldState;
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {

@@ -77,11 +73,7 @@ var copy = [].concat(array || []);

return copy;
});
}); // now we have increment any higher indexes
var backup = _extends({}, state.fields); // now we have increment any higher indexes
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)"); // we need to increment high indices first so
// lower indices won't overlap
Object.keys(state.fields).sort().reverse().forEach(function (key) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);

@@ -93,8 +85,14 @@

if (fieldIndex >= index) {
// inc index one higher
// Shift all higher indices up
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2];
moveFieldState(state, backup[key], incrementedKey);
copyField(state.fields, key, newFields, incrementedKey);
return;
}
}
} // Keep this field that does not match the name,
// or has index smaller than what is being inserted
newFields[key] = state.fields[key];
});
state.fields = newFields;
};

@@ -114,37 +112,2 @@

function moveFields(name, matchPrefix, destIndex, state) {
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, matchPrefix.length) === matchPrefix) {
var suffix = key.substring(matchPrefix.length);
var destKey = name + "[" + destIndex + "]" + suffix;
moveFieldState(state, state.fields[key], destKey);
}
});
}
//
function restoreFunctions(state, backupState) {
Object.keys(state.fields).forEach(function (key) {
state.fields[key] = _extends({}, state.fields[key], {
change: state.fields[key].change || backupState.fields[key] && backupState.fields[key].change,
blur: state.fields[key].blur || backupState.fields[key] && backupState.fields[key].blur,
focus: state.fields[key].focus || backupState.fields[key] && backupState.fields[key].focus
});
if (!state.fields[key].change) {
delete state.fields[key].change;
}
if (!state.fields[key].blur) {
delete state.fields[key].blur;
}
if (!state.fields[key].focus) {
delete state.fields[key].focus;
}
});
}
var TMP = 'tmp';
var move = function move(_ref, state, _ref2) {

@@ -166,76 +129,49 @@ var name = _ref[0],

return copy;
}); //make a copy of a state for further functions restore
var backupState = _extends({}, state, {
fields: _extends({}, state.fields) // move this row to tmp index
});
var newFields = {};
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var lowest;
var highest;
var increment;
var fromPrefix = name + "[" + from + "]";
moveFields(name, fromPrefix, TMP, state);
if (from < to) {
// moving to a higher index
// decrement all indices between from and to
for (var i = from + 1; i <= to; i++) {
var innerFromPrefix = name + "[" + i + "]";
moveFields(name, innerFromPrefix, "" + (i - 1), state);
}
if (from > to) {
lowest = to;
highest = from;
increment = 1;
} else {
// moving to a lower index
// increment all indices between to and from
for (var _i = from - 1; _i >= to; _i--) {
var _innerFromPrefix = name + "[" + _i + "]";
lowest = from;
highest = to;
increment = -1;
}
moveFields(name, _innerFromPrefix, "" + (_i + 1), state);
}
} // move from tmp index to destination
Object.keys(state.fields).forEach(function (key) {
var tokens = pattern.exec(key);
if (tokens) {
var fieldIndex = Number(tokens[1]);
var tmpPrefix = name + "[" + TMP + "]";
moveFields(name, tmpPrefix, to, state);
restoreFunctions(state, backupState);
};
//
var pop = function pop(_ref, state, _ref2) {
var name = _ref[0];
var changeValue = _ref2.changeValue;
var result;
var removedIndex;
changeValue(state, name, function (array) {
if (array) {
if (!array.length) {
return [];
if (fieldIndex === from) {
var newKey = name + "[" + to + "]" + tokens[2];
copyField(state.fields, key, newFields, newKey);
return;
}
removedIndex = array.length - 1;
result = array[removedIndex];
return array.slice(0, removedIndex);
}
}); // now we have to remove any subfields for our index,
if (lowest <= fieldIndex && fieldIndex <= highest) {
// Shift all indices
var _newKey = name + "[" + (fieldIndex + increment) + "]" + tokens[2];
if (removedIndex !== undefined) {
var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[" + removedIndex + "].*");
Object.keys(state.fields).forEach(function (key) {
if (pattern.test(key)) {
delete state.fields[key];
copyField(state.fields, key, newFields, _newKey);
return;
}
});
}
} // Keep this field that does not match the name,
// or has index smaller or larger than affected range
return result;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
newFields[key] = state.fields[key];
});
state.fields = newFields;
};
//
var remove = function remove(_ref, state, _ref2) {

@@ -245,9 +181,14 @@ var name = _ref[0],

var changeValue = _ref2.changeValue,
renameField = _ref2.renameField;
getIn = _ref2.getIn,
setIn = _ref2.setIn;
var returnValue;
changeValue(state, name, function (array) {
var copy = [].concat(array || []);
if (!array) {
return array;
}
var copy = [].concat(array);
returnValue = copy[index];
copy.splice(index, 1);
return copy;
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our index,

@@ -257,7 +198,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var backup = _extends({}, state, {
fields: _extends({}, state.fields)
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -270,27 +207,77 @@ var tokens = pattern.exec(key);

if (fieldIndex === index) {
// delete any subfields for this array item
delete state.fields[key];
} else if (fieldIndex > index) {
// shift all higher ones down
delete state.fields[key];
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
// delete any submitErrors for this array item
// if the root key of the delete index
if (key === name + "[" + index + "]") {
var path = "formState.submitErrors." + name;
var submitErrors = getIn(state, path); // if has submitErrors for array
if (backup.fields[decrementedKey]) {
moveFieldState(state, backup.fields[key], decrementedKey, backup);
} else {
// take care of setting the correct change, blur, focus, validators on new field
renameField(state, key, decrementedKey);
if (Array.isArray(submitErrors)) {
submitErrors.splice(index, 1);
state = setIn(state, path, submitErrors);
}
}
return;
}
}
if (fieldIndex > index) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newFields;
return returnValue;
};
var countBelow = function countBelow(array, value) {
return array.reduce(function (count, item) {
return item < value ? count + 1 : count;
}, 0);
//
var pop = function pop(_ref, state, tools) {
var name = _ref[0];
var getIn = tools.getIn;
var array = getIn(state.formState.values, name);
return array && array.length > 0 ? remove([name, array.length - 1], state, tools) : undefined;
};
//
var push = function push(_ref, state, _ref2) {
var name = _ref[0],
value = _ref[1];
var changeValue = _ref2.changeValue;
changeValue(state, name, function (array) {
return array ? [].concat(array, [value]) : [value];
});
};
//
var binarySearch = function binarySearch(list, value) {
// This algorithm assumes the items in list is unique
var first = 0;
var last = list.length - 1;
var middle = 0;
while (first <= last) {
middle = Math.floor((first + last) / 2);
if (list[middle] === value) {
return middle;
}
if (list[middle] > value) {
last = middle - 1;
} else {
first = middle + 1;
}
}
return ~first;
};
var removeBatch = function removeBatch(_ref, state, _ref2) {

@@ -300,8 +287,13 @@ var name = _ref[0],

var changeValue = _ref2.changeValue;
if (indexes.length === 0) {
return [];
}
var sortedIndexes = [].concat(indexes);
sortedIndexes.sort(); // remove duplicates
sortedIndexes.sort(); // Remove duplicates
for (var i = 0; i < sortedIndexes.length; i++) {
if (i > 0 && sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i--, 1);
for (var i = sortedIndexes.length - 1; i > 0; i -= 1) {
if (sortedIndexes[i] === sortedIndexes[i - 1]) {
sortedIndexes.splice(i, 1);
}

@@ -317,3 +309,3 @@ }

if (!array || !sortedIndexes.length) {
if (!array) {
return array;

@@ -323,8 +315,9 @@ }

var copy = [].concat(array);
var removed = [];
sortedIndexes.forEach(function (index) {
copy.splice(index - removed.length, 1);
removed.push(array && array[index]);
});
return copy;
for (var _i = sortedIndexes.length - 1; _i >= 0; _i -= 1) {
var index = sortedIndexes[_i];
copy.splice(index, 1);
}
return copy.length > 0 ? copy : undefined;
}); // now we have to remove any subfields for our indexes,

@@ -334,7 +327,3 @@ // and decrement all higher indexes.

var pattern = new RegExp("^" + escapeRegexTokens(name) + "\\[(\\d+)\\](.*)");
var newState = _extends({}, state, {
fields: {}
});
var newFields = {};
Object.keys(state.fields).forEach(function (key) {

@@ -345,14 +334,22 @@ var tokens = pattern.exec(key);

var fieldIndex = Number(tokens[1]);
var indexOfFieldIndex = binarySearch(sortedIndexes, fieldIndex);
if (!~sortedIndexes.indexOf(fieldIndex)) {
// not one of the removed indexes
// shift all higher ones down
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2];
moveFieldState(newState, state.fields[key], decrementedKey, state);
if (indexOfFieldIndex >= 0) {
// One of the removed indices
return;
}
} else {
newState.fields[key] = state.fields[key];
}
if (fieldIndex > sortedIndexes[0]) {
// Shift all higher indices down
var decrementedKey = name + "[" + (fieldIndex - ~indexOfFieldIndex) + "]" + tokens[2];
copyField(state.fields, key, newFields, decrementedKey);
return;
}
} // Keep this field that does not match the name,
// or has index smaller than what is being removed
newFields[key] = state.fields[key];
});
state.fields = newState.fields;
state.fields = newFields;
return returnValue;

@@ -368,3 +365,3 @@ };

var TMP$1 = 'tmp';
//

@@ -387,16 +384,24 @@ var swap = function swap(_ref, state, _ref2) {

return copy;
}); //make a copy of a state for further functions restore
}); // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var backupState = _extends({}, state, {
fields: _extends({}, state.fields) // swap all field state that begin with "name[indexA]" with that under "name[indexB]"
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var newFields = {};
Object.keys(state.fields).forEach(function (key) {
if (key.substring(0, aPrefix.length) === aPrefix) {
var suffix = key.substring(aPrefix.length);
var newKey = bPrefix + suffix;
copyField(state.fields, key, newFields, newKey);
} else if (key.substring(0, bPrefix.length) === bPrefix) {
var _suffix = key.substring(bPrefix.length);
var _newKey = aPrefix + _suffix;
copyField(state.fields, key, newFields, _newKey);
} else {
// Keep this field that does not match the name
newFields[key] = state.fields[key];
}
});
var aPrefix = name + "[" + indexA + "]";
var bPrefix = name + "[" + indexB + "]";
var tmpPrefix = name + "[" + TMP$1 + "]";
moveFields(name, aPrefix, TMP$1, state);
moveFields(name, bPrefix, indexA, state);
moveFields(name, tmpPrefix, indexB, state);
restoreFunctions(state, backupState);
state.fields = newFields;
};

@@ -403,0 +408,0 @@

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self)["final-form-arrays"]={})}(this,function(e){"use strict";function o(){return(o=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var f=arguments[n];for(var i in f)Object.prototype.hasOwnProperty.call(f,i)&&(e[i]=f[i])}return e}).apply(this,arguments)}function d(e,n,f,i){void 0===i&&(i=e),delete e.fields[n.name],e.fields[f]=o({},n,{name:f,change:i.fields[f]&&i.fields[f].change,blur:i.fields[f]&&i.fields[f].blur,focus:i.fields[f]&&i.fields[f].focus,lastFieldState:void 0}),e.fields[f].change||delete e.fields[f].change,e.fields[f].blur||delete e.fields[f].blur,e.fields[f].focus||delete e.fields[f].focus}function v(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function r(e,t,n){var r=e[0],c=e[1],f=e[2],i=n.changeValue;n.resetFieldState,i(t,r,function(e){var n=[].concat(e||[]);return n.splice(c,0,f),n});var l=o({},t.fields),s=new RegExp("^"+v(r)+"\\[(\\d+)\\](.*)");Object.keys(t.fields).sort().reverse().forEach(function(e){var n=s.exec(e);if(n){var f=Number(n[1]);if(c<=f){var i=r+"["+(f+1)+"]"+n[2];d(t,l[e],i)}}})}function u(i,t,r,c){Object.keys(c.fields).forEach(function(e){if(e.substring(0,t.length)===t){var n=e.substring(t.length),f=i+"["+r+"]"+n;d(c,c.fields[e],f)}})}function h(n,f){Object.keys(n.fields).forEach(function(e){n.fields[e]=o({},n.fields[e],{change:n.fields[e].change||f.fields[e]&&f.fields[e].change,blur:n.fields[e].blur||f.fields[e]&&f.fields[e].blur,focus:n.fields[e].focus||f.fields[e]&&f.fields[e].focus}),n.fields[e].change||delete n.fields[e].change,n.fields[e].blur||delete n.fields[e].blur,n.fields[e].focus||delete n.fields[e].focus})}function t(e,t,n){var f,r=e[0],c=e[1],i=n.changeValue,l=n.renameField;i(t,r,function(e){var n=[].concat(e||[]);return f=n[c],n.splice(c,1),n});var s=new RegExp("^"+v(r)+"\\[(\\d+)\\](.*)"),a=o({},t,{fields:o({},t.fields)});return Object.keys(t.fields).forEach(function(e){var n=s.exec(e);if(n){var f=Number(n[1]);if(f===c)delete t.fields[e];else if(c<f){delete t.fields[e];var i=r+"["+(f-1)+"]"+n[2];a.fields[i]?d(t,a.fields[e],i,a):l(t,e,i)}}}),f}var n={insert:r,concat:function(e,n,f){var i=e[0],t=e[1];(0,f.changeValue)(n,i,function(e){return e?[].concat(e,t):t})},move:function(e,n,f){var i=e[0],t=e[1],r=e[2],c=f.changeValue;if(t!==r){c(n,i,function(e){var n=[].concat(e||[]),f=n[t];return n.splice(t,1),n.splice(r,0,f),n});var l=o({},n,{fields:o({},n.fields)});if(u(i,i+"["+t+"]","tmp",n),t<r)for(var s=t+1;s<=r;s++){u(i,i+"["+s+"]",""+(s-1),n)}else for(var a=t-1;r<=a;a--){u(i,i+"["+a+"]",""+(a+1),n)}u(i,i+"[tmp]",r,n),h(n,l)}},pop:function(e,n,f){var i,t,r=e[0];if((0,f.changeValue)(n,r,function(e){if(e)return e.length?(t=e.length-1,i=e[t],e.slice(0,t)):[]}),void 0!==t){var c=new RegExp("^"+v(r)+"\\["+t+"].*");Object.keys(n.fields).forEach(function(e){c.test(e)&&delete n.fields[e]})}return i},push:function(e,n,f){var i=e[0],t=e[1];(0,f.changeValue)(n,i,function(e){return e?[].concat(e,[t]):[t]})},remove:t,removeBatch:function(e,t,n){var r=e[0],c=e[1],f=n.changeValue,l=[].concat(c);l.sort();for(var i=0;i<l.length;i++)0<i&&l[i]===l[i-1]&&l.splice(i--,1);var s=[];f(t,r,function(n){if(s=c.map(function(e){return n&&n[e]}),!n||!l.length)return n;var f=[].concat(n),i=[];return l.forEach(function(e){f.splice(e-i.length,1),i.push(n&&n[e])}),f});var a=new RegExp("^"+v(r)+"\\[(\\d+)\\](.*)"),u=o({},t,{fields:{}});return Object.keys(t.fields).forEach(function(e){var n=a.exec(e);if(n){var f=Number(n[1]);if(!~l.indexOf(f)){var i=r+"["+(f-function(e,f){return e.reduce(function(e,n){return n<f?e+1:e},0)}(l,f))+"]"+n[2];d(u,t.fields[e],i,t)}}else u.fields[e]=t.fields[e]}),t.fields=u.fields,s},shift:function(e,n,f){var i=e[0];return t([i,0],n,f)},swap:function(e,n,f){var i=e[0],t=e[1],r=e[2],c=f.changeValue;if(t!==r){c(n,i,function(e){var n=[].concat(e||[]),f=n[t];return n[t]=n[r],n[r]=f,n});var l=o({},n,{fields:o({},n.fields)}),s=i+"["+r+"]",a=i+"[tmp]";u(i,i+"["+t+"]","tmp",n),u(i,s,t,n),u(i,a,r,n),h(n,l)}},unshift:function(e,n,f){var i=e[0],t=e[1];return r([i,0,t],n,f)},update:function(e,n,f){var i=e[0],t=e[1],r=e[2];(0,f.changeValue)(n,i,function(e){var n=[].concat(e||[]);return n.splice(t,1,r),n})}};e.default=n,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self)["final-form-arrays"]={})}(this,function(e){"use strict";function i(){return(i=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function h(e,n,r,t){r[t]=i({},e[n],{name:t,change:e[t]&&e[t].change,blur:e[t]&&e[t].blur,focus:e[t]&&e[t].focus,lastFieldState:void 0}),r[t].change||delete r[t].change,r[t].blur||delete r[t].blur,r[t].focus||delete r[t].focus}function g(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function a(e,i,n){var a=e[0],f=e[1],r=e[2];(0,n.changeValue)(i,a,function(e){var n=[].concat(e||[]);return n.splice(f,0,r),n});var c=new RegExp("^"+g(a)+"\\[(\\d+)\\](.*)"),u={};Object.keys(i.fields).forEach(function(e){var n=c.exec(e);if(n){var r=Number(n[1]);if(f<=r){var t=a+"["+(r+1)+"]"+n[2];return void h(i.fields,e,u,t)}}u[e]=i.fields[e]}),i.fields=u}function f(e,f,n){var r,c=e[0],u=e[1],t=n.changeValue,o=n.getIn,l=n.setIn;t(f,c,function(e){if(!e)return e;var n=[].concat(e);return r=n[u],n.splice(u,1),0<n.length?n:void 0});var s=new RegExp("^"+g(c)+"\\[(\\d+)\\](.*)"),v={};return Object.keys(f.fields).forEach(function(e){var n=s.exec(e);if(n){var r=Number(n[1]);if(r===u){if(e===c+"["+u+"]"){var t="formState.submitErrors."+c,i=o(f,t);Array.isArray(i)&&(i.splice(u,1),f=l(f,t,i))}return}if(u<r){var a=c+"["+(r-1)+"]"+n[2];return void h(f.fields,e,v,a)}}v[e]=f.fields[e]}),f.fields=v,r}var n={insert:a,concat:function(e,n,r){var t=e[0],i=e[1];(0,r.changeValue)(n,t,function(e){return e?[].concat(e,i):i})},move:function(e,a,n){var f=e[0],c=e[1],u=e[2],r=n.changeValue;if(c!==u){r(a,f,function(e){var n=[].concat(e||[]),r=n[c];return n.splice(c,1),n.splice(u,0,r),n});var o,l,s,v={},d=new RegExp("^"+g(f)+"\\[(\\d+)\\](.*)");s=u<c?(o=u,l=c,1):(o=c,l=u,-1),Object.keys(a.fields).forEach(function(e){var n=d.exec(e);if(n){var r=Number(n[1]);if(r===c){var t=f+"["+u+"]"+n[2];return void h(a.fields,e,v,t)}if(o<=r&&r<=l){var i=f+"["+(r+s)+"]"+n[2];return void h(a.fields,e,v,i)}}v[e]=a.fields[e]}),a.fields=v}},pop:function(e,n,r){var t=e[0],i=(0,r.getIn)(n.formState.values,t);return i&&0<i.length?f([t,i.length-1],n,r):void 0},push:function(e,n,r){var t=e[0],i=e[1];(0,r.changeValue)(n,t,function(e){return e?[].concat(e,[i]):[i]})},remove:f,removeBatch:function(e,a,n){var f=e[0],i=e[1],r=n.changeValue;if(0===i.length)return[];var c=[].concat(i);c.sort();for(var t=c.length-1;0<t;t-=1)c[t]===c[t-1]&&c.splice(t,1);var u=[];r(a,f,function(n){if(u=i.map(function(e){return n&&n[e]}),!n)return n;for(var e=[].concat(n),r=c.length-1;0<=r;r-=1){var t=c[r];e.splice(t,1)}return 0<e.length?e:void 0});var o=new RegExp("^"+g(f)+"\\[(\\d+)\\](.*)"),l={};return Object.keys(a.fields).forEach(function(e){var n=o.exec(e);if(n){var r=Number(n[1]),t=function(e,n){for(var r=0,t=e.length-1,i=0;r<=t;){if(e[i=Math.floor((r+t)/2)]===n)return i;e[i]>n?t=i-1:r=i+1}return~r}(c,r);if(0<=t)return;if(r>c[0]){var i=f+"["+(r-~t)+"]"+n[2];return void h(a.fields,e,l,i)}}l[e]=a.fields[e]}),a.fields=l,u},shift:function(e,n,r){var t=e[0];return f([t,0],n,r)},swap:function(e,a,n){var r=e[0],t=e[1],i=e[2],f=n.changeValue;if(t!==i){f(a,r,function(e){var n=[].concat(e||[]),r=n[t];return n[t]=n[i],n[i]=r,n});var c=r+"["+t+"]",u=r+"["+i+"]",o={};Object.keys(a.fields).forEach(function(e){if(e.substring(0,c.length)===c){var n=e.substring(c.length),r=u+n;h(a.fields,e,o,r)}else if(e.substring(0,u.length)===u){var t=e.substring(u.length),i=c+t;h(a.fields,e,o,i)}else o[e]=a.fields[e]}),a.fields=o}},unshift:function(e,n,r){var t=e[0],i=e[1];return a([t,0,i],n,r)},update:function(e,n,r){var t=e[0],i=e[1],a=e[2];(0,r.changeValue)(n,t,function(e){var n=[].concat(e||[]);return n.splice(i,1,a),n})}};e.default=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=final-form-arrays.umd.min.js.map
{
"name": "final-form-arrays",
"version": "3.0.2",
"version": "3.1.0",
"description": "Array Mutators for 🏁 Final Form",

@@ -55,3 +55,3 @@ "main": "dist/final-form-arrays.cjs.js",

"eslint-plugin-react": "^7.13.0",
"final-form": "^4.18.2",
"final-form": "^4.20.8",
"flow-bin": "^0.102.0",

@@ -77,3 +77,3 @@ "glow": "^1.2.2",

"peerDependencies": {
"final-form": "^4.18.2"
"final-form": "^4.20.8"
},

@@ -80,0 +80,0 @@ "lint-staged": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc