final-form-arrays
Advanced tools
@@ -5,2 +5,16 @@ 'use strict'; | ||
| var _extends = Object.assign || function (target) { | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| var source = arguments[i]; | ||
| for (var key in source) { | ||
| if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| } | ||
| return target; | ||
| }; | ||
| var slicedToArray = function () { | ||
@@ -44,14 +58,2 @@ function sliceIterator(arr, i) { | ||
| var toConsumableArray = function (arr) { | ||
@@ -96,2 +98,5 @@ if (Array.isArray(arr)) { | ||
| if (from === to) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
@@ -104,2 +109,36 @@ var copy = [].concat(toConsumableArray(array || [])); | ||
| }); | ||
| var fromPrefix = name + "[" + from + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, fromPrefix.length) === fromPrefix) { | ||
| var suffix = key.substring(fromPrefix.length); | ||
| var fromKey = fromPrefix + suffix; | ||
| var backup = state.fields[fromKey]; | ||
| if (from < to) { | ||
| // moving to a higher index | ||
| // decrement all indices between from and to | ||
| for (var i = from; i < to; i++) { | ||
| var destKey = name + "[" + i + "]" + suffix; | ||
| state.fields[destKey] = _extends({}, state.fields[name + "[" + (i + 1) + "]" + suffix], { | ||
| name: destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } else { | ||
| // moving to a lower index | ||
| // increment all indices between to and from | ||
| for (var _i = from; _i > to; _i--) { | ||
| var _destKey = name + "[" + _i + "]" + suffix; | ||
| state.fields[_destKey] = _extends({}, state.fields[name + "[" + (_i - 1) + "]" + suffix], { | ||
| name: _destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } | ||
| var toKey = name + "[" + to + "]" + suffix; | ||
| state.fields[toKey] = _extends({}, backup, { | ||
| name: toKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
@@ -197,2 +236,5 @@ | ||
| if (indexA === indexB) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
@@ -205,2 +247,21 @@ var copy = [].concat(toConsumableArray(array || [])); | ||
| }); | ||
| // swap all field state that begin with "name[indexA]" with that under "name[indexB]" | ||
| var aPrefix = name + "[" + indexA + "]"; | ||
| var bPrefix = name + "[" + indexB + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, aPrefix.length) === aPrefix) { | ||
| var suffix = key.substring(aPrefix.length); | ||
| var aKey = aPrefix + suffix; | ||
| var bKey = bPrefix + suffix; | ||
| var fieldA = state.fields[aKey]; | ||
| state.fields[aKey] = _extends({}, state.fields[bKey], { | ||
| name: aKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| state.fields[bKey] = _extends({}, fieldA, { | ||
| name: bKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
@@ -225,2 +286,20 @@ | ||
| var update = function update(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| index = _ref3[1], | ||
| value = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| copy.splice(index, 1, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| // | ||
| var mutators = { | ||
@@ -234,5 +313,6 @@ insert: insert, | ||
| swap: swap, | ||
| unshift: unshift | ||
| unshift: unshift, | ||
| update: update | ||
| }; | ||
| exports.default = mutators; |
@@ -0,1 +1,15 @@ | ||
| var _extends = Object.assign || function (target) { | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| var source = arguments[i]; | ||
| for (var key in source) { | ||
| if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| } | ||
| return target; | ||
| }; | ||
| var slicedToArray = function () { | ||
@@ -39,14 +53,2 @@ function sliceIterator(arr, i) { | ||
| var toConsumableArray = function (arr) { | ||
@@ -91,2 +93,5 @@ if (Array.isArray(arr)) { | ||
| if (from === to) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
@@ -99,2 +104,36 @@ var copy = [].concat(toConsumableArray(array || [])); | ||
| }); | ||
| var fromPrefix = name + "[" + from + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, fromPrefix.length) === fromPrefix) { | ||
| var suffix = key.substring(fromPrefix.length); | ||
| var fromKey = fromPrefix + suffix; | ||
| var backup = state.fields[fromKey]; | ||
| if (from < to) { | ||
| // moving to a higher index | ||
| // decrement all indices between from and to | ||
| for (var i = from; i < to; i++) { | ||
| var destKey = name + "[" + i + "]" + suffix; | ||
| state.fields[destKey] = _extends({}, state.fields[name + "[" + (i + 1) + "]" + suffix], { | ||
| name: destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } else { | ||
| // moving to a lower index | ||
| // increment all indices between to and from | ||
| for (var _i = from; _i > to; _i--) { | ||
| var _destKey = name + "[" + _i + "]" + suffix; | ||
| state.fields[_destKey] = _extends({}, state.fields[name + "[" + (_i - 1) + "]" + suffix], { | ||
| name: _destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } | ||
| var toKey = name + "[" + to + "]" + suffix; | ||
| state.fields[toKey] = _extends({}, backup, { | ||
| name: toKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
@@ -192,2 +231,5 @@ | ||
| if (indexA === indexB) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
@@ -200,2 +242,21 @@ var copy = [].concat(toConsumableArray(array || [])); | ||
| }); | ||
| // swap all field state that begin with "name[indexA]" with that under "name[indexB]" | ||
| var aPrefix = name + "[" + indexA + "]"; | ||
| var bPrefix = name + "[" + indexB + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, aPrefix.length) === aPrefix) { | ||
| var suffix = key.substring(aPrefix.length); | ||
| var aKey = aPrefix + suffix; | ||
| var bKey = bPrefix + suffix; | ||
| var fieldA = state.fields[aKey]; | ||
| state.fields[aKey] = _extends({}, state.fields[bKey], { | ||
| name: aKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| state.fields[bKey] = _extends({}, fieldA, { | ||
| name: bKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
@@ -220,2 +281,20 @@ | ||
| var update = function update(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| index = _ref3[1], | ||
| value = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| copy.splice(index, 1, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| // | ||
| var mutators = { | ||
@@ -229,5 +308,6 @@ insert: insert, | ||
| swap: swap, | ||
| unshift: unshift | ||
| unshift: unshift, | ||
| update: update | ||
| }; | ||
| export default mutators; |
+249
-169
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
| typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
| (factory((global['final-form-arrays'] = {}))); | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
| typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
| (factory((global['final-form-arrays'] = {}))); | ||
| }(this, (function (exports) { 'use strict'; | ||
| var slicedToArray = function () { | ||
| function sliceIterator(arr, i) { | ||
| var _arr = []; | ||
| var _n = true; | ||
| var _d = false; | ||
| var _e = undefined; | ||
| var _extends = Object.assign || function (target) { | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| var source = arguments[i]; | ||
| try { | ||
| for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
| _arr.push(_s.value); | ||
| for (var key in source) { | ||
| if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| } | ||
| if (i && _arr.length === i) break; | ||
| } | ||
| } catch (err) { | ||
| _d = true; | ||
| _e = err; | ||
| } finally { | ||
| return target; | ||
| }; | ||
| var slicedToArray = function () { | ||
| function sliceIterator(arr, i) { | ||
| var _arr = []; | ||
| var _n = true; | ||
| var _d = false; | ||
| var _e = undefined; | ||
| try { | ||
| if (!_n && _i["return"]) _i["return"](); | ||
| for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
| _arr.push(_s.value); | ||
| if (i && _arr.length === i) break; | ||
| } | ||
| } catch (err) { | ||
| _d = true; | ||
| _e = err; | ||
| } finally { | ||
| if (_d) throw _e; | ||
| try { | ||
| if (!_n && _i["return"]) _i["return"](); | ||
| } finally { | ||
| if (_d) throw _e; | ||
| } | ||
| } | ||
| return _arr; | ||
| } | ||
| return _arr; | ||
| } | ||
| return function (arr, i) { | ||
| if (Array.isArray(arr)) { | ||
| return arr; | ||
| } else if (Symbol.iterator in Object(arr)) { | ||
| return sliceIterator(arr, i); | ||
| } else { | ||
| throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
| } | ||
| }; | ||
| }(); | ||
| return function (arr, i) { | ||
| var toConsumableArray = function (arr) { | ||
| if (Array.isArray(arr)) { | ||
| return arr; | ||
| } else if (Symbol.iterator in Object(arr)) { | ||
| return sliceIterator(arr, i); | ||
| for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
| return arr2; | ||
| } else { | ||
| throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
| return Array.from(arr); | ||
| } | ||
| }; | ||
| }(); | ||
| // | ||
| var insert = function insert(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| index = _ref3[1], | ||
| value = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| copy.splice(index, 0, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| // | ||
| var move = function move(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| from = _ref3[1], | ||
| to = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| if (from === to) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| var value = copy[from]; | ||
| copy.splice(from, 1); | ||
| copy.splice(to, 0, value); | ||
| return copy; | ||
| }); | ||
| var fromPrefix = name + "[" + from + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, fromPrefix.length) === fromPrefix) { | ||
| var suffix = key.substring(fromPrefix.length); | ||
| var fromKey = fromPrefix + suffix; | ||
| var backup = state.fields[fromKey]; | ||
| if (from < to) { | ||
| // moving to a higher index | ||
| // decrement all indices between from and to | ||
| for (var i = from; i < to; i++) { | ||
| var destKey = name + "[" + i + "]" + suffix; | ||
| state.fields[destKey] = _extends({}, state.fields[name + "[" + (i + 1) + "]" + suffix], { | ||
| name: destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } else { | ||
| // moving to a lower index | ||
| // increment all indices between to and from | ||
| for (var _i = from; _i > to; _i--) { | ||
| var _destKey = name + "[" + _i + "]" + suffix; | ||
| state.fields[_destKey] = _extends({}, state.fields[name + "[" + (_i - 1) + "]" + suffix], { | ||
| name: _destKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| } | ||
| var toKey = name + "[" + to + "]" + suffix; | ||
| state.fields[toKey] = _extends({}, backup, { | ||
| name: toKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
| // | ||
| var toConsumableArray = function (arr) { | ||
| if (Array.isArray(arr)) { | ||
| for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
| var pop = function pop(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 1), | ||
| name = _ref3[0]; | ||
| return arr2; | ||
| } else { | ||
| return Array.from(arr); | ||
| } | ||
| }; | ||
| var changeValue = _ref2.changeValue; | ||
| // | ||
| var result = void 0; | ||
| changeValue(state, name, function (array) { | ||
| if (array) { | ||
| if (!array.length) { | ||
| return []; | ||
| } | ||
| result = array[array.length - 1]; | ||
| return array.slice(0, array.length - 1); | ||
| } | ||
| }); | ||
| return result; | ||
| }; | ||
| // | ||
| var insert = function insert(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| index = _ref3[1], | ||
| value = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| var push = function push(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| value = _ref3[1]; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| copy.splice(index, 0, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| var changeValue = _ref2.changeValue; | ||
| // | ||
| changeValue(state, name, function (array) { | ||
| return array ? [].concat(toConsumableArray(array), [value]) : [value]; | ||
| }); | ||
| }; | ||
| // | ||
| var move = function move(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| from = _ref3[1], | ||
| to = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| var remove = function remove(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| index = _ref3[1]; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| var value = copy[from]; | ||
| copy.splice(from, 1); | ||
| copy.splice(to, 0, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| var changeValue = _ref2.changeValue; | ||
| // | ||
| var returnValue = void 0; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| returnValue = copy[index]; | ||
| copy.splice(index, 1); | ||
| return copy; | ||
| }); | ||
| return returnValue; | ||
| }; | ||
| // | ||
| var pop = function pop(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 1), | ||
| name = _ref3[0]; | ||
| var changeValue = _ref2.changeValue; | ||
| var shift = function shift(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 1), | ||
| name = _ref3[0]; | ||
| var result = void 0; | ||
| changeValue(state, name, function (array) { | ||
| if (array) { | ||
| if (!array.length) { | ||
| return []; | ||
| var changeValue = _ref2.changeValue; | ||
| var result = void 0; | ||
| changeValue(state, name, function (array) { | ||
| if (array) { | ||
| if (!array.length) { | ||
| return []; | ||
| } | ||
| result = array[0]; | ||
| return array.slice(1, array.length); | ||
| } | ||
| result = array[array.length - 1]; | ||
| return array.slice(0, array.length - 1); | ||
| } | ||
| }); | ||
| return result; | ||
| }; | ||
| }); | ||
| return result; | ||
| }; | ||
| // | ||
| // | ||
| var push = function push(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| value = _ref3[1]; | ||
| var swap = function swap(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| indexA = _ref3[1], | ||
| indexB = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| return array ? [].concat(toConsumableArray(array), [value]) : [value]; | ||
| }); | ||
| }; | ||
| // | ||
| var remove = function remove(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| index = _ref3[1]; | ||
| var changeValue = _ref2.changeValue; | ||
| var returnValue = void 0; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| returnValue = copy[index]; | ||
| copy.splice(index, 1); | ||
| return copy; | ||
| }); | ||
| return returnValue; | ||
| }; | ||
| // | ||
| var shift = function shift(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 1), | ||
| name = _ref3[0]; | ||
| var changeValue = _ref2.changeValue; | ||
| var result = void 0; | ||
| changeValue(state, name, function (array) { | ||
| if (array) { | ||
| if (!array.length) { | ||
| return []; | ||
| if (indexA === indexB) { | ||
| return; | ||
| } | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| var a = copy[indexA]; | ||
| copy[indexA] = copy[indexB]; | ||
| copy[indexB] = a; | ||
| return copy; | ||
| }); | ||
| // swap all field state that begin with "name[indexA]" with that under "name[indexB]" | ||
| var aPrefix = name + "[" + indexA + "]"; | ||
| var bPrefix = name + "[" + indexB + "]"; | ||
| Object.keys(state.fields).forEach(function (key) { | ||
| if (key.substring(0, aPrefix.length) === aPrefix) { | ||
| var suffix = key.substring(aPrefix.length); | ||
| var aKey = aPrefix + suffix; | ||
| var bKey = bPrefix + suffix; | ||
| var fieldA = state.fields[aKey]; | ||
| state.fields[aKey] = _extends({}, state.fields[bKey], { | ||
| name: aKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| state.fields[bKey] = _extends({}, fieldA, { | ||
| name: bKey, | ||
| lastFieldState: undefined // clearing lastFieldState forces renotification | ||
| }); | ||
| } | ||
| result = array[0]; | ||
| return array.slice(1, array.length); | ||
| } | ||
| }); | ||
| return result; | ||
| }; | ||
| }); | ||
| }; | ||
| // | ||
| // | ||
| var swap = function swap(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| indexA = _ref3[1], | ||
| indexB = _ref3[2]; | ||
| var unshift = function unshift(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| value = _ref3[1]; | ||
| var changeValue = _ref2.changeValue; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| var a = copy[indexA]; | ||
| copy[indexA] = copy[indexB]; | ||
| copy[indexB] = a; | ||
| return copy; | ||
| }); | ||
| }; | ||
| changeValue(state, name, function (array) { | ||
| return array ? [value].concat(toConsumableArray(array)) : [value]; | ||
| }); | ||
| }; | ||
| // | ||
| // | ||
| var unshift = function unshift(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 2), | ||
| name = _ref3[0], | ||
| value = _ref3[1]; | ||
| var update = function update(_ref, state, _ref2) { | ||
| var _ref3 = slicedToArray(_ref, 3), | ||
| name = _ref3[0], | ||
| index = _ref3[1], | ||
| value = _ref3[2]; | ||
| var changeValue = _ref2.changeValue; | ||
| var changeValue = _ref2.changeValue; | ||
| changeValue(state, name, function (array) { | ||
| return array ? [value].concat(toConsumableArray(array)) : [value]; | ||
| }); | ||
| }; | ||
| changeValue(state, name, function (array) { | ||
| var copy = [].concat(toConsumableArray(array || [])); | ||
| copy.splice(index, 1, value); | ||
| return copy; | ||
| }); | ||
| }; | ||
| // | ||
| // | ||
| var mutators = { | ||
| insert: insert, | ||
| move: move, | ||
| pop: pop, | ||
| push: push, | ||
| remove: remove, | ||
| shift: shift, | ||
| swap: swap, | ||
| unshift: unshift | ||
| }; | ||
| var mutators = { | ||
| insert: insert, | ||
| move: move, | ||
| pop: pop, | ||
| push: push, | ||
| remove: remove, | ||
| shift: shift, | ||
| swap: swap, | ||
| unshift: unshift, | ||
| update: update | ||
| }; | ||
| exports.default = mutators; | ||
| exports.default = mutators; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| }))); | ||
| //# sourceMappingURL=final-form-arrays.umd.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"final-form-arrays.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} | ||
| {"version":3,"file":"final-form-arrays.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} |
@@ -1,2 +0,2 @@ | ||
| !function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n["final-form-arrays"]={})}(this,function(n){"use strict";var r=function(){return function(n,r){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return function(n,r){var e=[],t=!0,u=!1,a=void 0;try{for(var i,o=n[Symbol.iterator]();!(t=(i=o.next()).done)&&(e.push(i.value),!r||e.length!==r);t=!0);}catch(n){u=!0,a=n}finally{try{!t&&o.return&&o.return()}finally{if(u)throw a}}return e}(n,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),e=function(n){if(Array.isArray(n)){for(var r=0,e=Array(n.length);r<n.length;r++)e[r]=n[r];return e}return Array.from(n)},t={insert:function(n,t,u){var a=r(n,3),i=a[0],o=a[1],c=a[2];(0,u.changeValue)(t,i,function(n){var r=[].concat(e(n||[]));return r.splice(o,0,c),r})},move:function(n,t,u){var a=r(n,3),i=a[0],o=a[1],c=a[2];(0,u.changeValue)(t,i,function(n){var r=[].concat(e(n||[])),t=r[o];return r.splice(o,1),r.splice(c,0,t),r})},pop:function(n,e,t){var u=r(n,1)[0],a=void 0;return(0,t.changeValue)(e,u,function(n){if(n)return n.length?(a=n[n.length-1],n.slice(0,n.length-1)):[]}),a},push:function(n,t,u){var a=r(n,2),i=a[0],o=a[1];(0,u.changeValue)(t,i,function(n){return n?[].concat(e(n),[o]):[o]})},remove:function(n,t,u){var a=r(n,2),i=a[0],o=a[1],c=void 0;return(0,u.changeValue)(t,i,function(n){var r=[].concat(e(n||[]));return c=r[o],r.splice(o,1),r}),c},shift:function(n,e,t){var u=r(n,1)[0],a=void 0;return(0,t.changeValue)(e,u,function(n){if(n)return n.length?(a=n[0],n.slice(1,n.length)):[]}),a},swap:function(n,t,u){var a=r(n,3),i=a[0],o=a[1],c=a[2];(0,u.changeValue)(t,i,function(n){var r=[].concat(e(n||[])),t=r[o];return r[o]=r[c],r[c]=t,r})},unshift:function(n,t,u){var a=r(n,2),i=a[0],o=a[1];(0,u.changeValue)(t,i,function(n){return n?[o].concat(e(n)):[o]})}};n.default=t,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
| !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e["final-form-arrays"]={})}(this,function(e){"use strict";var h=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},g=function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,n){var t=[],r=!0,a=!1,i=void 0;try{for(var o,f=e[Symbol.iterator]();!(r=(o=f.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{!r&&f.return&&f.return()}finally{if(a)throw i}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},p=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},n={insert:function(e,n,t){var r=g(e,3),a=r[0],i=r[1],o=r[2];(0,t.changeValue)(n,a,function(e){var n=[].concat(p(e||[]));return n.splice(i,0,o),n})},move:function(e,c,n){var t=g(e,3),l=t[0],s=t[1],v=t[2],r=n.changeValue;if(s!==v){r(c,l,function(e){var n=[].concat(p(e||[])),t=n[s];return n.splice(s,1),n.splice(v,0,t),n});var d=l+"["+s+"]";Object.keys(c.fields).forEach(function(e){if(e.substring(0,d.length)===d){var n=e.substring(d.length),t=d+n,r=c.fields[t];if(s<v)for(var a=s;a<v;a++){var i=l+"["+a+"]"+n;c.fields[i]=h({},c.fields[l+"["+(a+1)+"]"+n],{name:i,lastFieldState:void 0})}else for(var o=s;v<o;o--){var f=l+"["+o+"]"+n;c.fields[f]=h({},c.fields[l+"["+(o-1)+"]"+n],{name:f,lastFieldState:void 0})}var u=l+"["+v+"]"+n;c.fields[u]=h({},r,{name:u,lastFieldState:void 0})}})}},pop:function(e,n,t){var r=g(e,1)[0],a=t.changeValue,i=void 0;return a(n,r,function(e){if(e)return e.length?(i=e[e.length-1],e.slice(0,e.length-1)):[]}),i},push:function(e,n,t){var r=g(e,2),a=r[0],i=r[1];(0,t.changeValue)(n,a,function(e){return e?[].concat(p(e),[i]):[i]})},remove:function(e,n,t){var r=g(e,2),a=r[0],i=r[1],o=t.changeValue,f=void 0;return o(n,a,function(e){var n=[].concat(p(e||[]));return f=n[i],n.splice(i,1),n}),f},shift:function(e,n,t){var r=g(e,1)[0],a=t.changeValue,i=void 0;return a(n,r,function(e){if(e)return e.length?(i=e[0],e.slice(1,e.length)):[]}),i},swap:function(e,i,n){var t=g(e,3),r=t[0],a=t[1],o=t[2],f=n.changeValue;if(a!==o){f(i,r,function(e){var n=[].concat(p(e||[])),t=n[a];return n[a]=n[o],n[o]=t,n});var u=r+"["+a+"]",c=r+"["+o+"]";Object.keys(i.fields).forEach(function(e){if(e.substring(0,u.length)===u){var n=e.substring(u.length),t=u+n,r=c+n,a=i.fields[t];i.fields[t]=h({},i.fields[r],{name:t,lastFieldState:void 0}),i.fields[r]=h({},a,{name:r,lastFieldState:void 0})}})}},unshift:function(e,n,t){var r=g(e,2),a=r[0],i=r[1];(0,t.changeValue)(n,a,function(e){return e?[i].concat(p(e)):[i]})},update:function(e,n,t){var r=g(e,3),a=r[0],i=r[1],o=r[2];(0,t.changeValue)(n,a,function(e){var n=[].concat(p(e||[]));return n.splice(i,1,o),n})}};e.default=n,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
| //# sourceMappingURL=final-form-arrays.umd.min.js.map |
+3
-0
@@ -10,2 +10,3 @@ import { Mutator } from 'final-form' | ||
| export const swap: Mutator | ||
| export const update: Mutator | ||
| export const unshift: Mutator | ||
@@ -21,2 +22,3 @@ | ||
| swap: Mutator | ||
| update: Mutator | ||
| unshift: Mutator | ||
@@ -37,3 +39,4 @@ } | ||
| swap: (name: string, indexA: number, indexB: number) => void | ||
| update: (name: string, index: number, value: any) => void | ||
| unshift: (name: string, value: any) => void | ||
| } |
+16
-12
| { | ||
| "name": "final-form-arrays", | ||
| "version": "1.0.4", | ||
| "version": "1.1.0", | ||
| "description": "Array Mutators for 🏁 Final Form", | ||
@@ -29,3 +29,3 @@ "main": "dist/final-form-arrays.cjs.js", | ||
| "babel-eslint": "^8.2.1", | ||
| "babel-jest": "^22.1.0", | ||
| "babel-jest": "^23.4.2", | ||
| "babel-plugin-external-helpers": "^6.22.0", | ||
@@ -35,7 +35,7 @@ "babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
| "babel-preset-stage-2": "^6.24.1", | ||
| "bundlesize": "^0.15.3", | ||
| "bundlesize": "^0.17.0", | ||
| "doctoc": "^1.3.0", | ||
| "eslint": "^4.16.0", | ||
| "eslint": "^5.4.0", | ||
| "eslint-config-react-app": "^2.1.0", | ||
| "eslint-plugin-babel": "^4.1.2", | ||
| "eslint-plugin-babel": "^5.1.0", | ||
| "eslint-plugin-flowtype": "^2.41.0", | ||
@@ -46,6 +46,7 @@ "eslint-plugin-import": "^2.8.0", | ||
| "final-form": "^4.0.4", | ||
| "flow-bin": "^0.63.1", | ||
| "flow-bin": "^0.79.1", | ||
| "glow": "^1.2.2", | ||
| "husky": "^0.14.3", | ||
| "jest": "^22.1.4", | ||
| "lint-staged": "^6.0.1", | ||
| "jest": "^23.5.0", | ||
| "lint-staged": "^7.2.2", | ||
| "nps": "^5.7.1", | ||
@@ -55,10 +56,10 @@ "nps-utils": "^1.5.0", | ||
| "prettier-eslint-cli": "^4.7.0", | ||
| "rollup": "^0.55.0", | ||
| "rollup": "^0.64.1", | ||
| "rollup-plugin-babel": "^3.0.3", | ||
| "rollup-plugin-commonjs": "^8.2.6", | ||
| "rollup-plugin-commonjs": "^9.1.5", | ||
| "rollup-plugin-flow": "^1.1.1", | ||
| "rollup-plugin-node-resolve": "^3.0.2", | ||
| "rollup-plugin-replace": "^2.0.0", | ||
| "rollup-plugin-uglify": "^3.0.0", | ||
| "typescript": "^2.6.2" | ||
| "rollup-plugin-uglify": "^4.0.0", | ||
| "typescript": "^3.0.1" | ||
| }, | ||
@@ -74,2 +75,5 @@ "peerDependencies": { | ||
| }, | ||
| "jest": { | ||
| "testEnvironment": "node" | ||
| }, | ||
| "bundlesize": [ | ||
@@ -76,0 +80,0 @@ { |
+15
-12
@@ -48,16 +48,15 @@ # 🏁 Final Form Arrays | ||
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
| * [Mutators](#mutators) | ||
| * [`form.mutators.insert(name: string, index:number, value: any) => undefined`](#formmutatorsinsertname-string-indexnumber-value-any--undefined) | ||
| * [`form.mutators.move(name: string, from: number, to: number) => undefined`](#formmutatorsmovename-string-from-number-to-number--undefined) | ||
| * [`form.mutators.pop(name: string) => any`](#formmutatorspopname-string--any) | ||
| * [`form.mutators.push(name: string, value: any) => void`](#formmutatorspushname-string-value-any--void) | ||
| * [`form.mutators.remove(name: string, index: number) => any`](#formmutatorsremovename-string-index-number--any) | ||
| * [`form.mutators.shift(name: string) => any`](#formmutatorsshiftname-string--any) | ||
| * [`form.mutators.swap(name: string, indexA: number, indexB: number) => void`](#formmutatorsswapname-string-indexa-number-indexb-number--void) | ||
| * [`form.mutators.unshift(name: string, value: any) => void`](#formmutatorsunshiftname-string-value-any--void) | ||
| - [Mutators](#mutators) | ||
| - [`form.mutators.insert(name: string, index: number, value: any) => undefined`](#formmutatorsinsertname-string-index-number-value-any--undefined) | ||
| - [`form.mutators.move(name: string, from: number, to: number) => undefined`](#formmutatorsmovename-string-from-number-to-number--undefined) | ||
| - [`form.mutators.pop(name: string) => any`](#formmutatorspopname-string--any) | ||
| - [`form.mutators.push(name: string, value: any) => void`](#formmutatorspushname-string-value-any--void) | ||
| - [`form.mutators.remove(name: string, index: number) => any`](#formmutatorsremovename-string-index-number--any) | ||
| - [`form.mutators.shift(name: string) => any`](#formmutatorsshiftname-string--any) | ||
| - [`form.mutators.swap(name: string, indexA: number, indexB: number) => void`](#formmutatorsswapname-string-indexa-number-indexb-number--void) | ||
| - [`form.mutators.update(name: string, index: number, value: any) => void`](#formmutatorsupdatename-string-index-number-value-any--void) | ||
| - [`form.mutators.unshift(name: string, value: any) => void`](#formmutatorsunshiftname-string-value-any--void) | ||
@@ -68,3 +67,3 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
| ### `form.mutators.insert(name: string, index:number, value: any) => undefined` | ||
| ### `form.mutators.insert(name: string, index: number, value: any) => undefined` | ||
@@ -98,4 +97,8 @@ Inserts a value into the specified index of the array field. | ||
| ### `form.mutators.update(name: string, index: number, value: any) => void` | ||
| Updates a value of the specified index of the array field. | ||
| ### `form.mutators.unshift(name: string, value: any) => void` | ||
| Inserts a value onto the beginning of the array field. |
Sorry, the diff of this file is not supported yet
35597
45.18%805
47.44%102
3.03%33
3.13%