Comparing version 0.0.16 to 0.1.0
@@ -58,3 +58,2 @@ "use strict"; | ||
getCheckboxChecked: () => getCheckboxChecked, | ||
getDescendantErrors: () => getDescendantErrors, | ||
getElementsWithNames: () => getElementsWithNames, | ||
@@ -85,3 +84,2 @@ getFieldArrayKeys: () => getFieldArrayKeys, | ||
scopeFormScope: () => scopeFormScope, | ||
scopeKeyObject: () => scopeKeyObject, | ||
setFormControlValue: () => setFormControlValue, | ||
@@ -166,62 +164,5 @@ toArrayBehavior: () => toArrayBehavior | ||
init_define_import_meta(); | ||
var import_set_get2 = require("@rvf/set-get"); | ||
// src/native-form-data/flatten.ts | ||
init_define_import_meta(); | ||
var import_set_get = require("@rvf/set-get"); | ||
// src/native-form-data/MultiValueMap.ts | ||
init_define_import_meta(); | ||
var import_react2 = require("react"); | ||
var MultiValueMap = class { | ||
dict = /* @__PURE__ */ new Map(); | ||
add = (key, value) => { | ||
if (this.dict.has(key)) { | ||
this.dict.get(key).push(value); | ||
} else { | ||
this.dict.set(key, [value]); | ||
} | ||
}; | ||
delete = (key) => { | ||
this.dict.delete(key); | ||
}; | ||
remove = (key, value) => { | ||
if (!this.dict.has(key)) | ||
return; | ||
const array = this.dict.get(key); | ||
const index = array.indexOf(value); | ||
if (index !== -1) | ||
array.splice(index, 1); | ||
if (array.length === 0) | ||
this.dict.delete(key); | ||
}; | ||
getAll = (key) => { | ||
return this.dict.get(key) ?? []; | ||
}; | ||
entries = () => this.dict.entries(); | ||
keys = () => this.dict.keys(); | ||
values = () => this.dict.values(); | ||
has = (key) => this.dict.has(key); | ||
}; | ||
// src/native-form-data/flatten.ts | ||
var objectFromPathEntries = (entries) => { | ||
const map = new MultiValueMap(); | ||
entries.forEach(([key, value]) => map.add(key, value)); | ||
return [...map.entries()].reduce( | ||
(acc, [key, value]) => (0, import_set_get.setPath)(acc, key, value.length === 1 ? value[0] : value), | ||
{} | ||
); | ||
}; | ||
var preprocessFormData = (data) => { | ||
if ("entries" in data && typeof data.entries === "function") | ||
return objectFromPathEntries([...data.entries()]); | ||
if (Object.keys(data).some((key) => /[\[\]\.]/.test(key))) | ||
return objectFromPathEntries(Object.entries(data)); | ||
return data; | ||
}; | ||
// src/getters.ts | ||
var getFieldValue = (state, fieldName) => (0, import_set_get2.getPath)(state.values, fieldName); | ||
var getFieldDefaultValue = (state, fieldName) => (0, import_set_get2.getPath)(state.defaultValues, fieldName); | ||
var getFieldValue = (state, fieldName) => (0, import_set_get.getPath)(state.values, fieldName); | ||
var getFieldDefaultValue = (state, fieldName) => (0, import_set_get.getPath)(state.defaultValues, fieldName); | ||
var getFieldTouched = (state, fieldName) => state.touchedFields[fieldName] ?? false; | ||
@@ -244,8 +185,2 @@ var getFieldDirty = (state, fieldName) => state.dirtyFields[fieldName] ?? false; | ||
}; | ||
var getDescendantErrors = (state, fieldName) => { | ||
const all = getAllErrors(state); | ||
const scoped = scopeKeyObject(all, fieldName); | ||
const structured = objectFromPathEntries(Object.entries(scoped)); | ||
return structured; | ||
}; | ||
var getFormId = (state) => state.formProps.id; | ||
@@ -474,2 +409,57 @@ var getFormProps = (state) => state.formProps; | ||
// src/native-form-data/flatten.ts | ||
init_define_import_meta(); | ||
var import_set_get2 = require("@rvf/set-get"); | ||
// src/native-form-data/MultiValueMap.ts | ||
init_define_import_meta(); | ||
var import_react2 = require("react"); | ||
var MultiValueMap = class { | ||
dict = /* @__PURE__ */ new Map(); | ||
add = (key, value) => { | ||
if (this.dict.has(key)) { | ||
this.dict.get(key).push(value); | ||
} else { | ||
this.dict.set(key, [value]); | ||
} | ||
}; | ||
delete = (key) => { | ||
this.dict.delete(key); | ||
}; | ||
remove = (key, value) => { | ||
if (!this.dict.has(key)) | ||
return; | ||
const array = this.dict.get(key); | ||
const index = array.indexOf(value); | ||
if (index !== -1) | ||
array.splice(index, 1); | ||
if (array.length === 0) | ||
this.dict.delete(key); | ||
}; | ||
getAll = (key) => { | ||
return this.dict.get(key) ?? []; | ||
}; | ||
entries = () => this.dict.entries(); | ||
keys = () => this.dict.keys(); | ||
values = () => this.dict.values(); | ||
has = (key) => this.dict.has(key); | ||
}; | ||
// src/native-form-data/flatten.ts | ||
var objectFromPathEntries = (entries) => { | ||
const map = new MultiValueMap(); | ||
entries.forEach(([key, value]) => map.add(key, value)); | ||
return [...map.entries()].reduce( | ||
(acc, [key, value]) => (0, import_set_get2.setPath)(acc, key, value.length === 1 ? value[0] : value), | ||
{} | ||
); | ||
}; | ||
var preprocessFormData = (data) => { | ||
if ("entries" in data && typeof data.entries === "function") | ||
return objectFromPathEntries([...data.entries()]); | ||
if (Object.keys(data).some((key) => /[\[\]\.]/.test(key))) | ||
return objectFromPathEntries(Object.entries(data)); | ||
return data; | ||
}; | ||
// src/arrayUtil.ts | ||
@@ -617,12 +607,2 @@ init_define_import_meta(); | ||
}; | ||
var scopeKeyObject = (prefixObject, prefix) => { | ||
const scopedObject = {}; | ||
const relevantEntries = Object.entries(prefixObject).filter( | ||
([key]) => key.startsWith(prefix) | ||
); | ||
for (const [key, value] of relevantEntries) { | ||
scopedObject[key.replace(prefix, "")] = value; | ||
} | ||
return scopedObject; | ||
}; | ||
var moveFieldArrayKeys = (objs, fieldName, updater) => { | ||
@@ -1751,3 +1731,2 @@ objs.forEach((obj) => { | ||
getCheckboxChecked, | ||
getDescendantErrors, | ||
getElementsWithNames, | ||
@@ -1778,3 +1757,2 @@ getFieldArrayKeys, | ||
scopeFormScope, | ||
scopeKeyObject, | ||
setFormControlValue, | ||
@@ -1781,0 +1759,0 @@ toArrayBehavior |
@@ -222,3 +222,2 @@ import * as zustand_react from 'zustand/react'; | ||
declare const deleteFieldsWithPrefix: (prefixObjects: Record<string, any>[], path: string) => void; | ||
declare const scopeKeyObject: (prefixObject: Record<string, any>, prefix: string) => Record<string, any>; | ||
declare const moveFieldArrayKeys: (objs: Record<string, any>[], fieldName: string, updater: (index: number) => number) => void; | ||
@@ -307,3 +306,2 @@ declare const toArrayBehavior: (config?: ValidationBehaviorConfig) => FieldArrayValidationBehaviorConfig; | ||
declare const getAllErrors: (state: FormStoreValue) => Record<string, string>; | ||
declare const getDescendantErrors: (state: FormStoreValue, fieldName: string) => Record<string, any>; | ||
declare const getFormId: (state: FormStoreValue) => string; | ||
@@ -346,2 +344,2 @@ declare const getFormProps: (state: FormStoreValue) => StoreFormProps; | ||
export { AllProps, CreateValidatorArg, DomSubmitHandler, ErrorResult, FORM_ID_FIELD_NAME, FieldArrayValidationBehavior, FieldArrayValidationBehaviorConfig, FieldErrors, FieldSerializer, FieldValue, FieldValues, FormControl, FormScope, FormStore, FormStoreInit, FormStoreValue, GenericObject, Invalid, MultiFileInputValue, MutableImplStore, NativeValueByType, NumberInputValue, RefStore, ResolverQueue, ScopedValues, SingleFileInputValue, StateSubmitHandler, StoreFlags, StoreFormProps, SubmitStatus, SubmitterOptions, SuccessResult, Valid, ValidationBehavior, ValidationBehaviorConfig, ValidationErrorResponseData, ValidationResult, Validator, ValidatorData, ValidatorError, ValueOfInputType, createFormScope, createFormStateStore, createRefStore, createResolverQueue, createValidator, deleteFieldsWithPrefix, focusFirst, focusOrReport, getAllDirty, getAllErrors, getAllTouched, getArrayUpdateKey, getCheckboxChecked, getDescendantErrors, getElementsWithNames, getFieldArrayKeys, getFieldDefaultValue, getFieldDirty, getFieldError, getFieldTouched, getFieldValue, getFormAction, getFormControlValue, getFormId, getFormProps, getNextCheckboxValue, getNextNativeValue, getRadioChecked, isEvent, isFormControl, isValidationErrorResponse, moveFieldArrayKeys, objectFromPathEntries, onNativeBlur, onNativeChange, preprocessFormData, registerFormElementEvents, renameFlatFieldStateKeys, scopeFormScope, scopeKeyObject, setFormControlValue, toArrayBehavior }; | ||
export { AllProps, CreateValidatorArg, DomSubmitHandler, ErrorResult, FORM_ID_FIELD_NAME, FieldArrayValidationBehavior, FieldArrayValidationBehaviorConfig, FieldErrors, FieldSerializer, FieldValue, FieldValues, FormControl, FormScope, FormStore, FormStoreInit, FormStoreValue, GenericObject, Invalid, MultiFileInputValue, MutableImplStore, NativeValueByType, NumberInputValue, RefStore, ResolverQueue, ScopedValues, SingleFileInputValue, StateSubmitHandler, StoreFlags, StoreFormProps, SubmitStatus, SubmitterOptions, SuccessResult, Valid, ValidationBehavior, ValidationBehaviorConfig, ValidationErrorResponseData, ValidationResult, Validator, ValidatorData, ValidatorError, ValueOfInputType, createFormScope, createFormStateStore, createRefStore, createResolverQueue, createValidator, deleteFieldsWithPrefix, focusFirst, focusOrReport, getAllDirty, getAllErrors, getAllTouched, getArrayUpdateKey, getCheckboxChecked, getElementsWithNames, getFieldArrayKeys, getFieldDefaultValue, getFieldDirty, getFieldError, getFieldTouched, getFieldValue, getFormAction, getFormControlValue, getFormId, getFormProps, getNextCheckboxValue, getNextNativeValue, getRadioChecked, isEvent, isFormControl, isValidationErrorResponse, moveFieldArrayKeys, objectFromPathEntries, onNativeBlur, onNativeChange, preprocessFormData, registerFormElementEvents, renameFlatFieldStateKeys, scopeFormScope, setFormControlValue, toArrayBehavior }; |
@@ -96,59 +96,2 @@ var __getOwnPropNames = Object.getOwnPropertyNames; | ||
import { getPath } from "@rvf/set-get"; | ||
// src/native-form-data/flatten.ts | ||
init_define_import_meta(); | ||
import { setPath } from "@rvf/set-get"; | ||
// src/native-form-data/MultiValueMap.ts | ||
init_define_import_meta(); | ||
import { useCallback, useRef } from "react"; | ||
var MultiValueMap = class { | ||
dict = /* @__PURE__ */ new Map(); | ||
add = (key, value) => { | ||
if (this.dict.has(key)) { | ||
this.dict.get(key).push(value); | ||
} else { | ||
this.dict.set(key, [value]); | ||
} | ||
}; | ||
delete = (key) => { | ||
this.dict.delete(key); | ||
}; | ||
remove = (key, value) => { | ||
if (!this.dict.has(key)) | ||
return; | ||
const array = this.dict.get(key); | ||
const index = array.indexOf(value); | ||
if (index !== -1) | ||
array.splice(index, 1); | ||
if (array.length === 0) | ||
this.dict.delete(key); | ||
}; | ||
getAll = (key) => { | ||
return this.dict.get(key) ?? []; | ||
}; | ||
entries = () => this.dict.entries(); | ||
keys = () => this.dict.keys(); | ||
values = () => this.dict.values(); | ||
has = (key) => this.dict.has(key); | ||
}; | ||
// src/native-form-data/flatten.ts | ||
var objectFromPathEntries = (entries) => { | ||
const map = new MultiValueMap(); | ||
entries.forEach(([key, value]) => map.add(key, value)); | ||
return [...map.entries()].reduce( | ||
(acc, [key, value]) => setPath(acc, key, value.length === 1 ? value[0] : value), | ||
{} | ||
); | ||
}; | ||
var preprocessFormData = (data) => { | ||
if ("entries" in data && typeof data.entries === "function") | ||
return objectFromPathEntries([...data.entries()]); | ||
if (Object.keys(data).some((key) => /[\[\]\.]/.test(key))) | ||
return objectFromPathEntries(Object.entries(data)); | ||
return data; | ||
}; | ||
// src/getters.ts | ||
var getFieldValue = (state, fieldName) => getPath(state.values, fieldName); | ||
@@ -173,8 +116,2 @@ var getFieldDefaultValue = (state, fieldName) => getPath(state.defaultValues, fieldName); | ||
}; | ||
var getDescendantErrors = (state, fieldName) => { | ||
const all = getAllErrors(state); | ||
const scoped = scopeKeyObject(all, fieldName); | ||
const structured = objectFromPathEntries(Object.entries(scoped)); | ||
return structured; | ||
}; | ||
var getFormId = (state) => state.formProps.id; | ||
@@ -403,2 +340,57 @@ var getFormProps = (state) => state.formProps; | ||
// src/native-form-data/flatten.ts | ||
init_define_import_meta(); | ||
import { setPath } from "@rvf/set-get"; | ||
// src/native-form-data/MultiValueMap.ts | ||
init_define_import_meta(); | ||
import { useCallback, useRef } from "react"; | ||
var MultiValueMap = class { | ||
dict = /* @__PURE__ */ new Map(); | ||
add = (key, value) => { | ||
if (this.dict.has(key)) { | ||
this.dict.get(key).push(value); | ||
} else { | ||
this.dict.set(key, [value]); | ||
} | ||
}; | ||
delete = (key) => { | ||
this.dict.delete(key); | ||
}; | ||
remove = (key, value) => { | ||
if (!this.dict.has(key)) | ||
return; | ||
const array = this.dict.get(key); | ||
const index = array.indexOf(value); | ||
if (index !== -1) | ||
array.splice(index, 1); | ||
if (array.length === 0) | ||
this.dict.delete(key); | ||
}; | ||
getAll = (key) => { | ||
return this.dict.get(key) ?? []; | ||
}; | ||
entries = () => this.dict.entries(); | ||
keys = () => this.dict.keys(); | ||
values = () => this.dict.values(); | ||
has = (key) => this.dict.has(key); | ||
}; | ||
// src/native-form-data/flatten.ts | ||
var objectFromPathEntries = (entries) => { | ||
const map = new MultiValueMap(); | ||
entries.forEach(([key, value]) => map.add(key, value)); | ||
return [...map.entries()].reduce( | ||
(acc, [key, value]) => setPath(acc, key, value.length === 1 ? value[0] : value), | ||
{} | ||
); | ||
}; | ||
var preprocessFormData = (data) => { | ||
if ("entries" in data && typeof data.entries === "function") | ||
return objectFromPathEntries([...data.entries()]); | ||
if (Object.keys(data).some((key) => /[\[\]\.]/.test(key))) | ||
return objectFromPathEntries(Object.entries(data)); | ||
return data; | ||
}; | ||
// src/arrayUtil.ts | ||
@@ -546,12 +538,2 @@ init_define_import_meta(); | ||
}; | ||
var scopeKeyObject = (prefixObject, prefix) => { | ||
const scopedObject = {}; | ||
const relevantEntries = Object.entries(prefixObject).filter( | ||
([key]) => key.startsWith(prefix) | ||
); | ||
for (const [key, value] of relevantEntries) { | ||
scopedObject[key.replace(prefix, "")] = value; | ||
} | ||
return scopedObject; | ||
}; | ||
var moveFieldArrayKeys = (objs, fieldName, updater) => { | ||
@@ -1681,3 +1663,2 @@ objs.forEach((obj) => { | ||
getCheckboxChecked, | ||
getDescendantErrors, | ||
getElementsWithNames, | ||
@@ -1708,3 +1689,2 @@ getFieldArrayKeys, | ||
scopeFormScope, | ||
scopeKeyObject, | ||
setFormControlValue, | ||
@@ -1711,0 +1691,0 @@ toArrayBehavior |
{ | ||
"name": "@rvf/core", | ||
"version": "0.0.16", | ||
"version": "0.1.0", | ||
"description": "Easy, predictable form state management for React", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
@@ -7,5 +7,4 @@ # RVF Core | ||
## ALPHA RELEASE | ||
## BETA RELEASE | ||
This is an alpha version. There WILL be breaking API changes. | ||
Please feel free to experiment with it and give feedback, but don't use it in production. | ||
This is an beta version. The API should be relatively stable, but there may be some small breaking changes before the final release. |
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
13110456
122226
10