@felte/core
Advanced tools
Comparing version 1.0.0-next.24 to 1.0.0-next.25
@@ -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/core", | ||
"version": "1.0.0-next.24", | ||
"version": "1.0.0-next.25", | ||
"description": "Core utility for Felte's integration with front-end frameworks", | ||
@@ -27,3 +27,3 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@felte/common": "1.0.0-next.20" | ||
"@felte/common": "1.0.0-next.21" | ||
}, | ||
@@ -30,0 +30,0 @@ "publishConfig": { |
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
421169
3682
+ Added@felte/common@1.0.0-next.21(transitive)
- Removed@felte/common@1.0.0-next.20(transitive)
Updated@felte/common@1.0.0-next.21