Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rvf/core

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rvf/core - npm Package Compare versions

Comparing version 6.1.0 to 7.0.0-beta.0

62

dist/index.cjs.js

@@ -165,3 +165,17 @@ "use strict";

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 getFieldDefaultValue = (state, fieldName) => {
const path = (0, import_set_get.stringToPathArray)(fieldName);
const postfix = [];
while (path.length > 0) {
let current = (0, import_set_get.pathArrayToString)(path);
if (current in state.defaultValueOverrides) {
const parent = state.defaultValueOverrides[current];
if (postfix.length)
return (0, import_set_get.getPath)(parent, postfix);
return parent;
}
postfix.push(path.pop());
}
return (0, import_set_get.getPath)(state.defaultValues, fieldName);
};
var getFieldTouched = (state, fieldName) => state.touchedFields[fieldName] ?? false;

@@ -645,2 +659,3 @@ var getFieldDirty = (state, fieldName) => state.dirtyFields[fieldName] ?? false;

defaultValues,
defaultValueOverrides: {},
touchedFields: {},

@@ -1037,2 +1052,3 @@ dirtyFields: {},

state.defaultValues = nextValues;
state.defaultValueOverrides = {};
state.touchedFields = {};

@@ -1054,3 +1070,5 @@ state.dirtyFields = {};

},
resetField: (fieldName, nextValue = (0, import_set_get3.getPath)(get().defaultValues, fieldName)) => {
resetField: (fieldName, opts = {}) => {
const currentDefaultValue = getFieldDefaultValue(get(), fieldName);
const nextValue = opts.defaultValue ?? currentDefaultValue;
set((state) => {

@@ -1063,3 +1081,4 @@ (0, import_set_get3.setPath)(state.values, fieldName, nextValue);

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1069,2 +1088,4 @@ fieldName

state.arrayUpdateKeys[fieldName] = genKey();
if ("defaultValue" in opts)
state.defaultValueOverrides[fieldName] = opts.defaultValue;
});

@@ -1107,5 +1128,7 @@ if (get().submitSource === "dom" && controlledFieldRefs.has(fieldName) && !fieldSerializerRefs.has(fieldName)) {

throw new Error("Can't push to a non-array");
const previousLength = val.length;
val.push(value);
state.fieldArrayKeys[fieldName]?.push(genKey());
state.arrayUpdateKeys[fieldName] = genKey();
state.defaultValueOverrides[`${fieldName}[${previousLength}]`] = value;
});

@@ -1132,3 +1155,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1157,3 +1181,4 @@ `${fieldName}[${numItems - 1}]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1167,3 +1192,4 @@ `${fieldName}[0]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1193,3 +1219,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1199,2 +1226,3 @@ fieldName,

);
state.defaultValueOverrides[`${fieldName}[0]`] = value;
});

@@ -1220,3 +1248,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1226,2 +1255,3 @@ fieldName,

);
state.defaultValueOverrides[`${fieldName}[${insertAtIndex}]`] = value;
});

