@felte/react
Advanced tools
Comparing version 1.0.0-next.22 to 1.0.0-next.23
@@ -5,2 +5,3 @@ import { __rest } from './external/.pnpm/tslib@2.3.1/external/tslib/tslib.es6.js'; | ||
import { deepSetTouched } from './deep-set-touched.js'; | ||
import { deepRemoveKey } from './deep-set-key.js'; | ||
import { _merge } from './packages/common/dist/esm/utils/merge.js'; | ||
@@ -74,3 +75,3 @@ import { deepSet } from './packages/common/dist/esm/utils/deepSet.js'; | ||
isSubmitting.set(true); | ||
const currentData = get(data); | ||
const currentData = deepRemoveKey(get(data)); | ||
const currentErrors = await validateErrors(currentData, altConfig === null || altConfig === void 0 ? void 0 : altConfig.validate); | ||
@@ -77,0 +78,0 @@ const currentWarnings = await validateWarnings(currentData, altConfig === null || altConfig === void 0 ? void 0 : altConfig.warn); |
import { createHelpers } from './helpers.js'; | ||
import { createFormAction } from './create-form-action.js'; | ||
import { createStores } from './stores.js'; | ||
import { deepSetKey } from './deep-set-key.js'; | ||
import { executeTransforms } from './packages/common/dist/esm/utils/executeTransforms.js'; | ||
@@ -56,4 +57,4 @@ | ||
const originalSet = data.set; | ||
const transUpdate = (updater) => originalUpdate((values) => executeTransforms(updater(values), config.transform)); | ||
const transSet = (values) => originalSet(executeTransforms(values, config.transform)); | ||
const transUpdate = (updater) => originalUpdate((values) => deepSetKey(executeTransforms(updater(values), config.transform))); | ||
const transSet = (values) => originalSet(deepSetKey(executeTransforms(values, config.transform))); | ||
data.update = transUpdate; | ||
@@ -60,0 +61,0 @@ data.set = transSet; |
@@ -0,1 +1,2 @@ | ||
import { __rest } from './external/.pnpm/tslib@2.3.1/external/tslib/tslib.es6.js'; | ||
import { _mapValues } from './packages/common/dist/esm/utils/mapValues.js'; | ||
@@ -26,4 +27,23 @@ import { _isPlainObject } from './packages/common/dist/esm/utils/isPlainObject.js'; | ||
} | ||
function deepRemoveKey(obj) { | ||
if (!obj) | ||
return {}; | ||
return _mapValues(obj, (prop) => { | ||
if (_isPlainObject(prop)) | ||
return deepSetKey(prop); | ||
if (Array.isArray(prop)) { | ||
if (prop.length === 0 || prop.every((p) => typeof p === 'string')) | ||
return prop; | ||
return prop.map((p) => { | ||
if (!_isPlainObject(p)) | ||
return p; | ||
const _a = deepSetKey(p), field = __rest(_a, ["key"]); | ||
return field; | ||
}); | ||
} | ||
return prop; | ||
}); | ||
} | ||
export { deepSetKey }; | ||
export { deepRemoveKey, deepSetKey }; | ||
//# sourceMappingURL=deep-set-key.js.map |
@@ -75,4 +75,3 @@ import { get } from './get.js'; | ||
const newData = _unset($data, path); | ||
if (formNode) | ||
setForm(formNode, newData); | ||
setTimeout(() => formNode && setForm(formNode, newData)); | ||
return newData; | ||
@@ -79,0 +78,0 @@ }); |
import { deepSetTouched } from './deep-set-touched.js'; | ||
import { deepSetKey } from './deep-set-key.js'; | ||
import { deepSetKey, deepRemoveKey } from './deep-set-key.js'; | ||
import { executeTransforms } from './packages/common/dist/esm/utils/executeTransforms.js'; | ||
@@ -118,5 +118,5 @@ import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
const derived = createDerivedFactory(storeFactory); | ||
const initialValues = config.initialValues | ||
const initialValues = (config.initialValues = config.initialValues | ||
? deepSetKey(executeTransforms(_cloneDeep(config.initialValues), config.transform)) | ||
: {}; | ||
: {}); | ||
const initialTouched = deepSetTouched(initialValues, false); | ||
@@ -214,6 +214,7 @@ const touched = storeFactory(initialTouched); | ||
var _a; | ||
const errors = validateErrors(data, storesShape, altValidate !== null && altValidate !== void 0 ? altValidate : config.validate, true); | ||
const $data = deepRemoveKey(data); | ||
const errors = validateErrors($data, storesShape, altValidate !== null && altValidate !== void 0 ? altValidate : config.validate, true); | ||
if (altValidate) | ||
return errors; | ||
const debouncedErrors = validateDebouncedErrors(data, storesShape, (_a = config.debounced) === null || _a === void 0 ? void 0 : _a.validate, true); | ||
const debouncedErrors = validateDebouncedErrors($data, storesShape, (_a = config.debounced) === null || _a === void 0 ? void 0 : _a.validate, true); | ||
return mergeErrors(await Promise.all([errors, debouncedErrors])); | ||
@@ -223,6 +224,7 @@ } | ||
var _a; | ||
const warnings = validateWarnings(data, storesShape, altWarn !== null && altWarn !== void 0 ? altWarn : config.warn, true); | ||
const $data = deepRemoveKey(data); | ||
const warnings = validateWarnings($data, storesShape, altWarn !== null && altWarn !== void 0 ? altWarn : config.warn, true); | ||
if (altWarn) | ||
return warnings; | ||
const debouncedWarnings = validateDebouncedWarnings(data, storesShape, (_a = config.debounced) === null || _a === void 0 ? void 0 : _a.warn, true); | ||
const debouncedWarnings = validateDebouncedWarnings($data, storesShape, (_a = config.debounced) === null || _a === void 0 ? void 0 : _a.warn, true); | ||
return mergeErrors(await Promise.all([warnings, debouncedWarnings])); | ||
@@ -233,4 +235,5 @@ } | ||
function start() { | ||
const dataUnsubscriber = data.subscribe(($data) => { | ||
const dataUnsubscriber = data.subscribe(($keyedData) => { | ||
var _a, _b; | ||
const $data = deepRemoveKey($keyedData); | ||
validateErrors($data, storesShape, config.validate); | ||
@@ -289,3 +292,3 @@ validateWarnings($data, storesShape, config.warn); | ||
return { | ||
data, | ||
data: data, | ||
errors: filteredErrors, | ||
@@ -292,0 +295,0 @@ warnings: filteredWarnings, |
@@ -1,12 +0,12 @@ | ||
import { Obj, Errors, Touched, TransWritable, Traverse, Paths } from '@felte/core'; | ||
import { Obj, Errors, Touched, TransWritable, Traverse, Paths, Keyed, KeyedWritable } from '@felte/core'; | ||
import { Readable, Writable } from 'svelte/store'; | ||
type Accessor<T> = T extends Obj ? (<R>(selector: (storeValue: T) => R) => R) & (<P extends Paths<T> = Paths<T>, V extends Traverse<T, P> = Traverse<T, P>>(path: P) => V) & (() => T) : (<R>(deriveFn: (storeValue: T) => R) => R) & (() => T); | ||
type UnknownStores<Data extends Obj> = Omit<Stores<Data>, 'data'> & { | ||
data: Accessor<Data> & TransWritable<Data>; | ||
data: Accessor<Keyed<Data>> & TransWritable<Data>; | ||
}; | ||
type KnownStores<Data extends Obj> = Omit<Stores<Data>, 'data'> & { | ||
data: Accessor<Data> & Writable<Data>; | ||
data: Accessor<Keyed<Data>> & KeyedWritable<Data>; | ||
}; | ||
type Stores<Data extends Obj> = { | ||
data: Accessor<Data> & Writable<Data>; | ||
data: Accessor<Keyed<Data>> & KeyedWritable<Data>; | ||
errors: Accessor<Errors<Data>> & Writable<Errors<Data>>; | ||
@@ -13,0 +13,0 @@ warnings: Accessor<Errors<Data>> & Writable<Errors<Data>>; |
{ | ||
"name": "@felte/react", | ||
"version": "1.0.0-next.22", | ||
"version": "1.0.0-next.23", | ||
"description": "An extensible form library for ReactJS", | ||
@@ -29,3 +29,3 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@felte/core": "1.0.0-next.19" | ||
"@felte/core": "1.0.0-next.20" | ||
}, | ||
@@ -39,3 +39,3 @@ "publishConfig": { | ||
"devDependencies": { | ||
"@felte/common": "1.0.0-next.16", | ||
"@felte/common": "1.0.0-next.17", | ||
"@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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
470486
3566
+ Added@felte/common@1.0.0-next.17(transitive)
+ Added@felte/core@1.0.0-next.20(transitive)
- Removed@felte/common@1.0.0-next.16(transitive)
- Removed@felte/core@1.0.0-next.19(transitive)
Updated@felte/core@1.0.0-next.20