@felte/react
Advanced tools
Comparing version 1.0.0-next.14 to 1.0.0-next.15
@@ -111,64 +111,2 @@ 'use strict'; | ||
/** @ignore */ | ||
function _mapValues(obj, updater) { | ||
const keys = Object.keys(obj); | ||
return keys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: updater(obj[key]) })), {}); | ||
} | ||
function handleArray(value) { | ||
return function (propVal) { | ||
if (_isPlainObject(propVal)) | ||
return deepSet(propVal, value); | ||
return value; | ||
}; | ||
} | ||
/** | ||
* @category Helper | ||
*/ | ||
function deepSet(obj, value) { | ||
return _mapValues(obj, (prop) => _isPlainObject(prop) | ||
? deepSet(prop, value) | ||
: Array.isArray(prop) | ||
? prop.map(handleArray(value)) | ||
: value); | ||
} | ||
/** @ignore */ | ||
function _mergeWith(...args) { | ||
const customizer = args.pop(); | ||
const obj = _cloneDeep(args.shift()); | ||
if (args.length === 0) | ||
return obj; | ||
for (const source of args) { | ||
if (!source) | ||
continue; | ||
const keys = Object.keys(source); | ||
for (const key of keys) { | ||
const rsValue = customizer(obj[key], source[key]); | ||
if (typeof rsValue !== 'undefined') { | ||
obj[key] = rsValue; | ||
} | ||
else if (_isPlainObject(source[key]) && _isPlainObject(obj[key])) { | ||
obj[key] = _mergeWith(obj[key], source[key], customizer); | ||
} | ||
else if (Array.isArray(source[key])) { | ||
obj[key] = source[key].map((val, i) => { | ||
if (!_isPlainObject(val)) | ||
return val; | ||
const newObj = Array.isArray(obj[key]) ? obj[key][i] : obj[key]; | ||
return _mergeWith(newObj, val, customizer); | ||
}); | ||
} | ||
else if (_isPlainObject(source[key])) { | ||
const defaultObj = deepSet(_cloneDeep(source[key]), undefined); | ||
obj[key] = _mergeWith(defaultObj, source[key], customizer); | ||
} | ||
else if (typeof source[key] !== 'undefined') { | ||
obj[key] = source[key]; | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
/* From: https://stackoverflow.com/a/54733755 */ | ||
@@ -417,2 +355,65 @@ /** @ignore */ | ||
} | ||
/** @ignore */ | ||
function _mapValues(obj, updater) { | ||
const keys = Object.keys(obj); | ||
return keys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: updater(obj[key]) })), {}); | ||
} | ||
function handleArray(value) { | ||
return function (propVal) { | ||
if (_isPlainObject(propVal)) | ||
return deepSet(propVal, value); | ||
return value; | ||
}; | ||
} | ||
/** | ||
* @category Helper | ||
*/ | ||
function deepSet(obj, value) { | ||
return _mapValues(obj, (prop) => _isPlainObject(prop) | ||
? deepSet(prop, value) | ||
: Array.isArray(prop) | ||
? prop.map(handleArray(value)) | ||
: value); | ||
} | ||
/** @ignore */ | ||
function _mergeWith(...args) { | ||
const customizer = args.pop(); | ||
const obj = _cloneDeep(args.shift()); | ||
if (args.length === 0) | ||
return obj; | ||
for (const source of args) { | ||
if (!source) | ||
continue; | ||
const keys = Object.keys(source); | ||
for (const key of keys) { | ||
const rsValue = customizer(obj[key], source[key]); | ||
if (typeof rsValue !== 'undefined') { | ||
obj[key] = rsValue; | ||
} | ||
else if (_isPlainObject(source[key]) && _isPlainObject(obj[key])) { | ||
obj[key] = _mergeWith(obj[key], source[key], customizer); | ||
} | ||
else if (Array.isArray(source[key])) { | ||
obj[key] = source[key].map((val, i) => { | ||
if (!_isPlainObject(val)) | ||
return val; | ||
const newObj = Array.isArray(obj[key]) ? obj[key][i] : obj[key]; | ||
return _mergeWith(newObj, val, customizer); | ||
}); | ||
} | ||
else if (_isPlainObject(source[key])) { | ||
const defaultObj = deepSet(_cloneDeep(source[key]), undefined); | ||
obj[key] = _mergeWith(defaultObj, source[key], customizer); | ||
} | ||
else if (typeof source[key] !== 'undefined') { | ||
obj[key] = source[key]; | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
function executeCustomizer(objValue, srcValue) { | ||
@@ -441,9 +442,2 @@ if (_isPlainObject(objValue) || _isPlainObject(srcValue)) | ||
} | ||
function executeTransforms(values, transforms) { | ||
if (!transforms) | ||
return values; | ||
if (!Array.isArray(transforms)) | ||
return transforms(values); | ||
return transforms.reduce((res, t) => t(res), values); | ||
} | ||
@@ -609,2 +603,40 @@ /** @ignore */ | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __rest$1(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
class FelteSuccessEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('feltesuccess', { detail }); | ||
} | ||
} | ||
class FelteErrorEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('felteerror', { detail }); | ||
} | ||
} | ||
/** @ignore */ | ||
@@ -699,3 +731,4 @@ function _some(obj, pred) { | ||
function createFormAction({ helpers, stores, config, extender, _setFormNode, _getFormNode, _getInitialValues, _setCurrentExtenders, _getCurrentExtenders, }) { | ||
const { setFields, setTouched, reset, validate, addValidator, addWarnValidator, addTransformer, setInitialValues, } = helpers; | ||
const { setFields, setTouched, reset, setInitialValues } = helpers; | ||
const { addValidator, addWarnValidator, addTransformer, validate, setIsDirty, setIsSubmitting } = helpers, contextHelpers = __rest$1(helpers, ["addValidator", "addWarnValidator", "addTransformer", "validate", "setIsDirty", "setIsSubmitting"]); | ||
const { data, errors, warnings, touched, isSubmitting, isDirty } = stores; | ||
@@ -739,20 +772,13 @@ function createSubmitHandler(altConfig) { | ||
} | ||
const context = Object.assign(Object.assign({}, contextHelpers), { form: formNode, controls: formNode && Array.from(formNode.elements).filter(isFormControl), config: Object.assign(Object.assign({}, config), altConfig) }); | ||
try { | ||
const response = await onSubmit(currentData, { | ||
form: formNode, | ||
controls: formNode && Array.from(formNode.elements).filter(isFormControl), | ||
config: Object.assign(Object.assign({}, config), altConfig), | ||
}); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new CustomEvent('feltesuccess', { | ||
detail: response, | ||
})); | ||
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response)); | ||
const response = await onSubmit(currentData, context); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new FelteSuccessEvent(Object.assign({ response }, context))); | ||
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, context)); | ||
} | ||
catch (e) { | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new CustomEvent('felteerror', { | ||
detail: e, | ||
})); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new FelteErrorEvent(Object.assign({ error: e }, context))); | ||
if (!onError) | ||
return; | ||
const serverErrors = await onError(e); | ||
const serverErrors = await onError(e, context); | ||
if (serverErrors) { | ||
@@ -1003,2 +1029,10 @@ errors.set(serverErrors); | ||
function executeTransforms(values, transforms) { | ||
if (!transforms) | ||
return values; | ||
if (!Array.isArray(transforms)) | ||
return transforms(values); | ||
return transforms.reduce((res, t) => t(res), values); | ||
} | ||
function errorFilterer(errValue, touchValue) { | ||
@@ -1418,5 +1452,7 @@ if (_isPlainObject(touchValue)) | ||
exports.FelteErrorEvent = FelteErrorEvent; | ||
exports.FelteSubmitError = FelteSubmitError; | ||
exports.FelteSuccessEvent = FelteSuccessEvent; | ||
exports.useAccessor = useAccessor; | ||
exports.useForm = useForm; | ||
//# sourceMappingURL=index.js.map |
export { useAccessor } from './use-accessor.js'; | ||
export { useForm } from './use-form.js'; | ||
export { FelteSubmitError } from './packages/core/dist/esm/error.js'; | ||
export { FelteErrorEvent, FelteSuccessEvent } from './packages/core/dist/esm/events.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,17 +1,20 @@ | ||
import { __rest } from './external/.pnpm/tslib@2.3.1/external/tslib/tslib.es6.js'; | ||
import { get } from './get.js'; | ||
import { FelteSubmitError } from './error.js'; | ||
import { executeValidation, getFormDefaultValues, getInputTextOrNumber, getFormControls } from './common/dist/esm/utils/domUtils.js'; | ||
import { _merge } from './common/dist/esm/utils/merge.js'; | ||
import { deepSet } from './common/dist/esm/utils/deepSet.js'; | ||
import { deepSome } from './common/dist/esm/utils/deepSome.js'; | ||
import { isFormControl, isSelectElement, isInputElement, isElement } from './common/dist/esm/utils/typeGuards.js'; | ||
import { _cloneDeep } from './common/dist/esm/utils/cloneDeep.js'; | ||
import { _get } from './common/dist/esm/utils/get.js'; | ||
import { getPath } from './common/dist/esm/utils/getPath.js'; | ||
import { shouldIgnore } from './common/dist/esm/utils/shouldIgnore.js'; | ||
import { _set } from './common/dist/esm/utils/set.js'; | ||
import { _defaultsDeep } from './common/dist/esm/utils/defaultsDeep.js'; | ||
import { getIndex } from './common/dist/esm/utils/getIndex.js'; | ||
import { _unset } from './common/dist/esm/utils/unset.js'; | ||
import { getPathFromDataset } from './common/dist/esm/utils/getPathFromDataset.js'; | ||
import { FelteSuccessEvent, FelteErrorEvent } from './events.js'; | ||
import { executeValidation } from './packages/common/dist/esm/utils/executeValidation.js'; | ||
import { _merge } from './packages/common/dist/esm/utils/merge.js'; | ||
import { deepSet } from './packages/common/dist/esm/utils/deepSet.js'; | ||
import { deepSome } from './packages/common/dist/esm/utils/deepSome.js'; | ||
import { isFormControl, isSelectElement, isInputElement, isElement } from './packages/common/dist/esm/utils/typeGuards.js'; | ||
import { getFormDefaultValues, getInputTextOrNumber, getFormControls } from './packages/common/dist/esm/utils/domUtils.js'; | ||
import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
import { _get } from './packages/common/dist/esm/utils/get.js'; | ||
import { getPath } from './packages/common/dist/esm/utils/getPath.js'; | ||
import { shouldIgnore } from './packages/common/dist/esm/utils/shouldIgnore.js'; | ||
import { _set } from './packages/common/dist/esm/utils/set.js'; | ||
import { _defaultsDeep } from './packages/common/dist/esm/utils/defaultsDeep.js'; | ||
import { getIndex } from './packages/common/dist/esm/utils/getIndex.js'; | ||
import { _unset } from './packages/common/dist/esm/utils/unset.js'; | ||
import { getPathFromDataset } from './packages/common/dist/esm/utils/getPathFromDataset.js'; | ||
@@ -57,3 +60,4 @@ function createDefaultSubmitHandler(form) { | ||
function createFormAction({ helpers, stores, config, extender, _setFormNode, _getFormNode, _getInitialValues, _setCurrentExtenders, _getCurrentExtenders, }) { | ||
const { setFields, setTouched, reset, validate, addValidator, addWarnValidator, addTransformer, setInitialValues, } = helpers; | ||
const { setFields, setTouched, reset, setInitialValues } = helpers; | ||
const { addValidator, addWarnValidator, addTransformer, validate, setIsDirty, setIsSubmitting } = helpers, contextHelpers = __rest(helpers, ["addValidator", "addWarnValidator", "addTransformer", "validate", "setIsDirty", "setIsSubmitting"]); | ||
const { data, errors, warnings, touched, isSubmitting, isDirty } = stores; | ||
@@ -97,20 +101,13 @@ function createSubmitHandler(altConfig) { | ||
} | ||
const context = Object.assign(Object.assign({}, contextHelpers), { form: formNode, controls: formNode && Array.from(formNode.elements).filter(isFormControl), config: Object.assign(Object.assign({}, config), altConfig) }); | ||
try { | ||
const response = await onSubmit(currentData, { | ||
form: formNode, | ||
controls: formNode && Array.from(formNode.elements).filter(isFormControl), | ||
config: Object.assign(Object.assign({}, config), altConfig), | ||
}); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new CustomEvent('feltesuccess', { | ||
detail: response, | ||
})); | ||
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response)); | ||
const response = await onSubmit(currentData, context); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new FelteSuccessEvent(Object.assign({ response }, context))); | ||
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, context)); | ||
} | ||
catch (e) { | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new CustomEvent('felteerror', { | ||
detail: e, | ||
})); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new FelteErrorEvent(Object.assign({ error: e }, context))); | ||
if (!onError) | ||
return; | ||
const serverErrors = await onError(e); | ||
const serverErrors = await onError(e, context); | ||
if (serverErrors) { | ||
@@ -117,0 +114,0 @@ errors.set(serverErrors); |
import { createHelpers } from './helpers.js'; | ||
import { createFormAction } from './create-form-action.js'; | ||
import { createStores } from './stores.js'; | ||
import { executeTransforms } from './common/dist/esm/utils/domUtils.js'; | ||
import { _mergeWith } from './common/dist/esm/utils/mergeWith.js'; | ||
import { _cloneDeep } from './common/dist/esm/utils/cloneDeep.js'; | ||
import { _isPlainObject } from './common/dist/esm/utils/isPlainObject.js'; | ||
import { executeTransforms } from './packages/common/dist/esm/utils/executeTransforms.js'; | ||
import { _mergeWith } from './packages/common/dist/esm/utils/mergeWith.js'; | ||
import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
import { _isPlainObject } from './packages/common/dist/esm/utils/isPlainObject.js'; | ||
@@ -9,0 +9,0 @@ function createForm(config, adapters) { |
import { get } from './get.js'; | ||
import { _unset } from './common/dist/esm/utils/unset.js'; | ||
import { setForm, executeValidation } from './common/dist/esm/utils/domUtils.js'; | ||
import { _update } from './common/dist/esm/utils/update.js'; | ||
import { _get } from './common/dist/esm/utils/get.js'; | ||
import { _set } from './common/dist/esm/utils/set.js'; | ||
import { deepSet } from './common/dist/esm/utils/deepSet.js'; | ||
import { _merge } from './common/dist/esm/utils/merge.js'; | ||
import { _cloneDeep } from './common/dist/esm/utils/cloneDeep.js'; | ||
import { _unset } from './packages/common/dist/esm/utils/unset.js'; | ||
import { setForm } from './packages/common/dist/esm/utils/domUtils.js'; | ||
import { _update } from './packages/common/dist/esm/utils/update.js'; | ||
import { _get } from './packages/common/dist/esm/utils/get.js'; | ||
import { _set } from './packages/common/dist/esm/utils/set.js'; | ||
import { deepSet } from './packages/common/dist/esm/utils/deepSet.js'; | ||
import { executeValidation } from './packages/common/dist/esm/utils/executeValidation.js'; | ||
import { _merge } from './packages/common/dist/esm/utils/merge.js'; | ||
import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
@@ -11,0 +12,0 @@ function addAtIndex(storeValue, path, value, index) { |
@@ -1,8 +0,9 @@ | ||
import { executeTransforms, executeValidation } from './common/dist/esm/utils/domUtils.js'; | ||
import { _cloneDeep } from './common/dist/esm/utils/cloneDeep.js'; | ||
import { deepSet } from './common/dist/esm/utils/deepSet.js'; | ||
import { deepSome } from './common/dist/esm/utils/deepSome.js'; | ||
import { _mergeWith } from './common/dist/esm/utils/mergeWith.js'; | ||
import { _isPlainObject } from './common/dist/esm/utils/isPlainObject.js'; | ||
import { _merge } from './common/dist/esm/utils/merge.js'; | ||
import { executeTransforms } from './packages/common/dist/esm/utils/executeTransforms.js'; | ||
import { _cloneDeep } from './packages/common/dist/esm/utils/cloneDeep.js'; | ||
import { deepSet } from './packages/common/dist/esm/utils/deepSet.js'; | ||
import { deepSome } from './packages/common/dist/esm/utils/deepSome.js'; | ||
import { _mergeWith } from './packages/common/dist/esm/utils/mergeWith.js'; | ||
import { _isPlainObject } from './packages/common/dist/esm/utils/isPlainObject.js'; | ||
import { executeValidation } from './packages/common/dist/esm/utils/executeValidation.js'; | ||
import { _merge } from './packages/common/dist/esm/utils/merge.js'; | ||
@@ -9,0 +10,0 @@ function errorFilterer(errValue, touchValue) { |
import { useState, useRef, useCallback, useEffect } from 'react'; | ||
import { get } from './packages/core/dist/esm/get.js'; | ||
import { getValue } from './packages/core/dist/esm/common/dist/esm/utils/getValue.js'; | ||
import { getValue } from './packages/core/dist/esm/packages/common/dist/esm/utils/getValue.js'; | ||
@@ -5,0 +5,0 @@ function isWritable(store) { |
@@ -1,4 +0,5 @@ | ||
export { FelteSubmitError } from '@felte/core'; | ||
export type { FelteSuccessDetail, FelteErrorDetail } from '@felte/core'; | ||
export { FelteSubmitError, FelteSuccessEvent, FelteErrorEvent } from '@felte/core'; | ||
export { useAccessor } from "./use-accessor"; | ||
export { useForm } from "./use-form"; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@felte/react", | ||
"version": "1.0.0-next.14", | ||
"version": "1.0.0-next.15", | ||
"description": "An extensible form library for ReactJS", | ||
@@ -29,3 +29,3 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@felte/core": "1.0.0-next.11" | ||
"@felte/core": "1.0.0-next.12" | ||
}, | ||
@@ -39,3 +39,3 @@ "publishConfig": { | ||
"devDependencies": { | ||
"@felte/common": "1.0.0-next.9", | ||
"@felte/common": "1.0.0-next.10", | ||
"@testing-library/jest-dom": "^5.11.9", | ||
@@ -42,0 +42,0 @@ "@testing-library/react": "^12.1.2", |
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
394084
80
3036
+ Added@felte/common@1.0.0-next.10(transitive)
+ Added@felte/core@1.0.0-next.12(transitive)
- Removed@felte/common@1.0.0-next.9(transitive)
- Removed@felte/core@1.0.0-next.11(transitive)
Updated@felte/core@1.0.0-next.12