@felte/core
Advanced tools
Comparing version 1.0.0-next.1 to 1.0.0-next.2
import { Form, FormConfig, FormConfigWithTransformFn, FormConfigWithoutTransformFn, StoreFactory, Obj, UnknownStores, Stores, KnownStores, Helpers, UnknownHelpers, KnownHelpers } from "@felte/common"; | ||
type Adapters<StoreExt = {}> = { | ||
type Adapters<StoreExt = Record<string, any>> = { | ||
storeFactory: StoreFactory<StoreExt>; | ||
@@ -8,7 +8,7 @@ }; | ||
}; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = {}>(config: FormConfigWithTransformFn<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & UnknownHelpers<Data> & UnknownStores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = {}>(config: FormConfigWithoutTransformFn<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & KnownHelpers<Data> & KnownStores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = {}>(config: FormConfig<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & Helpers<Data> & Stores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = Record<string, any>>(config: FormConfigWithTransformFn<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & UnknownHelpers<Data> & UnknownStores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = Record<string, any>>(config: FormConfigWithoutTransformFn<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & KnownHelpers<Data> & KnownStores<Data, StoreExt>; | ||
declare function createForm<Data extends Obj = Obj, Ext extends Obj = Obj, StoreExt = Record<string, any>>(config: FormConfig<Data> & Ext, adapters: Adapters<StoreExt>): CoreForm<Data> & Helpers<Data> & Stores<Data, StoreExt>; | ||
export { Adapters, CoreForm, createForm }; | ||
export * from '@felte/common'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -142,3 +142,3 @@ 'use strict'; | ||
// If not yet an array, get the keys from the string-path | ||
let newPath = !Array.isArray(path) | ||
const newPath = !Array.isArray(path) | ||
? path.toString().match(/[^.[\]]+/g) || [] | ||
@@ -160,3 +160,2 @@ : path; | ||
function _unset(obj, path) { | ||
var _a; | ||
if (Object(obj) !== obj) | ||
@@ -168,9 +167,15 @@ return; | ||
// If not yet an array, get the keys from the string-path | ||
let newPath = !Array.isArray(path) | ||
const newPath = !Array.isArray(path) | ||
? path.toString().match(/[^.[\]]+/g) || [] | ||
: path; | ||
(_a = newPath.slice(0, -1).reduce((a, c) => Object(a[c]) === a[c] // Does the key exist and is its value an object? | ||
const foundProp = newPath.slice(0, -1).reduce((a, c) => Object(a[c]) === a[c] // Does the key exist and is its value an object? | ||
? // Yes: then follow that path | ||
a[c] | ||
: undefined, obj)) === null || _a === void 0 ? true : delete _a[newPath[newPath.length - 1]]; | ||
: undefined, obj); | ||
if (Array.isArray(foundProp)) { | ||
foundProp.splice(Number(newPath[newPath.length - 1]), 1); | ||
} | ||
else { | ||
foundProp === null || foundProp === void 0 ? true : delete foundProp[newPath[newPath.length - 1]]; | ||
} | ||
return obj; // Return the top-level object to allow chaining | ||
@@ -184,3 +189,3 @@ } | ||
// If not yet an array, get the keys from the string-path | ||
let newPath = path.toString().match(/[^.[\]]+/g) || []; | ||
const newPath = path.toString().match(/[^.[\]]+/g) || []; | ||
newPath.slice(0, -1).reduce((a, c, i // Iterate all of them except the last one | ||
@@ -556,2 +561,11 @@ ) => Object(a[c]) === a[c] // Does the key exist and is its value an object? | ||
function unsetField(path) { | ||
errors.update(($errors) => { | ||
return _unset($errors, path); | ||
}); | ||
warnings.update(($warnings) => { | ||
return _unset($warnings, path); | ||
}); | ||
touched.update(($touched) => { | ||
return _unset($touched, path); | ||
}); | ||
data.update(($data) => { | ||
@@ -563,11 +577,2 @@ const newData = _unset($data, path); | ||
}); | ||
touched.update(($touched) => { | ||
return _unset($touched, path); | ||
}); | ||
errors.update(($errors) => { | ||
return _unset($errors, path); | ||
}); | ||
warnings.update(($warnings) => { | ||
return _unset($warnings, path); | ||
}); | ||
} | ||
@@ -728,43 +733,2 @@ function resetField(path) { | ||
} | ||
function proxyInputs() { | ||
for (const control of Array.from(node.elements).filter(isFormControl)) { | ||
if (shouldIgnore(control) || !control.name) | ||
continue; | ||
let propName = 'value'; | ||
if (isInputElement(control) && | ||
['checkbox', 'radio'].includes(control.type)) { | ||
propName = 'checked'; | ||
} | ||
if (isInputElement(control) && control.type === 'file') { | ||
propName = 'files'; | ||
} | ||
const prop = Object.getOwnPropertyDescriptor(isSelectElement(control) | ||
? HTMLSelectElement.prototype | ||
: isTextAreaElement(control) | ||
? HTMLTextAreaElement.prototype | ||
: HTMLInputElement.prototype, propName); | ||
Object.defineProperty(control, propName, { | ||
configurable: true, | ||
set(newValue) { | ||
var _a; | ||
(_a = prop === null || prop === void 0 ? void 0 : prop.set) === null || _a === void 0 ? void 0 : _a.call(control, newValue); | ||
if (isInputElement(control)) { | ||
if (control.type === 'checkbox') | ||
return setCheckboxValues(control); | ||
if (control.type === 'radio') | ||
return setRadioValues(control); | ||
if (control.type === 'file') | ||
return setFileValue(control); | ||
} | ||
const inputValue = isSelectElement(control) | ||
? control.value | ||
: getInputTextOrNumber(control); | ||
data.update(($data) => { | ||
return _set($data, getPath(control), inputValue); | ||
}); | ||
}, | ||
get: prop === null || prop === void 0 ? void 0 : prop.get, | ||
}); | ||
} | ||
} | ||
_setCurrentExtenders(extender.map(callExtender('MOUNT'))); | ||
@@ -871,12 +835,6 @@ node.noValidate = !!config.validate; | ||
function unsetTaggedForRemove(formControls) { | ||
for (const control of formControls) { | ||
for (const control of formControls.reverse()) { | ||
if (control.hasAttribute('data-felte-keep-on-remove') && | ||
control.dataset.felteKeepOnRemove !== 'false') | ||
continue; | ||
data.update(($data) => { | ||
return _unset($data, getPathFromDataset(control)); | ||
}); | ||
touched.update(($touched) => { | ||
return _unset($touched, getPathFromDataset(control)); | ||
}); | ||
errors.update(($errors) => { | ||
@@ -888,2 +846,8 @@ return _unset($errors, getPathFromDataset(control)); | ||
}); | ||
touched.update(($touched) => { | ||
return _unset($touched, getPathFromDataset(control)); | ||
}); | ||
data.update(($data) => { | ||
return _unset($data, getPathFromDataset(control)); | ||
}); | ||
} | ||
@@ -896,3 +860,2 @@ } | ||
if (mutation.addedNodes.length > 0) { | ||
proxyInputs(); | ||
const shouldUpdate = Array.from(mutation.addedNodes).some((node) => { | ||
@@ -933,3 +896,2 @@ if (!isElement(node)) | ||
observer.observe(node, mutationOptions); | ||
proxyInputs(); | ||
node.addEventListener('input', handleInput); | ||
@@ -936,0 +898,0 @@ node.addEventListener('change', handleChange); |
{ | ||
"name": "@felte/core", | ||
"version": "1.0.0-next.1", | ||
"version": "1.0.0-next.2", | ||
"description": "Core package for FelteJS", | ||
@@ -27,3 +27,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@felte/common": "1.0.0-next.0" | ||
"@felte/common": "1.0.0-next.1" | ||
}, | ||
@@ -30,0 +30,0 @@ "publishConfig": { |
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
267402
2280
+ Added@felte/common@1.0.0-next.1(transitive)
- Removed@felte/common@1.0.0-next.0(transitive)
Updated@felte/common@1.0.0-next.1