@felte/react
Advanced tools
Comparing version 1.0.0-next.27 to 1.0.0-next.28
@@ -6,4 +6,2 @@ import { get } from './get.js'; | ||
import { _set } from './packages/common/dist/esm/utils/set.js'; | ||
import { _unset } from './packages/common/dist/esm/utils/unset.js'; | ||
import { setForm } from './packages/common/dist/esm/utils/domUtils.js'; | ||
import { _isPlainObject } from './packages/common/dist/esm/utils/isPlainObject.js'; | ||
@@ -13,3 +11,5 @@ import { deepSet } from './packages/common/dist/esm/utils/deepSet.js'; | ||
import { _update } from './packages/common/dist/esm/utils/update.js'; | ||
import { setForm } from './packages/common/dist/esm/utils/domUtils.js'; | ||
import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
import { _unset } from './packages/common/dist/esm/utils/unset.js'; | ||
@@ -31,2 +31,18 @@ function addAtIndex(storeValue, path, value, index) { | ||
} | ||
function swapInArray(storeValue, path, from, to) { | ||
return _update(storeValue, path, (oldValue) => { | ||
if (!oldValue || !Array.isArray(oldValue)) | ||
return oldValue; | ||
[oldValue[from], oldValue[to]] = [oldValue[to], oldValue[from]]; | ||
return oldValue; | ||
}); | ||
} | ||
function moveInArray(storeValue, path, from, to) { | ||
return _update(storeValue, path, (oldValue) => { | ||
if (!oldValue || !Array.isArray(oldValue)) | ||
return oldValue; | ||
oldValue.splice(to, 0, oldValue.splice(from, 1)[0]); | ||
return oldValue; | ||
}); | ||
} | ||
function isUpdater(value) { | ||
@@ -76,18 +92,2 @@ return typeof value === 'function'; | ||
}; | ||
function unsetField(path) { | ||
data.update(($data) => { | ||
const newData = _unset($data, path); | ||
setTimeout(() => formNode && setForm(formNode, newData)); | ||
return newData; | ||
}); | ||
touched.update(($touched) => { | ||
return _unset($touched, path); | ||
}); | ||
errors.update(($errors) => { | ||
return _unset($errors, path); | ||
}); | ||
warnings.update(($warnings) => { | ||
return _unset($warnings, path); | ||
}); | ||
} | ||
function addField(path, value, index) { | ||
@@ -116,2 +116,21 @@ const touchedValue = _isPlainObject(value) | ||
} | ||
function updateAll(updater) { | ||
errors.update(updater); | ||
warnings.update(updater); | ||
touched.update(updater); | ||
data.update(($data) => { | ||
const newData = updater($data); | ||
setTimeout(() => formNode && setForm(formNode, newData)); | ||
return newData; | ||
}); | ||
} | ||
function unsetField(path) { | ||
updateAll((storeValue) => _unset(storeValue, path)); | ||
} | ||
function swapFields(path, from, to) { | ||
updateAll((storeValue) => swapInArray(storeValue, path, from, to)); | ||
} | ||
function moveField(path, from, to) { | ||
updateAll((storeValue) => moveInArray(storeValue, path, from, to)); | ||
} | ||
function resetField(path) { | ||
@@ -172,2 +191,4 @@ const initialValue = _get(initialValues, path); | ||
addField, | ||
swapFields, | ||
moveField, | ||
setInitialValues: (values) => { | ||
@@ -174,0 +195,0 @@ initialValues = deepSetKey(values); |
{ | ||
"name": "@felte/react", | ||
"version": "1.0.0-next.27", | ||
"version": "1.0.0-next.28", | ||
"description": "An extensible form library for ReactJS", | ||
@@ -29,3 +29,3 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@felte/core": "1.0.0-next.24" | ||
"@felte/core": "1.0.0-next.25" | ||
}, | ||
@@ -39,3 +39,3 @@ "publishConfig": { | ||
"devDependencies": { | ||
"@felte/common": "1.0.0-next.20", | ||
"@felte/common": "1.0.0-next.21", | ||
"@testing-library/jest-dom": "^5.11.9", | ||
@@ -42,0 +42,0 @@ "@testing-library/react": "^12.1.2", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
515997
3969
+ Added@felte/common@1.0.0-next.21(transitive)
+ Added@felte/core@1.0.0-next.25(transitive)
- Removed@felte/common@1.0.0-next.20(transitive)
- Removed@felte/core@1.0.0-next.24(transitive)
Updated@felte/core@1.0.0-next.25