@@ -1247,3 +1277,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1282,3 +1313,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1292,3 +1324,4 @@ `${fieldName}[${removeIndex}]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1324,3 +1357,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1356,6 +1390,8 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],
`${fieldName}[${index}]`
);
state.defaultValueOverrides[`${fieldName}[${index}]`] = value;
});

@@ -1362,0 +1398,0 @@ void get().maybeValidateArrayOperation(

@@ -146,2 +146,3 @@ import * as zustand_react from 'zustand/react';

defaultValues: FieldValues;
defaultValueOverrides: Record<string, unknown>;
touchedFields: Record<string, boolean>;

@@ -164,2 +165,5 @@ dirtyFields: Record<string, boolean>;

};
type ResetFieldOpts = {
defaultValue?: unknown;
};
type StoreEvents = {

@@ -211,3 +215,3 @@ onFieldChange: (fieldName: string, value: unknown, validationBehaviorConfig?: ValidationBehaviorConfig) => void;

reset: (nextValues?: FieldValues) => void;
resetField: (fieldName: string, nextValue?: unknown) => void;
resetField: (fieldName: string, opts?: ResetFieldOpts) => void;
getFieldArrayKeys: (fieldName: string) => Array<string>;

@@ -377,2 +381,2 @@ arrayPush: (fieldName: string, value: unknown, validationBehavior?: FieldArrayValidationBehaviorConfig) => void;

export { AllProps, BeforeSubmitApi, 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, getOriginalObject, getRadioChecked, isEvent, isFormControl, isValidationErrorResponse, moveFieldArrayKeys, objectFromPathEntries, onNativeBlur, onNativeChange, preprocessFormData, registerFormElementEvents, renameFlatFieldStateKeys, scopeFormScope, setFormControlValue, toArrayBehavior };
export { AllProps, BeforeSubmitApi, 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, ResetFieldOpts, 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, getOriginalObject, getRadioChecked, isEvent, isFormControl, isValidationErrorResponse, moveFieldArrayKeys, objectFromPathEntries, onNativeBlur, onNativeChange, preprocessFormData, registerFormElementEvents, renameFlatFieldStateKeys, scopeFormScope, setFormControlValue, toArrayBehavior };

@@ -22,4 +22,4 @@ var __getOwnPropNames = Object.getOwnPropertyNames;

getPath as getPath2,
stringToPathArray,
pathArrayToString
stringToPathArray as stringToPathArray2,
pathArrayToString as pathArrayToString2
} from "@rvf/set-get";

@@ -96,5 +96,19 @@

init_define_import_meta();
import { getPath } from "@rvf/set-get";
import { getPath, pathArrayToString, stringToPathArray } from "@rvf/set-get";
var getFieldValue = (state, fieldName) => getPath(state.values, fieldName);
var getFieldDefaultValue = (state, fieldName) => getPath(state.defaultValues, fieldName);
var getFieldDefaultValue = (state, fieldName) => {
const path = stringToPathArray(fieldName);
const postfix = [];
while (path.length > 0) {
let current = pathArrayToString(path);
if (current in state.defaultValueOverrides) {
const parent = state.defaultValueOverrides[current];
if (postfix.length)
return getPath(parent, postfix);
return parent;
}
postfix.push(path.pop());
}
return getPath(state.defaultValues, fieldName);
};
var getFieldTouched = (state, fieldName) => state.touchedFields[fieldName] ?? false;

@@ -545,3 +559,3 @@ var getFieldDirty = (state, fieldName) => state.dirtyFields[fieldName] ?? false;

const suffix = key.replace(`${fieldName}`, "");
const parts = stringToPathArray(suffix);
const parts = stringToPathArray2(suffix);
const index = Number(parts.shift());

@@ -551,3 +565,3 @@ if (Number.isNaN(index))

const newIndex = updater(index);
return pathArrayToString([fieldName, newIndex, ...parts]);
return pathArrayToString2([fieldName, newIndex, ...parts]);
});

@@ -580,2 +594,3 @@ });

defaultValues,
defaultValueOverrides: {},
touchedFields: {},

@@ -972,2 +987,3 @@ dirtyFields: {},

state.defaultValues = nextValues;
state.defaultValueOverrides = {};
state.touchedFields = {};

@@ -989,3 +1005,5 @@ state.dirtyFields = {};

},
resetField: (fieldName, nextValue = getPath2(get().defaultValues, fieldName)) => {
resetField: (fieldName, opts = {}) => {
const currentDefaultValue = getFieldDefaultValue(get(), fieldName);
const nextValue = opts.defaultValue ?? currentDefaultValue;
set((state) => {

@@ -998,3 +1016,4 @@ setPath2(state.values, fieldName, nextValue);

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1004,2 +1023,4 @@ fieldName

state.arrayUpdateKeys[fieldName] = genKey();
if ("defaultValue" in opts)
state.defaultValueOverrides[fieldName] = opts.defaultValue;
});

@@ -1042,5 +1063,7 @@ if (get().submitSource === "dom" && controlledFieldRefs.has(fieldName) && !fieldSerializerRefs.has(fieldName)) {

throw new Error("Can't push to a non-array");
const previousLength = val.length;
val.push(value);
state.fieldArrayKeys[fieldName]?.push(genKey());
state.arrayUpdateKeys[fieldName] = genKey();
state.defaultValueOverrides[`${fieldName}[${previousLength}]`] = value;
});

@@ -1067,3 +1090,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1092,3 +1116,4 @@ `${fieldName}[${numItems - 1}]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1102,3 +1127,4 @@ `${fieldName}[0]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1128,3 +1154,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1134,2 +1161,3 @@ fieldName,

);
state.defaultValueOverrides[`${fieldName}[0]`] = value;
});

@@ -1155,3 +1183,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1161,2 +1190,3 @@ fieldName,

);
state.defaultValueOverrides[`${fieldName}[${insertAtIndex}]`] = value;
});

@@ -1182,3 +1212,4 @@ void get().maybeValidateArrayOperation(

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1217,3 +1248,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1227,3 +1259,4 @@ `${fieldName}[${removeIndex}]`

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1259,3 +1292,4 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],

@@ -1291,6 +1325,8 @@ fieldName,

state.dirtyFields,
state.fieldArrayKeys
state.fieldArrayKeys,
state.defaultValueOverrides
],
`${fieldName}[${index}]`
);
state.defaultValueOverrides[`${fieldName}[${index}]`] = value;
});

@@ -1608,3 +1644,3 @@ void get().maybeValidateArrayOperation(

import {
pathArrayToString as pathArrayToString2
pathArrayToString as pathArrayToString3
} from "@rvf/set-get";

@@ -1672,3 +1708,3 @@ var createFormScope = ({

scope(field) {
const newPrefix = pathArrayToString2([prefix, field].filter(Boolean));
const newPrefix = pathArrayToString3([prefix, field].filter(Boolean));
if (store.subformCache.has(newPrefix))

@@ -1675,0 +1711,0 @@ return store.subformCache.get(newPrefix);

{
"name": "@rvf/core",
"version": "6.1.0",
"version": "7.0.0-beta.0",
"description": "Easy, predictable form state management for React",

@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc