final-form-arrays
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -32,2 +32,20 @@ 'use strict'; | ||
// | ||
function moveFieldState(state, source, destKey, oldState) { | ||
if (oldState === void 0) { | ||
oldState = state; | ||
} | ||
state.fields[destKey] = _extends_1({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] 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, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
var insert = function insert(_ref, state, _ref2) { | ||
@@ -46,3 +64,5 @@ var name = _ref[0], | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var changes = {}; | ||
var backup = _extends_1({}, state.fields); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -57,6 +77,3 @@ var tokens = pattern.exec(key); | ||
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2]; | ||
changes[incrementedKey] = _extends_1({}, state.fields[key]); // make copy of field state | ||
changes[incrementedKey].name = incrementedKey; | ||
changes[incrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup[key], incrementedKey); | ||
} | ||
@@ -69,3 +86,2 @@ | ||
}); | ||
state.fields = _extends_1({}, state.fields, {}, changes); | ||
}; | ||
@@ -84,2 +100,3 @@ | ||
// | ||
var move = function move(_ref, state, _ref2) { | ||
@@ -114,6 +131,3 @@ var name = _ref[0], | ||
var destKey = name + "[" + i + "]" + suffix; | ||
moveFieldState({ | ||
destKey: destKey, | ||
source: state.fields[name + "[" + (i + 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (i + 1) + "]" + suffix], destKey); | ||
} | ||
@@ -126,6 +140,3 @@ } else { | ||
moveFieldState({ | ||
destKey: _destKey, | ||
source: state.fields[name + "[" + (_i - 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (_i - 1) + "]" + suffix], _destKey); | ||
} | ||
@@ -135,24 +146,5 @@ } | ||
var toKey = name + "[" + to + "]" + suffix; | ||
moveFieldState({ | ||
destKey: toKey, | ||
source: backup | ||
}); | ||
moveFieldState(state, backup, toKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends_1({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] does not exist, it will be created | ||
// when that field gets registered, with its own change/blur/focus callbacks | ||
change: state.fields[destKey] && state.fields[destKey].change, | ||
blur: state.fields[destKey] && state.fields[destKey].blur, | ||
focus: state.fields[destKey] && state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -200,3 +192,2 @@ | ||
// | ||
var remove = function remove(_ref, state, _ref2) { | ||
@@ -217,3 +208,5 @@ var name = _ref[0], | ||
var backup = _extends_1({}, state.fields); | ||
var backup = _extends_1({}, state, { | ||
fields: _extends_1({}, state.fields) | ||
}); | ||
@@ -233,5 +226,3 @@ Object.keys(state.fields).forEach(function (key) { | ||
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2]; | ||
state.fields[decrementedKey] = backup[key]; | ||
state.fields[decrementedKey].name = decrementedKey; | ||
state.fields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup.fields[key], decrementedKey, backup); | ||
} | ||
@@ -243,3 +234,2 @@ } | ||
// | ||
var countBelow = function countBelow(array, value) { | ||
@@ -286,3 +276,7 @@ return array.reduce(function (count, item) { | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var newFields = {}; | ||
var newState = _extends_1({}, state, { | ||
fields: {} | ||
}); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -298,11 +292,9 @@ var tokens = pattern.exec(key); | ||
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2]; | ||
newFields[decrementedKey] = state.fields[key]; | ||
newFields[decrementedKey].name = decrementedKey; | ||
newFields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(newState, state.fields[key], decrementedKey, state); | ||
} | ||
} else { | ||
newFields[key] = state.fields[key]; | ||
newState.fields[key] = state.fields[key]; | ||
} | ||
}); | ||
state.fields = newFields; | ||
state.fields = newState.fields; | ||
return returnValue; | ||
@@ -319,2 +311,3 @@ }; | ||
// | ||
var swap = function swap(_ref, state, _ref2) { | ||
@@ -346,26 +339,6 @@ var name = _ref[0], | ||
var fieldA = state.fields[aKey]; | ||
moveFieldState({ | ||
destKey: aKey, | ||
source: state.fields[bKey] | ||
}); | ||
moveFieldState({ | ||
destKey: bKey, | ||
source: fieldA | ||
}); | ||
moveFieldState(state, state.fields[bKey], aKey); | ||
moveFieldState(state, fieldA, bKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends_1({}, source, { | ||
name: destKey, | ||
change: state.fields[destKey].change, | ||
// prevent functions from being overwritten | ||
blur: state.fields[destKey].blur, | ||
focus: state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -372,0 +345,0 @@ |
@@ -20,2 +20,20 @@ function _extends() { | ||
// | ||
function moveFieldState(state, source, destKey, oldState) { | ||
if (oldState === void 0) { | ||
oldState = state; | ||
} | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] 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, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
var insert = function insert(_ref, state, _ref2) { | ||
@@ -34,3 +52,5 @@ var name = _ref[0], | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var changes = {}; | ||
var backup = _extends({}, state.fields); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -45,6 +65,3 @@ var tokens = pattern.exec(key); | ||
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2]; | ||
changes[incrementedKey] = _extends({}, state.fields[key]); // make copy of field state | ||
changes[incrementedKey].name = incrementedKey; | ||
changes[incrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup[key], incrementedKey); | ||
} | ||
@@ -57,3 +74,2 @@ | ||
}); | ||
state.fields = _extends({}, state.fields, {}, changes); | ||
}; | ||
@@ -72,2 +88,3 @@ | ||
// | ||
var move = function move(_ref, state, _ref2) { | ||
@@ -102,6 +119,3 @@ var name = _ref[0], | ||
var destKey = name + "[" + i + "]" + suffix; | ||
moveFieldState({ | ||
destKey: destKey, | ||
source: state.fields[name + "[" + (i + 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (i + 1) + "]" + suffix], destKey); | ||
} | ||
@@ -114,6 +128,3 @@ } else { | ||
moveFieldState({ | ||
destKey: _destKey, | ||
source: state.fields[name + "[" + (_i - 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (_i - 1) + "]" + suffix], _destKey); | ||
} | ||
@@ -123,24 +134,5 @@ } | ||
var toKey = name + "[" + to + "]" + suffix; | ||
moveFieldState({ | ||
destKey: toKey, | ||
source: backup | ||
}); | ||
moveFieldState(state, backup, toKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] does not exist, it will be created | ||
// when that field gets registered, with its own change/blur/focus callbacks | ||
change: state.fields[destKey] && state.fields[destKey].change, | ||
blur: state.fields[destKey] && state.fields[destKey].blur, | ||
focus: state.fields[destKey] && state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -188,3 +180,2 @@ | ||
// | ||
var remove = function remove(_ref, state, _ref2) { | ||
@@ -205,3 +196,5 @@ var name = _ref[0], | ||
var backup = _extends({}, state.fields); | ||
var backup = _extends({}, state, { | ||
fields: _extends({}, state.fields) | ||
}); | ||
@@ -221,5 +214,3 @@ Object.keys(state.fields).forEach(function (key) { | ||
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2]; | ||
state.fields[decrementedKey] = backup[key]; | ||
state.fields[decrementedKey].name = decrementedKey; | ||
state.fields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup.fields[key], decrementedKey, backup); | ||
} | ||
@@ -231,3 +222,2 @@ } | ||
// | ||
var countBelow = function countBelow(array, value) { | ||
@@ -274,3 +264,7 @@ return array.reduce(function (count, item) { | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var newFields = {}; | ||
var newState = _extends({}, state, { | ||
fields: {} | ||
}); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -286,11 +280,9 @@ var tokens = pattern.exec(key); | ||
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2]; | ||
newFields[decrementedKey] = state.fields[key]; | ||
newFields[decrementedKey].name = decrementedKey; | ||
newFields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(newState, state.fields[key], decrementedKey, state); | ||
} | ||
} else { | ||
newFields[key] = state.fields[key]; | ||
newState.fields[key] = state.fields[key]; | ||
} | ||
}); | ||
state.fields = newFields; | ||
state.fields = newState.fields; | ||
return returnValue; | ||
@@ -307,2 +299,3 @@ }; | ||
// | ||
var swap = function swap(_ref, state, _ref2) { | ||
@@ -334,26 +327,6 @@ var name = _ref[0], | ||
var fieldA = state.fields[aKey]; | ||
moveFieldState({ | ||
destKey: aKey, | ||
source: state.fields[bKey] | ||
}); | ||
moveFieldState({ | ||
destKey: bKey, | ||
source: fieldA | ||
}); | ||
moveFieldState(state, state.fields[bKey], aKey); | ||
moveFieldState(state, fieldA, bKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
change: state.fields[destKey].change, | ||
// prevent functions from being overwritten | ||
blur: state.fields[destKey].blur, | ||
focus: state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -360,0 +333,0 @@ |
@@ -26,2 +26,20 @@ (function (global, factory) { | ||
// | ||
function moveFieldState(state, source, destKey, oldState) { | ||
if (oldState === void 0) { | ||
oldState = state; | ||
} | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] 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, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
var insert = function insert(_ref, state, _ref2) { | ||
@@ -40,3 +58,5 @@ var name = _ref[0], | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var changes = {}; | ||
var backup = _extends({}, state.fields); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -51,6 +71,3 @@ var tokens = pattern.exec(key); | ||
var incrementedKey = name + "[" + (fieldIndex + 1) + "]" + tokens[2]; | ||
changes[incrementedKey] = _extends({}, state.fields[key]); // make copy of field state | ||
changes[incrementedKey].name = incrementedKey; | ||
changes[incrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup[key], incrementedKey); | ||
} | ||
@@ -63,3 +80,2 @@ | ||
}); | ||
state.fields = _extends({}, state.fields, {}, changes); | ||
}; | ||
@@ -78,2 +94,3 @@ | ||
// | ||
var move = function move(_ref, state, _ref2) { | ||
@@ -108,6 +125,3 @@ var name = _ref[0], | ||
var destKey = name + "[" + i + "]" + suffix; | ||
moveFieldState({ | ||
destKey: destKey, | ||
source: state.fields[name + "[" + (i + 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (i + 1) + "]" + suffix], destKey); | ||
} | ||
@@ -120,6 +134,3 @@ } else { | ||
moveFieldState({ | ||
destKey: _destKey, | ||
source: state.fields[name + "[" + (_i - 1) + "]" + suffix] | ||
}); | ||
moveFieldState(state, state.fields[name + "[" + (_i - 1) + "]" + suffix], _destKey); | ||
} | ||
@@ -129,24 +140,5 @@ } | ||
var toKey = name + "[" + to + "]" + suffix; | ||
moveFieldState({ | ||
destKey: toKey, | ||
source: backup | ||
}); | ||
moveFieldState(state, backup, toKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
// prevent functions from being overwritten | ||
// if the state.fields[destKey] does not exist, it will be created | ||
// when that field gets registered, with its own change/blur/focus callbacks | ||
change: state.fields[destKey] && state.fields[destKey].change, | ||
blur: state.fields[destKey] && state.fields[destKey].blur, | ||
focus: state.fields[destKey] && state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -194,3 +186,2 @@ | ||
// | ||
var remove = function remove(_ref, state, _ref2) { | ||
@@ -211,3 +202,5 @@ var name = _ref[0], | ||
var backup = _extends({}, state.fields); | ||
var backup = _extends({}, state, { | ||
fields: _extends({}, state.fields) | ||
}); | ||
@@ -227,5 +220,3 @@ Object.keys(state.fields).forEach(function (key) { | ||
var decrementedKey = name + "[" + (fieldIndex - 1) + "]" + tokens[2]; | ||
state.fields[decrementedKey] = backup[key]; | ||
state.fields[decrementedKey].name = decrementedKey; | ||
state.fields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(state, backup.fields[key], decrementedKey, backup); | ||
} | ||
@@ -237,3 +228,2 @@ } | ||
// | ||
var countBelow = function countBelow(array, value) { | ||
@@ -280,3 +270,7 @@ return array.reduce(function (count, item) { | ||
var pattern = new RegExp("^" + name + "\\[(\\d+)\\](.*)"); | ||
var newFields = {}; | ||
var newState = _extends({}, state, { | ||
fields: {} | ||
}); | ||
Object.keys(state.fields).forEach(function (key) { | ||
@@ -292,11 +286,9 @@ var tokens = pattern.exec(key); | ||
var decrementedKey = name + "[" + (fieldIndex - countBelow(sortedIndexes, fieldIndex)) + "]" + tokens[2]; | ||
newFields[decrementedKey] = state.fields[key]; | ||
newFields[decrementedKey].name = decrementedKey; | ||
newFields[decrementedKey].lastFieldState = undefined; | ||
moveFieldState(newState, state.fields[key], decrementedKey, state); | ||
} | ||
} else { | ||
newFields[key] = state.fields[key]; | ||
newState.fields[key] = state.fields[key]; | ||
} | ||
}); | ||
state.fields = newFields; | ||
state.fields = newState.fields; | ||
return returnValue; | ||
@@ -313,2 +305,3 @@ }; | ||
// | ||
var swap = function swap(_ref, state, _ref2) { | ||
@@ -340,26 +333,6 @@ var name = _ref[0], | ||
var fieldA = state.fields[aKey]; | ||
moveFieldState({ | ||
destKey: aKey, | ||
source: state.fields[bKey] | ||
}); | ||
moveFieldState({ | ||
destKey: bKey, | ||
source: fieldA | ||
}); | ||
moveFieldState(state, state.fields[bKey], aKey); | ||
moveFieldState(state, fieldA, bKey); | ||
} | ||
}); | ||
function moveFieldState(_ref3) { | ||
var destKey = _ref3.destKey, | ||
source = _ref3.source; | ||
state.fields[destKey] = _extends({}, source, { | ||
name: destKey, | ||
change: state.fields[destKey].change, | ||
// prevent functions from being overwritten | ||
blur: state.fields[destKey].blur, | ||
focus: state.fields[destKey].focus, | ||
lastFieldState: undefined // clearing lastFieldState forces renotification | ||
}); | ||
} | ||
}; | ||
@@ -366,0 +339,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 d(){return(d=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function f(e,i,n){var f=e[0],a=e[1],t=e[2],r=n.changeValue,c=n.resetFieldState;r(i,f,function(e){var n=[].concat(e||[]);return n.splice(a,0,t),n});var s=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),u={};Object.keys(i.fields).forEach(function(e){var n=s.exec(e);if(n){var t=Number(n[1]);if(a<=t){var r=f+"["+(t+1)+"]"+n[2];u[r]=d({},i.fields[e]),u[r].name=r,u[r].lastFieldState=void 0}t===a&&c(e)}}),i.fields=d({},i.fields,{},u)}function i(e,i,n){var t,f=e[0],a=e[1];(0,n.changeValue)(i,f,function(e){var n=[].concat(e||[]);return t=n[a],n.splice(a,1),n});var c=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),s=d({},i.fields);return Object.keys(i.fields).forEach(function(e){var n=c.exec(e);if(n){var t=Number(n[1]);if(t===a)delete i.fields[e];else if(a<t){delete i.fields[e];var r=f+"["+(t-1)+"]"+n[2];i.fields[r]=s[e],i.fields[r].name=r,i.fields[r].lastFieldState=void 0}}}),t}var n={insert:f,concat:function(e,n,t){var r=e[0],i=e[1];(0,t.changeValue)(n,r,function(e){return e?[].concat(e,i):i})},move:function(e,a,n){var c=e[0],s=e[1],u=e[2],t=n.changeValue;if(s!==u){t(a,c,function(e){var n=[].concat(e||[]),t=n[s];return n.splice(s,1),n.splice(u,0,t),n});var o=c+"["+s+"]";Object.keys(a.fields).forEach(function(e){if(e.substring(0,o.length)===o){var n=e.substring(o.length),t=o+n,r=a.fields[t];if(s<u)for(var i=s;i<u;i++){l({destKey:c+"["+i+"]"+n,source:a.fields[c+"["+(i+1)+"]"+n]})}else for(var f=s;u<f;f--){l({destKey:c+"["+f+"]"+n,source:a.fields[c+"["+(f-1)+"]"+n]})}l({destKey:c+"["+u+"]"+n,source:r})}})}function l(e){var n=e.destKey,t=e.source;a.fields[n]=d({},t,{name:n,change:a.fields[n]&&a.fields[n].change,blur:a.fields[n]&&a.fields[n].blur,focus:a.fields[n]&&a.fields[n].focus,lastFieldState:void 0})}},pop:function(e,n,t){var r,i,f=e[0];if((0,t.changeValue)(n,f,function(e){if(e)return e.length?(i=e.length-1,r=e[i],e.slice(0,i)):[]}),void 0!==i){var a=new RegExp("^"+f+"\\["+i+"].*");Object.keys(n.fields).forEach(function(e){a.test(e)&&delete n.fields[e]})}return r},push:function(e,n,t){var r=e[0],i=e[1];(0,t.changeValue)(n,r,function(e){return e?[].concat(e,[i]):[i]})},remove:i,removeBatch:function(e,i,n){var f=e[0],a=e[1],t=n.changeValue,c=[].concat(a);c.sort();for(var r=0;r<c.length;r++)0<r&&c[r]===c[r-1]&&c.splice(r--,1);var s=[];t(i,f,function(n){if(s=a.map(function(e){return n&&n[e]}),!n||!c.length)return n;var t=[].concat(n),r=[];return c.forEach(function(e){t.splice(e-r.length,1),r.push(n&&n[e])}),t});var u=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),o={};return Object.keys(i.fields).forEach(function(e){var n=u.exec(e);if(n){var t=Number(n[1]);if(!~c.indexOf(t)){var r=f+"["+(t-function(e,t){return e.reduce(function(e,n){return n<t?e+1:e},0)}(c,t))+"]"+n[2];o[r]=i.fields[e],o[r].name=r,o[r].lastFieldState=void 0}}else o[e]=i.fields[e]}),i.fields=o,s},shift:function(e,n,t){var r=e[0];return i([r,0],n,t)},swap:function(e,f,n){var t=e[0],r=e[1],i=e[2],a=n.changeValue;if(r!==i){a(f,t,function(e){var n=[].concat(e||[]),t=n[r];return n[r]=n[i],n[i]=t,n});var c=t+"["+r+"]",s=t+"["+i+"]";Object.keys(f.fields).forEach(function(e){if(e.substring(0,c.length)===c){var n=e.substring(c.length),t=c+n,r=s+n,i=f.fields[t];u({destKey:t,source:f.fields[r]}),u({destKey:r,source:i})}})}function u(e){var n=e.destKey,t=e.source;f.fields[n]=d({},t,{name:n,change:f.fields[n].change,blur:f.fields[n].blur,focus:f.fields[n].focus,lastFieldState:void 0})}},unshift:function(e,n,t){var r=e[0],i=e[1];return f([r,0,i],n,t)},update:function(e,n,t){var r=e[0],i=e[1],f=e[2];(0,t.changeValue)(n,r,function(e){var n=[].concat(e||[]);return n.splice(i,1,f),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 l(){return(l=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 v(e,n,r,t){void 0===t&&(t=e),e.fields[r]=l({},n,{name:r,change:t.fields[r]&&t.fields[r].change,blur:t.fields[r]&&t.fields[r].blur,focus:t.fields[r]&&t.fields[r].focus,lastFieldState:void 0})}function f(e,i,n){var f=e[0],c=e[1],r=e[2],t=n.changeValue,a=n.resetFieldState;t(i,f,function(e){var n=[].concat(e||[]);return n.splice(c,0,r),n});var u=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),o=l({},i.fields);Object.keys(i.fields).forEach(function(e){var n=u.exec(e);if(n){var r=Number(n[1]);if(c<=r){var t=f+"["+(r+1)+"]"+n[2];v(i,o[e],t)}r===c&&a(e)}})}function i(e,i,n){var r,f=e[0],c=e[1];(0,n.changeValue)(i,f,function(e){var n=[].concat(e||[]);return r=n[c],n.splice(c,1),n});var a=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),u=l({},i,{fields:l({},i.fields)});return Object.keys(i.fields).forEach(function(e){var n=a.exec(e);if(n){var r=Number(n[1]);if(r===c)delete i.fields[e];else if(c<r){delete i.fields[e];var t=f+"["+(r-1)+"]"+n[2];v(i,u.fields[e],t,u)}}}),r}var n={insert:f,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,u,n){var o=e[0],s=e[1],l=e[2],r=n.changeValue;if(s!==l){r(u,o,function(e){var n=[].concat(e||[]),r=n[s];return n.splice(s,1),n.splice(l,0,r),n});var d=o+"["+s+"]";Object.keys(u.fields).forEach(function(e){if(e.substring(0,d.length)===d){var n=e.substring(d.length),r=d+n,t=u.fields[r];if(s<l)for(var i=s;i<l;i++){var f=o+"["+i+"]"+n;v(u,u.fields[o+"["+(i+1)+"]"+n],f)}else for(var c=s;l<c;c--){var a=o+"["+c+"]"+n;v(u,u.fields[o+"["+(c-1)+"]"+n],a)}v(u,t,o+"["+l+"]"+n)}})}},pop:function(e,n,r){var t,i,f=e[0];if((0,r.changeValue)(n,f,function(e){if(e)return e.length?(i=e.length-1,t=e[i],e.slice(0,i)):[]}),void 0!==i){var c=new RegExp("^"+f+"\\["+i+"].*");Object.keys(n.fields).forEach(function(e){c.test(e)&&delete n.fields[e]})}return t},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:i,removeBatch:function(e,i,n){var f=e[0],c=e[1],r=n.changeValue,a=[].concat(c);a.sort();for(var t=0;t<a.length;t++)0<t&&a[t]===a[t-1]&&a.splice(t--,1);var u=[];r(i,f,function(n){if(u=c.map(function(e){return n&&n[e]}),!n||!a.length)return n;var r=[].concat(n),t=[];return a.forEach(function(e){r.splice(e-t.length,1),t.push(n&&n[e])}),r});var o=new RegExp("^"+f+"\\[(\\d+)\\](.*)"),s=l({},i,{fields:{}});return Object.keys(i.fields).forEach(function(e){var n=o.exec(e);if(n){var r=Number(n[1]);if(!~a.indexOf(r)){var t=f+"["+(r-function(e,r){return e.reduce(function(e,n){return n<r?e+1:e},0)}(a,r))+"]"+n[2];v(s,i.fields[e],t,i)}}else s.fields[e]=i.fields[e]}),i.fields=s.fields,u},shift:function(e,n,r){var t=e[0];return i([t,0],n,r)},swap:function(e,f,n){var r=e[0],t=e[1],i=e[2],c=n.changeValue;if(t!==i){c(f,r,function(e){var n=[].concat(e||[]),r=n[t];return n[t]=n[i],n[i]=r,n});var a=r+"["+t+"]",u=r+"["+i+"]";Object.keys(f.fields).forEach(function(e){if(e.substring(0,a.length)===a){var n=e.substring(a.length),r=a+n,t=u+n,i=f.fields[r];v(f,f.fields[t],r),v(f,i,t)}})}},unshift:function(e,n,r){var t=e[0],i=e[1];return f([t,0,i],n,r)},update:function(e,n,r){var t=e[0],i=e[1],f=e[2];(0,r.changeValue)(n,t,function(e){var n=[].concat(e||[]);return n.splice(i,1,f),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.0", | ||
"version": "3.0.1", | ||
"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.0", | ||
"final-form": "^4.18.2", | ||
"flow-bin": "^0.102.0", | ||
@@ -77,3 +77,3 @@ "glow": "^1.2.2", | ||
"peerDependencies": { | ||
"final-form": "^4.18.0" | ||
"final-form": "^4.18.2" | ||
}, | ||
@@ -80,0 +80,0 @@ "lint-staged": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44899
970