Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tanstack/form-core

Package Overview
Dependencies
Maintainers
5
Versions
217
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/form-core - npm Package Compare versions

Comparing version
1.32.0
to
1.32.1
+10
-0
dist/cjs/FormApi.cjs

@@ -111,2 +111,12 @@ "use strict";

});
if (shouldUpdateValues) {
const helper = metaHelper.metaHelper(this);
for (const fieldKey of Object.keys(
this.fieldInfo
)) {
if (Array.isArray(this.getFieldValue(fieldKey))) {
helper.bumpArrayVersion(fieldKey);
}
}
}
EventClient.formEventClient.emit("form-api", {

@@ -113,0 +123,0 @@ id: this._formId,

+52
-16

@@ -89,9 +89,7 @@ "use strict";

}
const reLineOfOnlyDigits = /^(\d+)$/gm;
const reDigitsBetweenDots = /\.(\d+)(?=\.)/gm;
const reStartWithDigitThenDot = /^(\d+)\./gm;
const reDotWithDigitsToEnd = /\.(\d+$)/gm;
const reMultipleDots = /\.{2,}/gm;
const intPrefix = "__int__";
const intReplace = `${intPrefix}$1`;
const CC_DOT = 46;
const CC_OPEN = 91;
const CC_CLOSE = 93;
const CC_ZERO = 48;
const CC_NINE = 57;
function makePathArray(str) {

@@ -104,13 +102,51 @@ if (Array.isArray(str)) {

}
return str.replace(/(^\[)|]/gm, "").replace(/\[/g, ".").replace(reLineOfOnlyDigits, intReplace).replace(reDigitsBetweenDots, `.${intReplace}.`).replace(reStartWithDigitThenDot, `${intReplace}.`).replace(reDotWithDigitsToEnd, `.${intReplace}`).replace(reMultipleDots, ".").split(".").map((d) => {
if (d.startsWith(intPrefix)) {
const numStr = d.substring(intPrefix.length);
const num = parseInt(numStr, 10);
if (String(num) === numStr) {
return num;
const len = str.length;
const result = [];
let segStart = len > 0 && str.charCodeAt(0) === CC_OPEN ? 1 : 0;
let allDigits = true;
let prev = -1;
for (let i = segStart; i <= len; i++) {
const char = i < len ? str.charCodeAt(i) : -1;
if (i === len || char === CC_DOT || char === CC_OPEN || char === CC_CLOSE) {
const segLen = i - segStart;
if (segLen > 0) {
const treatAsNumber = (
// ...it must contain only digits...
allDigits && // ...and either be a single '0' or not start with '0'.
(segLen === 1 || str.charCodeAt(segStart) !== CC_ZERO)
);
const seg = str.slice(segStart, i);
if (treatAsNumber) {
const num = parseInt(seg, 10);
if (segLen <= 15 || String(num) === seg) {
result.push(num);
} else {
result.push(seg);
}
} else {
result.push(seg);
}
} else if (
// This branch, which handles empty segments, only exists to preserve
// the old behavior for malformed input.
// Push the empty segment unless this is a "phantom boundary" the
// old regex impl would have absorbed:
// 1. `]` was always stripped — `prev === ']'` means the real
// boundary already happened on the previous iteration.
// 2. A leading `]` was stripped too (the leading `[` strip
// above handles its counterpart for `[`).
// 3. `..` and `[[` collapse to a single boundary.
prev !== CC_CLOSE && !(prev === -1 && char === CC_CLOSE) && !(prev === char && (char === CC_DOT || char === CC_OPEN))
) {
result.push("");
}
return numStr;
segStart = i + 1;
allDigits = true;
} else if (char < CC_ZERO || char > CC_NINE) {
allDigits = false;
}
return d;
});
prev = char;
}
if (!result.length) result.push("");
return result;
}

@@ -117,0 +153,0 @@ function concatenatePaths(path1, path2) {

@@ -1,1 +0,1 @@

{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { liteThrottle } from '@tanstack/pacer-lite'\nimport { formEventClient } from './EventClient'\nimport type { ValidationLogicProps } from './ValidationLogic'\nimport type { FieldValidators } from './FieldApi'\nimport type { AnyFormApi, FormValidators } from './FormApi'\nimport type {\n GlobalFormValidationError,\n ValidationCause,\n ValidationError,\n ValidationSource,\n} from './types'\n\nexport type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\n/**\n * @private\n */\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n * @private\n */\nexport function getBy(obj: unknown, path: string | (string | number)[]): any {\n const pathObj = makePathArray(path)\n return pathObj.reduce((current: any, pathPart) => {\n if (current === null) return null\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n * @private\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n if (parent === null) {\n parent = {}\n }\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (Array.isArray(parent) && typeof key === 'number') {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n return doSet(obj)\n}\n\n/**\n * Delete a field on an object using a path, including dot notation.\n * @private\n */\nexport function deleteBy(obj: any, _path: any) {\n const path = makePathArray(_path)\n\n function doDelete(parent: any): any {\n if (!parent) return\n if (path.length === 1) {\n const finalPath = path[0]!\n if (Array.isArray(parent) && typeof finalPath === 'number') {\n return parent.filter((_, i) => i !== finalPath)\n }\n const { [finalPath]: remove, ...rest } = parent\n return rest\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doDelete(parent[key]),\n }\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n if (key >= parent.length) {\n return parent\n }\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doDelete(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n }\n\n throw new Error('It seems we have created an infinite loop in deleteBy. ')\n }\n\n return doDelete(obj)\n}\n\nconst reLineOfOnlyDigits = /^(\\d+)$/gm\n// the second dot must be in a lookahead or the engine\n// will skip subsequent numbers (like foo.0.1.)\nconst reDigitsBetweenDots = /\\.(\\d+)(?=\\.)/gm\nconst reStartWithDigitThenDot = /^(\\d+)\\./gm\nconst reDotWithDigitsToEnd = /\\.(\\d+$)/gm\nconst reMultipleDots = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\n/**\n * @private\n */\nexport function makePathArray(str: string | Array<string | number>) {\n if (Array.isArray(str)) {\n return [...str]\n }\n\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return (\n str\n // Leading `[` may lead to wrong parsing down the line\n // (Example: '[0][1]' should be '0.1', not '.0.1')\n .replace(/(^\\[)|]/gm, '')\n .replace(/\\[/g, '.')\n .replace(reLineOfOnlyDigits, intReplace)\n .replace(reDigitsBetweenDots, `.${intReplace}.`)\n .replace(reStartWithDigitThenDot, `${intReplace}.`)\n .replace(reDotWithDigitsToEnd, `.${intReplace}`)\n .replace(reMultipleDots, '.')\n .split('.')\n .map((d) => {\n if (d.startsWith(intPrefix)) {\n const numStr = d.substring(intPrefix.length)\n const num = parseInt(numStr, 10)\n\n if (String(num) === numStr) {\n return num\n }\n return numStr\n }\n return d\n })\n )\n}\n\n/**\n * @private\n */\nexport function concatenatePaths(path1: string, path2: string): string {\n if (path1.length === 0) return path2\n if (path2.length === 0) return path1\n\n if (path2.startsWith('[')) {\n return path1 + path2\n }\n\n // In cases where parent and child withFieldGroup forms are both nested\n if (path2.startsWith('.')) {\n return path1 + path2\n }\n\n return `${path1}.${path2}`\n}\n\n/**\n * @private\n */\nexport function isNonEmptyArray(obj: any) {\n return !(Array.isArray(obj) && obj.length === 0)\n}\n\ninterface AsyncValidatorArrayPartialOptions<T> {\n validators?: T\n asyncDebounceMs?: number\n}\n\n/**\n * @private\n */\nexport interface AsyncValidator<T> {\n cause: ValidationCause\n validate: T\n debounceMs: number\n}\n\ninterface SyncValidatorArrayPartialOptions<T> {\n validators?: T\n}\n\n/**\n * @private\n */\nexport interface SyncValidator<T> {\n cause: ValidationCause\n validate: T\n}\n\n/**\n * @private\n */\nexport function getSyncValidatorArray<T>(\n cause: ValidationCause,\n options: SyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : never {\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n return {\n cause: validator!.cause,\n validate: validator!.fn,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: false },\n runValidation,\n })\n}\n\n/**\n * @private\n */\nexport function getAsyncValidatorArray<T>(\n cause: ValidationCause,\n options: AsyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : never {\n const { asyncDebounceMs } = options\n const {\n onBlurAsyncDebounceMs,\n onChangeAsyncDebounceMs,\n onDynamicAsyncDebounceMs,\n } = (options.validators || {}) as\n | FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n | FormValidators<any, any, any, any, any, any, any, any, any, any>\n\n const defaultDebounceMs = asyncDebounceMs ?? 0\n\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n const validatorCause = validator?.cause || cause\n\n let debounceMs = defaultDebounceMs\n\n switch (validatorCause) {\n case 'change':\n debounceMs = onChangeAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'blur':\n debounceMs = onBlurAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'dynamic':\n debounceMs = onDynamicAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'submit':\n debounceMs = 0 // submit validators are always run immediately\n break\n default:\n break\n }\n\n if (cause === 'submit') {\n debounceMs = 0\n }\n\n return {\n cause: validatorCause,\n validate: validator!.fn,\n debounceMs: debounceMs,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: true },\n runValidation,\n })\n}\n\nexport const isGlobalFormValidationError = (\n error: unknown,\n): error is GlobalFormValidationError<unknown> => {\n return !!error && typeof error === 'object' && 'fields' in error\n}\n\nexport function evaluate<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n if (objA instanceof Date && objB instanceof Date) {\n return objA.getTime() === objB.getTime()\n }\n\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false\n for (const [k, v] of objA) {\n if (!objB.has(k) || !Object.is(v, objB.get(k))) return false\n }\n return true\n }\n\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false\n for (const v of objA) {\n if (!objB.has(v)) return false\n }\n return true\n }\n\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n // Two distinct non-plain, non-array objects with no own enumerable keys cannot\n // be compared by key iteration — the loop below would vacuously succeed and\n // treat them as equal regardless of their internal state. This covers Temporal\n // types, RegExp, and any class that exposes values only through getters.\n if (\n keysA.length === 0 &&\n !Array.isArray(objA) &&\n !Array.isArray(objB) &&\n (Object.getPrototypeOf(objA) !== Object.prototype ||\n Object.getPrototypeOf(objB) !== Object.prototype)\n ) {\n return false\n }\n\n for (const key of keysA) {\n // performs recursive search down the object tree\n\n if (\n !keysB.includes(key) ||\n !evaluate(objA[key as keyof T], objB[key as keyof T])\n ) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the form level sync/async validation.\n * @private\n */\nexport const determineFormLevelErrorSourceAndValue = ({\n newFormValidatorError,\n isPreviousErrorFromFormValidator,\n previousErrorValue,\n}: {\n newFormValidatorError: ValidationError\n isPreviousErrorFromFormValidator: boolean\n previousErrorValue: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // All falsy values are not considered errors\n if (newFormValidatorError) {\n return { newErrorValue: newFormValidatorError, newSource: 'form' }\n }\n\n // Clears form level error since it's now stale\n if (isPreviousErrorFromFormValidator) {\n return { newErrorValue: undefined, newSource: undefined }\n }\n\n // At this point, we have a preivous error which must have been set by the field validator, keep as is\n if (previousErrorValue) {\n return { newErrorValue: previousErrorValue, newSource: 'field' }\n }\n\n // No new or previous error, clear the error\n return { newErrorValue: undefined, newSource: undefined }\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.\n * @private\n */\nexport const determineFieldLevelErrorSourceAndValue = ({\n formLevelError,\n fieldLevelError,\n}: {\n formLevelError: ValidationError\n fieldLevelError: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // At field level, we prioritize the field level error\n if (fieldLevelError) {\n return { newErrorValue: fieldLevelError, newSource: 'field' }\n }\n\n // If there is no field level error, and there is a form level error, we set the form level error\n if (formLevelError) {\n return { newErrorValue: formLevelError, newSource: 'form' }\n }\n\n return { newErrorValue: undefined, newSource: undefined }\n}\n\nexport function createFieldMap<T>(values: Readonly<T>): { [K in keyof T]: K } {\n const output: { [K in keyof T]: K } = {} as any\n\n for (const key in values) {\n output[key] = key\n }\n\n return output\n}\n\n/**\n * Merge the first parameter with the given overrides.\n * @private\n */\nexport function mergeOpts<T>(\n originalOpts: T | undefined | null,\n overrides: T,\n): T {\n if (originalOpts === undefined || originalOpts === null) {\n return overrides\n }\n\n return { ...originalOpts, ...overrides }\n}\n\n/*\n/ credit is due to https://github.com/lukeed/uuid for this code, with current npm\n/ attacks we didn't feel comfortable installing directly from npm. But big appreciation\n/ from the TanStack Form team <3.\n*/\n\nlet IDX = 256\nconst HEX: string[] = []\nlet BUFFER: number[] | undefined\n\nwhile (IDX--) {\n HEX[IDX] = (IDX + 256).toString(16).substring(1)\n}\n\nexport function uuid(): string {\n let i = 0\n let num: number\n let out = ''\n\n if (!BUFFER || IDX + 16 > 256) {\n BUFFER = new Array<number>(256)\n i = 256\n while (i--) {\n BUFFER[i] = (256 * Math.random()) | 0\n }\n i = 0\n IDX = 0\n }\n\n for (; i < 16; i++) {\n num = BUFFER[IDX + i] as number\n if (i === 6) out += HEX[(num & 15) | 64]\n else if (i === 8) out += HEX[(num & 63) | 128]\n else out += HEX[num]\n\n if (i & 1 && i > 1 && i < 11) out += '-'\n }\n\n IDX++\n return out\n}\n\nexport const throttleFormState = liteThrottle(\n (form: AnyFormApi) =>\n formEventClient.emit('form-state', {\n id: form.formId,\n state: form.store.state,\n }),\n {\n wait: 300,\n },\n)\n\n// Do not use a serialize and deserialize method like JSON.stringify/parse\n// as that will drop functions, dates, undefined, Infinity, NaN, etc.\nexport function deepCopy<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any\n }\n\n if (Array.isArray(obj)) {\n const arrCopy = [] as any[]\n for (let i = 0; i < obj.length; i++) {\n arrCopy[i] = deepCopy(obj[i])\n }\n return arrCopy as any\n }\n\n if (obj instanceof Map) {\n const mapCopy = new Map()\n obj.forEach((value, key) => {\n mapCopy.set(key, deepCopy(value))\n })\n return mapCopy as any\n }\n\n if (obj instanceof Set) {\n const setCopy = new Set()\n obj.forEach((value) => {\n setCopy.add(deepCopy(value))\n })\n return setCopy as any\n }\n\n const copy: { [key: string]: any } = {}\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n copy[key] = deepCopy((obj as any)[key])\n }\n }\n return copy as T\n}\n"],"names":["liteThrottle","formEventClient"],"mappings":";;;;AAqBO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAuC,KAAK,IAC7C;AACN;AAMO,SAAS,MAAM,KAAc,MAAyC;AAC3E,QAAM,UAAU,cAAc,IAAI;AAClC,SAAO,QAAQ,OAAO,CAAC,SAAc,aAAa;AAChD,QAAI,YAAY,KAAM,QAAO;AAC7B,QAAI,OAAO,YAAY,aAAa;AAClC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AACA,WAAO;AAAA,EACT,GAAG,GAAG;AACR;AAMO,SAAS,MAAM,KAAU,OAAY,SAAuB;AACjE,QAAM,OAAO,cAAc,KAAK;AAEhC,WAAS,MAAM,QAAmB;AAChC,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,iBAAiB,SAAS,MAAM;AAAA,IACzC;AAEA,UAAM,MAAM,KAAK,MAAA;AAEjB,QACE,OAAO,QAAQ,YACd,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,MAAM,GACjD;AACA,UAAI,OAAO,WAAW,UAAU;AAC9B,YAAI,WAAW,MAAM;AACnB,mBAAS,CAAA;AAAA,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AAChB,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,cAAQ,CAAC,IAAI,SAAS,IAAI,CAAC,CAAC;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,8BAAc,IAAA;AACpB,QAAI,QAAQ,CAAC,OAAO,QAAQ;AAC1B,cAAQ,IAAI,KAAK,SAAS,KAAK,CAAC;AAAA,IAClC,CAAC;AACD,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,8BAAc,IAAA;AACpB,QAAI,QAAQ,CAAC,UAAU;AACrB,cAAQ,IAAI,SAAS,KAAK,CAAC;AAAA,IAC7B,CAAC;AACD,WAAO;AAAA,EACT;AAEA,QAAM,OAA+B,CAAA;AACrC,aAAW,OAAO,KAAK;AACrB,QAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AAClD,WAAK,GAAG,IAAI,SAAU,IAAY,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACA,SAAO;AACT;;;;;;;;;;;;;;;;;;;"}
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { liteThrottle } from '@tanstack/pacer-lite'\nimport { formEventClient } from './EventClient'\nimport type { ValidationLogicProps } from './ValidationLogic'\nimport type { FieldValidators } from './FieldApi'\nimport type { AnyFormApi, FormValidators } from './FormApi'\nimport type {\n GlobalFormValidationError,\n ValidationCause,\n ValidationError,\n ValidationSource,\n} from './types'\n\nexport type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\n/**\n * @private\n */\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n * @private\n */\nexport function getBy(obj: unknown, path: string | (string | number)[]): any {\n const pathObj = makePathArray(path)\n return pathObj.reduce((current: any, pathPart) => {\n if (current === null) return null\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n * @private\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n if (parent === null) {\n parent = {}\n }\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (Array.isArray(parent) && typeof key === 'number') {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n return doSet(obj)\n}\n\n/**\n * Delete a field on an object using a path, including dot notation.\n * @private\n */\nexport function deleteBy(obj: any, _path: any) {\n const path = makePathArray(_path)\n\n function doDelete(parent: any): any {\n if (!parent) return\n if (path.length === 1) {\n const finalPath = path[0]!\n if (Array.isArray(parent) && typeof finalPath === 'number') {\n return parent.filter((_, i) => i !== finalPath)\n }\n const { [finalPath]: remove, ...rest } = parent\n return rest\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doDelete(parent[key]),\n }\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n if (key >= parent.length) {\n return parent\n }\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doDelete(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n }\n\n throw new Error('It seems we have created an infinite loop in deleteBy. ')\n }\n\n return doDelete(obj)\n}\n\n// Char codes used by the parser below.\nconst CC_DOT = 0x2e // '.'\nconst CC_OPEN = 0x5b // '['\nconst CC_CLOSE = 0x5d // ']'\nconst CC_ZERO = 0x30 // '0'\nconst CC_NINE = 0x39 // '9'\n\n/**\n * @private\n */\nexport function makePathArray(str: string | Array<string | number>) {\n if (Array.isArray(str)) {\n return [...str]\n }\n\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n const len = str.length\n const result: Array<string | number> = []\n // Location of the first character of the in-progress segment in `str`.\n // The segment ends at the current `i` when we hit a separator.\n //\n // We strip an optional leading '[' so '[0]' parses as [0], not ['', 0].\n // Doing this up front keeps the loop's backwards compatibility handling simpler.\n let segStart = len > 0 && str.charCodeAt(0) === CC_OPEN ? 1 : 0\n // Whether the in-progress segment has been all ASCII digits so far.\n // Used together with the leading-zero check to decide if it should be\n // pushed as a number instead of a string.\n let allDigits = true\n // Tracks the previous character. Only necessary to preserve the\n // old behavior for malformed input.\n let prev = -1\n // Walk once. `i === len` is treated as a virtual final separator so the\n // flush block handles both mid-string segments and the last one.\n for (let i = segStart; i <= len; i++) {\n const char = i < len ? str.charCodeAt(i) : -1\n\n // Handle separators (including the virtual one at the end). Flush the in-progress segment.\n if (i === len || char === CC_DOT || char === CC_OPEN || char === CC_CLOSE) {\n const segLen = i - segStart\n if (segLen > 0) {\n // To treat the segment as a number...\n const treatAsNumber =\n // ...it must contain only digits...\n allDigits &&\n // ...and either be a single '0' or not start with '0'.\n (segLen === 1 || str.charCodeAt(segStart) !== CC_ZERO)\n\n const seg = str.slice(segStart, i)\n if (treatAsNumber) {\n const num = parseInt(seg, 10)\n // Up to 15 digits, parseInt is always lossless (the max\n // 15-digit decimal is below Number.MAX_SAFE_INTEGER). Beyond\n // that, verify by round-trip: if parseInt lost precision\n // (e.g., a 20-digit literal), fall back to the string so we\n // don't silently change the value.\n if (segLen <= 15 || String(num) === seg) {\n result.push(num)\n } else {\n result.push(seg)\n }\n } else {\n result.push(seg)\n }\n } else if (\n // This branch, which handles empty segments, only exists to preserve\n // the old behavior for malformed input.\n\n // Push the empty segment unless this is a \"phantom boundary\" the\n // old regex impl would have absorbed:\n // 1. `]` was always stripped — `prev === ']'` means the real\n // boundary already happened on the previous iteration.\n // 2. A leading `]` was stripped too (the leading `[` strip\n // above handles its counterpart for `[`).\n // 3. `..` and `[[` collapse to a single boundary.\n prev !== CC_CLOSE &&\n !(prev === -1 && char === CC_CLOSE) &&\n !(prev === char && (char === CC_DOT || char === CC_OPEN))\n ) {\n result.push('')\n }\n\n // Start a new segment.\n segStart = i + 1\n allDigits = true\n } else if (char < CC_ZERO || char > CC_NINE) {\n allDigits = false\n }\n\n prev = char\n }\n\n // If the input was effectively all phantom chars (e.g. ']', '[]',\n // '[]]'), the loop produces no segments. The old impl returned ['']\n // for these because.\n if (!result.length) result.push('')\n\n return result\n}\n\n/**\n * @private\n */\nexport function concatenatePaths(path1: string, path2: string): string {\n if (path1.length === 0) return path2\n if (path2.length === 0) return path1\n\n if (path2.startsWith('[')) {\n return path1 + path2\n }\n\n // In cases where parent and child withFieldGroup forms are both nested\n if (path2.startsWith('.')) {\n return path1 + path2\n }\n\n return `${path1}.${path2}`\n}\n\n/**\n * @private\n */\nexport function isNonEmptyArray(obj: any) {\n return !(Array.isArray(obj) && obj.length === 0)\n}\n\ninterface AsyncValidatorArrayPartialOptions<T> {\n validators?: T\n asyncDebounceMs?: number\n}\n\n/**\n * @private\n */\nexport interface AsyncValidator<T> {\n cause: ValidationCause\n validate: T\n debounceMs: number\n}\n\ninterface SyncValidatorArrayPartialOptions<T> {\n validators?: T\n}\n\n/**\n * @private\n */\nexport interface SyncValidator<T> {\n cause: ValidationCause\n validate: T\n}\n\n/**\n * @private\n */\nexport function getSyncValidatorArray<T>(\n cause: ValidationCause,\n options: SyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : never {\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n return {\n cause: validator!.cause,\n validate: validator!.fn,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: false },\n runValidation,\n })\n}\n\n/**\n * @private\n */\nexport function getAsyncValidatorArray<T>(\n cause: ValidationCause,\n options: AsyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : never {\n const { asyncDebounceMs } = options\n const {\n onBlurAsyncDebounceMs,\n onChangeAsyncDebounceMs,\n onDynamicAsyncDebounceMs,\n } = (options.validators || {}) as\n | FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n | FormValidators<any, any, any, any, any, any, any, any, any, any>\n\n const defaultDebounceMs = asyncDebounceMs ?? 0\n\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n const validatorCause = validator?.cause || cause\n\n let debounceMs = defaultDebounceMs\n\n switch (validatorCause) {\n case 'change':\n debounceMs = onChangeAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'blur':\n debounceMs = onBlurAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'dynamic':\n debounceMs = onDynamicAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'submit':\n debounceMs = 0 // submit validators are always run immediately\n break\n default:\n break\n }\n\n if (cause === 'submit') {\n debounceMs = 0\n }\n\n return {\n cause: validatorCause,\n validate: validator!.fn,\n debounceMs: debounceMs,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: true },\n runValidation,\n })\n}\n\nexport const isGlobalFormValidationError = (\n error: unknown,\n): error is GlobalFormValidationError<unknown> => {\n return !!error && typeof error === 'object' && 'fields' in error\n}\n\nexport function evaluate<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n if (objA instanceof Date && objB instanceof Date) {\n return objA.getTime() === objB.getTime()\n }\n\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false\n for (const [k, v] of objA) {\n if (!objB.has(k) || !Object.is(v, objB.get(k))) return false\n }\n return true\n }\n\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false\n for (const v of objA) {\n if (!objB.has(v)) return false\n }\n return true\n }\n\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n // Two distinct non-plain, non-array objects with no own enumerable keys cannot\n // be compared by key iteration — the loop below would vacuously succeed and\n // treat them as equal regardless of their internal state. This covers Temporal\n // types, RegExp, and any class that exposes values only through getters.\n if (\n keysA.length === 0 &&\n !Array.isArray(objA) &&\n !Array.isArray(objB) &&\n (Object.getPrototypeOf(objA) !== Object.prototype ||\n Object.getPrototypeOf(objB) !== Object.prototype)\n ) {\n return false\n }\n\n for (const key of keysA) {\n // performs recursive search down the object tree\n\n if (\n !keysB.includes(key) ||\n !evaluate(objA[key as keyof T], objB[key as keyof T])\n ) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the form level sync/async validation.\n * @private\n */\nexport const determineFormLevelErrorSourceAndValue = ({\n newFormValidatorError,\n isPreviousErrorFromFormValidator,\n previousErrorValue,\n}: {\n newFormValidatorError: ValidationError\n isPreviousErrorFromFormValidator: boolean\n previousErrorValue: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // All falsy values are not considered errors\n if (newFormValidatorError) {\n return { newErrorValue: newFormValidatorError, newSource: 'form' }\n }\n\n // Clears form level error since it's now stale\n if (isPreviousErrorFromFormValidator) {\n return { newErrorValue: undefined, newSource: undefined }\n }\n\n // At this point, we have a preivous error which must have been set by the field validator, keep as is\n if (previousErrorValue) {\n return { newErrorValue: previousErrorValue, newSource: 'field' }\n }\n\n // No new or previous error, clear the error\n return { newErrorValue: undefined, newSource: undefined }\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.\n * @private\n */\nexport const determineFieldLevelErrorSourceAndValue = ({\n formLevelError,\n fieldLevelError,\n}: {\n formLevelError: ValidationError\n fieldLevelError: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // At field level, we prioritize the field level error\n if (fieldLevelError) {\n return { newErrorValue: fieldLevelError, newSource: 'field' }\n }\n\n // If there is no field level error, and there is a form level error, we set the form level error\n if (formLevelError) {\n return { newErrorValue: formLevelError, newSource: 'form' }\n }\n\n return { newErrorValue: undefined, newSource: undefined }\n}\n\nexport function createFieldMap<T>(values: Readonly<T>): { [K in keyof T]: K } {\n const output: { [K in keyof T]: K } = {} as any\n\n for (const key in values) {\n output[key] = key\n }\n\n return output\n}\n\n/**\n * Merge the first parameter with the given overrides.\n * @private\n */\nexport function mergeOpts<T>(\n originalOpts: T | undefined | null,\n overrides: T,\n): T {\n if (originalOpts === undefined || originalOpts === null) {\n return overrides\n }\n\n return { ...originalOpts, ...overrides }\n}\n\n/*\n/ credit is due to https://github.com/lukeed/uuid for this code, with current npm\n/ attacks we didn't feel comfortable installing directly from npm. But big appreciation\n/ from the TanStack Form team <3.\n*/\n\nlet IDX = 256\nconst HEX: string[] = []\nlet BUFFER: number[] | undefined\n\nwhile (IDX--) {\n HEX[IDX] = (IDX + 256).toString(16).substring(1)\n}\n\nexport function uuid(): string {\n let i = 0\n let num: number\n let out = ''\n\n if (!BUFFER || IDX + 16 > 256) {\n BUFFER = new Array<number>(256)\n i = 256\n while (i--) {\n BUFFER[i] = (256 * Math.random()) | 0\n }\n i = 0\n IDX = 0\n }\n\n for (; i < 16; i++) {\n num = BUFFER[IDX + i] as number\n if (i === 6) out += HEX[(num & 15) | 64]\n else if (i === 8) out += HEX[(num & 63) | 128]\n else out += HEX[num]\n\n if (i & 1 && i > 1 && i < 11) out += '-'\n }\n\n IDX++\n return out\n}\n\nexport const throttleFormState = liteThrottle(\n (form: AnyFormApi) =>\n formEventClient.emit('form-state', {\n id: form.formId,\n state: form.store.state,\n }),\n {\n wait: 300,\n },\n)\n\n// Do not use a serialize and deserialize method like JSON.stringify/parse\n// as that will drop functions, dates, undefined, Infinity, NaN, etc.\nexport function deepCopy<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any\n }\n\n if (Array.isArray(obj)) {\n const arrCopy = [] as any[]\n for (let i = 0; i < obj.length; i++) {\n arrCopy[i] = deepCopy(obj[i])\n }\n return arrCopy as any\n }\n\n if (obj instanceof Map) {\n const mapCopy = new Map()\n obj.forEach((value, key) => {\n mapCopy.set(key, deepCopy(value))\n })\n return mapCopy as any\n }\n\n if (obj instanceof Set) {\n const setCopy = new Set()\n obj.forEach((value) => {\n setCopy.add(deepCopy(value))\n })\n return setCopy as any\n }\n\n const copy: { [key: string]: any } = {}\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n copy[key] = deepCopy((obj as any)[key])\n }\n }\n return copy as T\n}\n"],"names":["liteThrottle","formEventClient"],"mappings":";;;;AAqBO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAuC,KAAK,IAC7C;AACN;AAMO,SAAS,MAAM,KAAc,MAAyC;AAC3E,QAAM,UAAU,cAAc,IAAI;AAClC,SAAO,QAAQ,OAAO,CAAC,SAAc,aAAa;AAChD,QAAI,YAAY,KAAM,QAAO;AAC7B,QAAI,OAAO,YAAY,aAAa;AAClC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AACA,WAAO;AAAA,EACT,GAAG,GAAG;AACR;AAMO,SAAS,MAAM,KAAU,OAAY,SAAuB;AACjE,QAAM,OAAO,cAAc,KAAK;AAEhC,WAAS,MAAM,QAAmB;AAChC,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,iBAAiB,SAAS,MAAM;AAAA,IACzC;AAEA,UAAM,MAAM,KAAK,MAAA;AAEjB,QACE,OAAO,QAAQ,YACd,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,MAAM,GACjD;AACA,UAAI,OAAO,WAAW,UAAU;AAC9B,YAAI,WAAW,MAAM;AACnB,mBAAS,CAAA;AAAA,QACX;AACA,eAAO;AAAA,UACL,GAAG;AAAA,UACH,CAAC,GAAG,GAAG,MAAM,OAAO,GAAG,CAAC;AAAA,QAAA;AAAA,MAE5B;AACA,aAAO;AAAA,QACL,CAAC,GAAG,GAAG,MAAA;AAAA,MAAM;AAAA,IAEjB;AAEA,QAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,UAAU;AACpD,YAAM,SAAS,OAAO,MAAM,GAAG,GAAG;AAClC,aAAO;AAAA,QACL,GAAI,OAAO,SAAS,SAAS,IAAI,MAAM,GAAG;AAAA,QAC1C,MAAM,OAAO,GA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U;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,SAAS;AAAA,EAC/B;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,UAAM,UAAU,CAAA;AAChB,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,cAAQ,CAAC,IAAI,SAAS,IAAI,CAAC,CAAC;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,8BAAc,IAAA;AACpB,QAAI,QAAQ,CAAC,OAAO,QAAQ;AAC1B,cAAQ,IAAI,KAAK,SAAS,KAAK,CAAC;AAAA,IAClC,CAAC;AACD,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,8BAAc,IAAA;AACpB,QAAI,QAAQ,CAAC,UAAU;AACrB,cAAQ,IAAI,SAAS,KAAK,CAAC;AAAA,IAC7B,CAAC;AACD,WAAO;AAAA,EACT;AAEA,QAAM,OAA+B,CAAA;AACrC,aAAW,OAAO,KAAK;AACrB,QAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AAClD,WAAK,GAAG,IAAI,SAAU,IAAY,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACA,SAAO;AACT;;;;;;;;;;;;;;;;;;;"}

@@ -109,2 +109,12 @@ import { batch, createStore } from "@tanstack/store";

});
if (shouldUpdateValues) {
const helper = metaHelper(this);
for (const fieldKey of Object.keys(
this.fieldInfo
)) {
if (Array.isArray(this.getFieldValue(fieldKey))) {
helper.bumpArrayVersion(fieldKey);
}
}
}
formEventClient.emit("form-api", {

@@ -111,0 +121,0 @@ id: this._formId,

@@ -87,9 +87,7 @@ import { liteThrottle } from "@tanstack/pacer-lite";

}
const reLineOfOnlyDigits = /^(\d+)$/gm;
const reDigitsBetweenDots = /\.(\d+)(?=\.)/gm;
const reStartWithDigitThenDot = /^(\d+)\./gm;
const reDotWithDigitsToEnd = /\.(\d+$)/gm;
const reMultipleDots = /\.{2,}/gm;
const intPrefix = "__int__";
const intReplace = `${intPrefix}$1`;
const CC_DOT = 46;
const CC_OPEN = 91;
const CC_CLOSE = 93;
const CC_ZERO = 48;
const CC_NINE = 57;
function makePathArray(str) {

@@ -102,13 +100,51 @@ if (Array.isArray(str)) {

}
return str.replace(/(^\[)|]/gm, "").replace(/\[/g, ".").replace(reLineOfOnlyDigits, intReplace).replace(reDigitsBetweenDots, `.${intReplace}.`).replace(reStartWithDigitThenDot, `${intReplace}.`).replace(reDotWithDigitsToEnd, `.${intReplace}`).replace(reMultipleDots, ".").split(".").map((d) => {
if (d.startsWith(intPrefix)) {
const numStr = d.substring(intPrefix.length);
const num = parseInt(numStr, 10);
if (String(num) === numStr) {
return num;
const len = str.length;
const result = [];
let segStart = len > 0 && str.charCodeAt(0) === CC_OPEN ? 1 : 0;
let allDigits = true;
let prev = -1;
for (let i = segStart; i <= len; i++) {
const char = i < len ? str.charCodeAt(i) : -1;
if (i === len || char === CC_DOT || char === CC_OPEN || char === CC_CLOSE) {
const segLen = i - segStart;
if (segLen > 0) {
const treatAsNumber = (
// ...it must contain only digits...
allDigits && // ...and either be a single '0' or not start with '0'.
(segLen === 1 || str.charCodeAt(segStart) !== CC_ZERO)
);
const seg = str.slice(segStart, i);
if (treatAsNumber) {
const num = parseInt(seg, 10);
if (segLen <= 15 || String(num) === seg) {
result.push(num);
} else {
result.push(seg);
}
} else {
result.push(seg);
}
} else if (
// This branch, which handles empty segments, only exists to preserve
// the old behavior for malformed input.
// Push the empty segment unless this is a "phantom boundary" the
// old regex impl would have absorbed:
// 1. `]` was always stripped — `prev === ']'` means the real
// boundary already happened on the previous iteration.
// 2. A leading `]` was stripped too (the leading `[` strip
// above handles its counterpart for `[`).
// 3. `..` and `[[` collapse to a single boundary.
prev !== CC_CLOSE && !(prev === -1 && char === CC_CLOSE) && !(prev === char && (char === CC_DOT || char === CC_OPEN))
) {
result.push("");
}
return numStr;
segStart = i + 1;
allDigits = true;
} else if (char < CC_ZERO || char > CC_NINE) {
allDigits = false;
}
return d;
});
prev = char;
}
if (!result.length) result.push("");
return result;
}

@@ -115,0 +151,0 @@ function concatenatePaths(path1, path2) {

@@ -1,1 +0,1 @@

{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { liteThrottle } from '@tanstack/pacer-lite'\nimport { formEventClient } from './EventClient'\nimport type { ValidationLogicProps } from './ValidationLogic'\nimport type { FieldValidators } from './FieldApi'\nimport type { AnyFormApi, FormValidators } from './FormApi'\nimport type {\n GlobalFormValidationError,\n ValidationCause,\n ValidationError,\n ValidationSource,\n} from './types'\n\nexport type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\n/**\n * @private\n */\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n * @private\n */\nexport function getBy(obj: unknown, path: string | (string | number)[]): any {\n const pathObj = makePathArray(path)\n return pathObj.reduce((current: any, pathPart) => {\n if (current === null) return null\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n * @private\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n if (parent === null) {\n parent = {}\n }\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (Array.isArray(parent) && typeof key === 'number') {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n return doSet(obj)\n}\n\n/**\n * Delete a field on an object using a path, including dot notation.\n * @private\n */\nexport function deleteBy(obj: any, _path: any) {\n const path = makePathArray(_path)\n\n function doDelete(parent: any): any {\n if (!parent) return\n if (path.length === 1) {\n const finalPath = path[0]!\n if (Array.isArray(parent) && typeof finalPath === 'number') {\n return parent.filter((_, i) => i !== finalPath)\n }\n const { [finalPath]: remove, ...rest } = parent\n return rest\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doDelete(parent[key]),\n }\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n if (key >= parent.length) {\n return parent\n }\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doDelete(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n }\n\n throw new Error('It seems we have created an infinite loop in deleteBy. ')\n }\n\n return doDelete(obj)\n}\n\nconst reLineOfOnlyDigits = /^(\\d+)$/gm\n// the second dot must be in a lookahead or the engine\n// will skip subsequent numbers (like foo.0.1.)\nconst reDigitsBetweenDots = /\\.(\\d+)(?=\\.)/gm\nconst reStartWithDigitThenDot = /^(\\d+)\\./gm\nconst reDotWithDigitsToEnd = /\\.(\\d+$)/gm\nconst reMultipleDots = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\n/**\n * @private\n */\nexport function makePathArray(str: string | Array<string | number>) {\n if (Array.isArray(str)) {\n return [...str]\n }\n\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return (\n str\n // Leading `[` may lead to wrong parsing down the line\n // (Example: '[0][1]' should be '0.1', not '.0.1')\n .replace(/(^\\[)|]/gm, '')\n .replace(/\\[/g, '.')\n .replace(reLineOfOnlyDigits, intReplace)\n .replace(reDigitsBetweenDots, `.${intReplace}.`)\n .replace(reStartWithDigitThenDot, `${intReplace}.`)\n .replace(reDotWithDigitsToEnd, `.${intReplace}`)\n .replace(reMultipleDots, '.')\n .split('.')\n .map((d) => {\n if (d.startsWith(intPrefix)) {\n const numStr = d.substring(intPrefix.length)\n const num = parseInt(numStr, 10)\n\n if (String(num) === numStr) {\n return num\n }\n return numStr\n }\n return d\n })\n )\n}\n\n/**\n * @private\n */\nexport function concatenatePaths(path1: string, path2: string): string {\n if (path1.length === 0) return path2\n if (path2.length === 0) return path1\n\n if (path2.startsWith('[')) {\n return path1 + path2\n }\n\n // In cases where parent and child withFieldGroup forms are both nested\n if (path2.startsWith('.')) {\n return path1 + path2\n }\n\n return `${path1}.${path2}`\n}\n\n/**\n * @private\n */\nexport function isNonEmptyArray(obj: any) {\n return !(Array.isArray(obj) && obj.length === 0)\n}\n\ninterface AsyncValidatorArrayPartialOptions<T> {\n validators?: T\n asyncDebounceMs?: number\n}\n\n/**\n * @private\n */\nexport interface AsyncValidator<T> {\n cause: ValidationCause\n validate: T\n debounceMs: number\n}\n\ninterface SyncValidatorArrayPartialOptions<T> {\n validators?: T\n}\n\n/**\n * @private\n */\nexport interface SyncValidator<T> {\n cause: ValidationCause\n validate: T\n}\n\n/**\n * @private\n */\nexport function getSyncValidatorArray<T>(\n cause: ValidationCause,\n options: SyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : never {\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n return {\n cause: validator!.cause,\n validate: validator!.fn,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: false },\n runValidation,\n })\n}\n\n/**\n * @private\n */\nexport function getAsyncValidatorArray<T>(\n cause: ValidationCause,\n options: AsyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : never {\n const { asyncDebounceMs } = options\n const {\n onBlurAsyncDebounceMs,\n onChangeAsyncDebounceMs,\n onDynamicAsyncDebounceMs,\n } = (options.validators || {}) as\n | FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n | FormValidators<any, any, any, any, any, any, any, any, any, any>\n\n const defaultDebounceMs = asyncDebounceMs ?? 0\n\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n const validatorCause = validator?.cause || cause\n\n let debounceMs = defaultDebounceMs\n\n switch (validatorCause) {\n case 'change':\n debounceMs = onChangeAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'blur':\n debounceMs = onBlurAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'dynamic':\n debounceMs = onDynamicAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'submit':\n debounceMs = 0 // submit validators are always run immediately\n break\n default:\n break\n }\n\n if (cause === 'submit') {\n debounceMs = 0\n }\n\n return {\n cause: validatorCause,\n validate: validator!.fn,\n debounceMs: debounceMs,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: true },\n runValidation,\n })\n}\n\nexport const isGlobalFormValidationError = (\n error: unknown,\n): error is GlobalFormValidationError<unknown> => {\n return !!error && typeof error === 'object' && 'fields' in error\n}\n\nexport function evaluate<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n if (objA instanceof Date && objB instanceof Date) {\n return objA.getTime() === objB.getTime()\n }\n\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false\n for (const [k, v] of objA) {\n if (!objB.has(k) || !Object.is(v, objB.get(k))) return false\n }\n return true\n }\n\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false\n for (const v of objA) {\n if (!objB.has(v)) return false\n }\n return true\n }\n\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n // Two distinct non-plain, non-array objects with no own enumerable keys cannot\n // be compared by key iteration — the loop below would vacuously succeed and\n // treat them as equal regardless of their internal state. This covers Temporal\n // types, RegExp, and any class that exposes values only through getters.\n if (\n keysA.length === 0 &&\n !Array.isArray(objA) &&\n !Array.isArray(objB) &&\n (Object.getPrototypeOf(objA) !== Object.prototype ||\n Object.getPrototypeOf(objB) !== Object.prototype)\n ) {\n return false\n }\n\n for (const key of keysA) {\n // performs recursive search down the object tree\n\n if (\n !keysB.includes(key) ||\n !evaluate(objA[key as keyof T], objB[key as keyof T])\n ) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the form level sync/async validation.\n * @private\n */\nexport const determineFormLevelErrorSourceAndValue = ({\n newFormValidatorError,\n isPreviousErrorFromFormValidator,\n previousErrorValue,\n}: {\n newFormValidatorError: ValidationError\n isPreviousErrorFromFormValidator: boolean\n previousErrorValue: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // All falsy values are not considered errors\n if (newFormValidatorError) {\n return { newErrorValue: newFormValidatorError, newSource: 'form' }\n }\n\n // Clears form level error since it's now stale\n if (isPreviousErrorFromFormValidator) {\n return { newErrorValue: undefined, newSource: undefined }\n }\n\n // At this point, we have a preivous error which must have been set by the field validator, keep as is\n if (previousErrorValue) {\n return { newErrorValue: previousErrorValue, newSource: 'field' }\n }\n\n // No new or previous error, clear the error\n return { newErrorValue: undefined, newSource: undefined }\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.\n * @private\n */\nexport const determineFieldLevelErrorSourceAndValue = ({\n formLevelError,\n fieldLevelError,\n}: {\n formLevelError: ValidationError\n fieldLevelError: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // At field level, we prioritize the field level error\n if (fieldLevelError) {\n return { newErrorValue: fieldLevelError, newSource: 'field' }\n }\n\n // If there is no field level error, and there is a form level error, we set the form level error\n if (formLevelError) {\n return { newErrorValue: formLevelError, newSource: 'form' }\n }\n\n return { newErrorValue: undefined, newSource: undefined }\n}\n\nexport function createFieldMap<T>(values: Readonly<T>): { [K in keyof T]: K } {\n const output: { [K in keyof T]: K } = {} as any\n\n for (const key in values) {\n output[key] = key\n }\n\n return output\n}\n\n/**\n * Merge the first parameter with the given overrides.\n * @private\n */\nexport function mergeOpts<T>(\n originalOpts: T | undefined | null,\n overrides: T,\n): T {\n if (originalOpts === undefined || originalOpts === null) {\n return overrides\n }\n\n return { ...originalOpts, ...overrides }\n}\n\n/*\n/ credit is due to https://github.com/lukeed/uuid for this code, with current npm\n/ attacks we didn't feel comfortable installing directly from npm. But big appreciation\n/ from the TanStack Form team <3.\n*/\n\nlet IDX = 256\nconst HEX: string[] = []\nlet BUFFER: number[] | undefined\n\nwhile (IDX--) {\n HEX[IDX] = (IDX + 256).toString(16).substring(1)\n}\n\nexport function uuid(): string {\n let i = 0\n let num: number\n let out = ''\n\n if (!BUFFER || IDX + 16 > 256) {\n BUFFER = new Array<number>(256)\n i = 256\n while (i--) {\n BUFFER[i] = (256 * Math.random()) | 0\n }\n i = 0\n IDX = 0\n }\n\n for (; i < 16; i++) {\n num = BUFFER[IDX + i] as number\n if (i === 6) out += HEX[(num & 15) | 64]\n else if (i === 8) out += HEX[(num & 63) | 128]\n else out += HEX[num]\n\n if (i & 1 && i > 1 && i < 11) out += '-'\n }\n\n IDX++\n return out\n}\n\nexport const throttleFormState = liteThrottle(\n (form: AnyFormApi) =>\n formEventClient.emit('form-state', {\n id: form.formId,\n state: form.store.state,\n }),\n {\n wait: 300,\n },\n)\n\n// Do not use a serialize and deserialize method like JSON.stringify/parse\n// as that will drop functions, dates, undefined, Infinity, NaN, etc.\nexport function deepCopy<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any\n }\n\n if (Array.isArray(obj)) {\n const arrCopy = [] as any[]\n for (let i = 0; i < obj.length; i++) {\n arrCopy[i] = deepCopy(obj[i])\n }\n return arrCopy as any\n }\n\n if (obj instanceof Map) {\n const mapCopy = new Map()\n obj.forEach((value, key) => {\n mapCopy.set(key, deepCopy(value))\n })\n return mapCopy as any\n }\n\n if (obj instanceof Set) {\n const setCopy = new Set()\n obj.forEach((value) => {\n setCopy.add(deepCopy(value))\n })\n return setCopy as any\n }\n\n const copy: { [key: string]: any } = {}\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n copy[key] = deepCopy((obj as any)[key])\n }\n }\n return copy as T\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAuC,KAAK,IAC7C;AACN;AA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;AACT;"}
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { liteThrottle } from '@tanstack/pacer-lite'\nimport { formEventClient } from './EventClient'\nimport type { ValidationLogicProps } from './ValidationLogic'\nimport type { FieldValidators } from './FieldApi'\nimport type { AnyFormApi, FormValidators } from './FormApi'\nimport type {\n GlobalFormValidationError,\n ValidationCause,\n ValidationError,\n ValidationSource,\n} from './types'\n\nexport type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\n/**\n * @private\n */\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n * @private\n */\nexport function getBy(obj: unknown, path: string | (string | number)[]): any {\n const pathObj = makePathArray(path)\n return pathObj.reduce((current: any, pathPart) => {\n if (current === null) return null\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n * @private\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n if (parent === null) {\n parent = {}\n }\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (Array.isArray(parent) && typeof key === 'number') {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n return doSet(obj)\n}\n\n/**\n * Delete a field on an object using a path, including dot notation.\n * @private\n */\nexport function deleteBy(obj: any, _path: any) {\n const path = makePathArray(_path)\n\n function doDelete(parent: any): any {\n if (!parent) return\n if (path.length === 1) {\n const finalPath = path[0]!\n if (Array.isArray(parent) && typeof finalPath === 'number') {\n return parent.filter((_, i) => i !== finalPath)\n }\n const { [finalPath]: remove, ...rest } = parent\n return rest\n }\n\n const key = path.shift()\n\n if (\n typeof key === 'string' ||\n (typeof key === 'number' && !Array.isArray(parent))\n ) {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doDelete(parent[key]),\n }\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n if (key >= parent.length) {\n return parent\n }\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doDelete(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n }\n\n throw new Error('It seems we have created an infinite loop in deleteBy. ')\n }\n\n return doDelete(obj)\n}\n\n// Char codes used by the parser below.\nconst CC_DOT = 0x2e // '.'\nconst CC_OPEN = 0x5b // '['\nconst CC_CLOSE = 0x5d // ']'\nconst CC_ZERO = 0x30 // '0'\nconst CC_NINE = 0x39 // '9'\n\n/**\n * @private\n */\nexport function makePathArray(str: string | Array<string | number>) {\n if (Array.isArray(str)) {\n return [...str]\n }\n\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n const len = str.length\n const result: Array<string | number> = []\n // Location of the first character of the in-progress segment in `str`.\n // The segment ends at the current `i` when we hit a separator.\n //\n // We strip an optional leading '[' so '[0]' parses as [0], not ['', 0].\n // Doing this up front keeps the loop's backwards compatibility handling simpler.\n let segStart = len > 0 && str.charCodeAt(0) === CC_OPEN ? 1 : 0\n // Whether the in-progress segment has been all ASCII digits so far.\n // Used together with the leading-zero check to decide if it should be\n // pushed as a number instead of a string.\n let allDigits = true\n // Tracks the previous character. Only necessary to preserve the\n // old behavior for malformed input.\n let prev = -1\n // Walk once. `i === len` is treated as a virtual final separator so the\n // flush block handles both mid-string segments and the last one.\n for (let i = segStart; i <= len; i++) {\n const char = i < len ? str.charCodeAt(i) : -1\n\n // Handle separators (including the virtual one at the end). Flush the in-progress segment.\n if (i === len || char === CC_DOT || char === CC_OPEN || char === CC_CLOSE) {\n const segLen = i - segStart\n if (segLen > 0) {\n // To treat the segment as a number...\n const treatAsNumber =\n // ...it must contain only digits...\n allDigits &&\n // ...and either be a single '0' or not start with '0'.\n (segLen === 1 || str.charCodeAt(segStart) !== CC_ZERO)\n\n const seg = str.slice(segStart, i)\n if (treatAsNumber) {\n const num = parseInt(seg, 10)\n // Up to 15 digits, parseInt is always lossless (the max\n // 15-digit decimal is below Number.MAX_SAFE_INTEGER). Beyond\n // that, verify by round-trip: if parseInt lost precision\n // (e.g., a 20-digit literal), fall back to the string so we\n // don't silently change the value.\n if (segLen <= 15 || String(num) === seg) {\n result.push(num)\n } else {\n result.push(seg)\n }\n } else {\n result.push(seg)\n }\n } else if (\n // This branch, which handles empty segments, only exists to preserve\n // the old behavior for malformed input.\n\n // Push the empty segment unless this is a \"phantom boundary\" the\n // old regex impl would have absorbed:\n // 1. `]` was always stripped — `prev === ']'` means the real\n // boundary already happened on the previous iteration.\n // 2. A leading `]` was stripped too (the leading `[` strip\n // above handles its counterpart for `[`).\n // 3. `..` and `[[` collapse to a single boundary.\n prev !== CC_CLOSE &&\n !(prev === -1 && char === CC_CLOSE) &&\n !(prev === char && (char === CC_DOT || char === CC_OPEN))\n ) {\n result.push('')\n }\n\n // Start a new segment.\n segStart = i + 1\n allDigits = true\n } else if (char < CC_ZERO || char > CC_NINE) {\n allDigits = false\n }\n\n prev = char\n }\n\n // If the input was effectively all phantom chars (e.g. ']', '[]',\n // '[]]'), the loop produces no segments. The old impl returned ['']\n // for these because.\n if (!result.length) result.push('')\n\n return result\n}\n\n/**\n * @private\n */\nexport function concatenatePaths(path1: string, path2: string): string {\n if (path1.length === 0) return path2\n if (path2.length === 0) return path1\n\n if (path2.startsWith('[')) {\n return path1 + path2\n }\n\n // In cases where parent and child withFieldGroup forms are both nested\n if (path2.startsWith('.')) {\n return path1 + path2\n }\n\n return `${path1}.${path2}`\n}\n\n/**\n * @private\n */\nexport function isNonEmptyArray(obj: any) {\n return !(Array.isArray(obj) && obj.length === 0)\n}\n\ninterface AsyncValidatorArrayPartialOptions<T> {\n validators?: T\n asyncDebounceMs?: number\n}\n\n/**\n * @private\n */\nexport interface AsyncValidator<T> {\n cause: ValidationCause\n validate: T\n debounceMs: number\n}\n\ninterface SyncValidatorArrayPartialOptions<T> {\n validators?: T\n}\n\n/**\n * @private\n */\nexport interface SyncValidator<T> {\n cause: ValidationCause\n validate: T\n}\n\n/**\n * @private\n */\nexport function getSyncValidatorArray<T>(\n cause: ValidationCause,\n options: SyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n SyncValidator<\n | T['onChange']\n | T['onBlur']\n | T['onSubmit']\n | T['onMount']\n | T['onDynamic']\n >\n >\n : never {\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n return {\n cause: validator!.cause,\n validate: validator!.fn,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: false },\n runValidation,\n })\n}\n\n/**\n * @private\n */\nexport function getAsyncValidatorArray<T>(\n cause: ValidationCause,\n options: AsyncValidatorArrayPartialOptions<T> & {\n validationLogic?: any\n form?: any\n fieldName?: string\n },\n): T extends FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : T extends FormValidators<any, any, any, any, any, any, any, any, any, any>\n ? Array<\n AsyncValidator<\n | T['onChangeAsync']\n | T['onBlurAsync']\n | T['onSubmitAsync']\n | T['onDynamicAsync']\n >\n >\n : never {\n const { asyncDebounceMs } = options\n const {\n onBlurAsyncDebounceMs,\n onChangeAsyncDebounceMs,\n onDynamicAsyncDebounceMs,\n } = (options.validators || {}) as\n | FieldValidators<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n | FormValidators<any, any, any, any, any, any, any, any, any, any>\n\n const defaultDebounceMs = asyncDebounceMs ?? 0\n\n const runValidation = (\n props: Parameters<ValidationLogicProps['runValidation']>[0],\n ) => {\n return props.validators.filter(Boolean).map((validator) => {\n const validatorCause = validator?.cause || cause\n\n let debounceMs = defaultDebounceMs\n\n switch (validatorCause) {\n case 'change':\n debounceMs = onChangeAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'blur':\n debounceMs = onBlurAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'dynamic':\n debounceMs = onDynamicAsyncDebounceMs ?? defaultDebounceMs\n break\n case 'submit':\n debounceMs = 0 // submit validators are always run immediately\n break\n default:\n break\n }\n\n if (cause === 'submit') {\n debounceMs = 0\n }\n\n return {\n cause: validatorCause,\n validate: validator!.fn,\n debounceMs: debounceMs,\n }\n })\n }\n\n return options.validationLogic({\n form: options.form,\n validators: options.validators,\n event: { type: cause, fieldName: options.fieldName, async: true },\n runValidation,\n })\n}\n\nexport const isGlobalFormValidationError = (\n error: unknown,\n): error is GlobalFormValidationError<unknown> => {\n return !!error && typeof error === 'object' && 'fields' in error\n}\n\nexport function evaluate<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n if (objA instanceof Date && objB instanceof Date) {\n return objA.getTime() === objB.getTime()\n }\n\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false\n for (const [k, v] of objA) {\n if (!objB.has(k) || !Object.is(v, objB.get(k))) return false\n }\n return true\n }\n\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false\n for (const v of objA) {\n if (!objB.has(v)) return false\n }\n return true\n }\n\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n // Two distinct non-plain, non-array objects with no own enumerable keys cannot\n // be compared by key iteration — the loop below would vacuously succeed and\n // treat them as equal regardless of their internal state. This covers Temporal\n // types, RegExp, and any class that exposes values only through getters.\n if (\n keysA.length === 0 &&\n !Array.isArray(objA) &&\n !Array.isArray(objB) &&\n (Object.getPrototypeOf(objA) !== Object.prototype ||\n Object.getPrototypeOf(objB) !== Object.prototype)\n ) {\n return false\n }\n\n for (const key of keysA) {\n // performs recursive search down the object tree\n\n if (\n !keysB.includes(key) ||\n !evaluate(objA[key as keyof T], objB[key as keyof T])\n ) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the form level sync/async validation.\n * @private\n */\nexport const determineFormLevelErrorSourceAndValue = ({\n newFormValidatorError,\n isPreviousErrorFromFormValidator,\n previousErrorValue,\n}: {\n newFormValidatorError: ValidationError\n isPreviousErrorFromFormValidator: boolean\n previousErrorValue: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // All falsy values are not considered errors\n if (newFormValidatorError) {\n return { newErrorValue: newFormValidatorError, newSource: 'form' }\n }\n\n // Clears form level error since it's now stale\n if (isPreviousErrorFromFormValidator) {\n return { newErrorValue: undefined, newSource: undefined }\n }\n\n // At this point, we have a preivous error which must have been set by the field validator, keep as is\n if (previousErrorValue) {\n return { newErrorValue: previousErrorValue, newSource: 'field' }\n }\n\n // No new or previous error, clear the error\n return { newErrorValue: undefined, newSource: undefined }\n}\n\n/**\n * Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.\n * @private\n */\nexport const determineFieldLevelErrorSourceAndValue = ({\n formLevelError,\n fieldLevelError,\n}: {\n formLevelError: ValidationError\n fieldLevelError: ValidationError\n}): {\n newErrorValue: ValidationError\n newSource: ValidationSource | undefined\n} => {\n // At field level, we prioritize the field level error\n if (fieldLevelError) {\n return { newErrorValue: fieldLevelError, newSource: 'field' }\n }\n\n // If there is no field level error, and there is a form level error, we set the form level error\n if (formLevelError) {\n return { newErrorValue: formLevelError, newSource: 'form' }\n }\n\n return { newErrorValue: undefined, newSource: undefined }\n}\n\nexport function createFieldMap<T>(values: Readonly<T>): { [K in keyof T]: K } {\n const output: { [K in keyof T]: K } = {} as any\n\n for (const key in values) {\n output[key] = key\n }\n\n return output\n}\n\n/**\n * Merge the first parameter with the given overrides.\n * @private\n */\nexport function mergeOpts<T>(\n originalOpts: T | undefined | null,\n overrides: T,\n): T {\n if (originalOpts === undefined || originalOpts === null) {\n return overrides\n }\n\n return { ...originalOpts, ...overrides }\n}\n\n/*\n/ credit is due to https://github.com/lukeed/uuid for this code, with current npm\n/ attacks we didn't feel comfortable installing directly from npm. But big appreciation\n/ from the TanStack Form team <3.\n*/\n\nlet IDX = 256\nconst HEX: string[] = []\nlet BUFFER: number[] | undefined\n\nwhile (IDX--) {\n HEX[IDX] = (IDX + 256).toString(16).substring(1)\n}\n\nexport function uuid(): string {\n let i = 0\n let num: number\n let out = ''\n\n if (!BUFFER || IDX + 16 > 256) {\n BUFFER = new Array<number>(256)\n i = 256\n while (i--) {\n BUFFER[i] = (256 * Math.random()) | 0\n }\n i = 0\n IDX = 0\n }\n\n for (; i < 16; i++) {\n num = BUFFER[IDX + i] as number\n if (i === 6) out += HEX[(num & 15) | 64]\n else if (i === 8) out += HEX[(num & 63) | 128]\n else out += HEX[num]\n\n if (i & 1 && i > 1 && i < 11) out += '-'\n }\n\n IDX++\n return out\n}\n\nexport const throttleFormState = liteThrottle(\n (form: AnyFormApi) =>\n formEventClient.emit('form-state', {\n id: form.formId,\n state: form.store.state,\n }),\n {\n wait: 300,\n },\n)\n\n// Do not use a serialize and deserialize method like JSON.stringify/parse\n// as that will drop functions, dates, undefined, Infinity, NaN, etc.\nexport function deepCopy<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any\n }\n\n if (Array.isArray(obj)) {\n const arrCopy = [] as any[]\n for (let i = 0; i < obj.length; i++) {\n arrCopy[i] = deepCopy(obj[i])\n }\n return arrCopy as any\n }\n\n if (obj instanceof Map) {\n const mapCopy = new Map()\n obj.forEach((value, key) => {\n mapCopy.set(key, deepCopy(value))\n })\n return mapCopy as any\n }\n\n if (obj instanceof Set) {\n const setCopy = new Set()\n obj.forEach((value) => {\n setCopy.add(deepCopy(value))\n })\n return setCopy as any\n }\n\n const copy: { [key: string]: any } = {}\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n copy[key] = deepCopy((obj as any)[key])\n }\n }\n return copy as T\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAuC,KAAK,IAC7C;AACN;AAMO,SAAS,MAAM,KAAc,MAAyC;AAC3E,QAAM,UAAU,cAAc,IAAI;AAClC,SAAO,QAAQ,OAAO,CAAC,SAAc,aAAa;AAChD,QAAI,YAAY,KAAM,QAAO;AAC7B,QAAI,OAAO,YAAY,aAAa;AAClC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AACA,WAAO;AAAA,EACT,GAAG,GAAG;AACR;AAMO,SAAS,MAAM,KAAU,OAAY,SAAuB;AACjE,QAAM,OAAO,cAAc,KAAK;AAEhC,WAAS,MAAM,QAAmB;AAChC,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,iBAAiB,SAAS,MAAM;AAAA,IACzC;AAEA,UAAM,MAAM,KAA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K,KAAK,GAAG,GAAG;AAClD,WAAK,GAAG,IAAI,SAAU,IAAY,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACA,SAAO;AACT;"}
{
"name": "@tanstack/form-core",
"version": "1.32.0",
"version": "1.32.1",
"description": "Powerful, type-safe, framework agnostic forms.",

@@ -57,3 +57,4 @@ "author": "tannerlinsley",

"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js",
"test:types:ts58": "tsc",
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js",
"test:types:ts59": "tsc",
"test:lib": "vitest",

@@ -60,0 +61,0 @@ "test:lib:dev": "pnpm run test:lib --watch",

@@ -144,13 +144,9 @@ import { liteThrottle } from '@tanstack/pacer-lite'

const reLineOfOnlyDigits = /^(\d+)$/gm
// the second dot must be in a lookahead or the engine
// will skip subsequent numbers (like foo.0.1.)
const reDigitsBetweenDots = /\.(\d+)(?=\.)/gm
const reStartWithDigitThenDot = /^(\d+)\./gm
const reDotWithDigitsToEnd = /\.(\d+$)/gm
const reMultipleDots = /\.{2,}/gm
// Char codes used by the parser below.
const CC_DOT = 0x2e // '.'
const CC_OPEN = 0x5b // '['
const CC_CLOSE = 0x5d // ']'
const CC_ZERO = 0x30 // '0'
const CC_NINE = 0x39 // '9'
const intPrefix = '__int__'
const intReplace = `${intPrefix}$1`
/**

@@ -168,27 +164,83 @@ * @private

return (
str
// Leading `[` may lead to wrong parsing down the line
// (Example: '[0][1]' should be '0.1', not '.0.1')
.replace(/(^\[)|]/gm, '')
.replace(/\[/g, '.')
.replace(reLineOfOnlyDigits, intReplace)
.replace(reDigitsBetweenDots, `.${intReplace}.`)
.replace(reStartWithDigitThenDot, `${intReplace}.`)
.replace(reDotWithDigitsToEnd, `.${intReplace}`)
.replace(reMultipleDots, '.')
.split('.')
.map((d) => {
if (d.startsWith(intPrefix)) {
const numStr = d.substring(intPrefix.length)
const num = parseInt(numStr, 10)
const len = str.length
const result: Array<string | number> = []
// Location of the first character of the in-progress segment in `str`.
// The segment ends at the current `i` when we hit a separator.
//
// We strip an optional leading '[' so '[0]' parses as [0], not ['', 0].
// Doing this up front keeps the loop's backwards compatibility handling simpler.
let segStart = len > 0 && str.charCodeAt(0) === CC_OPEN ? 1 : 0
// Whether the in-progress segment has been all ASCII digits so far.
// Used together with the leading-zero check to decide if it should be
// pushed as a number instead of a string.
let allDigits = true
// Tracks the previous character. Only necessary to preserve the
// old behavior for malformed input.
let prev = -1
// Walk once. `i === len` is treated as a virtual final separator so the
// flush block handles both mid-string segments and the last one.
for (let i = segStart; i <= len; i++) {
const char = i < len ? str.charCodeAt(i) : -1
if (String(num) === numStr) {
return num
// Handle separators (including the virtual one at the end). Flush the in-progress segment.
if (i === len || char === CC_DOT || char === CC_OPEN || char === CC_CLOSE) {
const segLen = i - segStart
if (segLen > 0) {
// To treat the segment as a number...
const treatAsNumber =
// ...it must contain only digits...
allDigits &&
// ...and either be a single '0' or not start with '0'.
(segLen === 1 || str.charCodeAt(segStart) !== CC_ZERO)
const seg = str.slice(segStart, i)
if (treatAsNumber) {
const num = parseInt(seg, 10)
// Up to 15 digits, parseInt is always lossless (the max
// 15-digit decimal is below Number.MAX_SAFE_INTEGER). Beyond
// that, verify by round-trip: if parseInt lost precision
// (e.g., a 20-digit literal), fall back to the string so we
// don't silently change the value.
if (segLen <= 15 || String(num) === seg) {
result.push(num)
} else {
result.push(seg)
}
return numStr
} else {
result.push(seg)
}
return d
})
)
} else if (
// This branch, which handles empty segments, only exists to preserve
// the old behavior for malformed input.
// Push the empty segment unless this is a "phantom boundary" the
// old regex impl would have absorbed:
// 1. `]` was always stripped — `prev === ']'` means the real
// boundary already happened on the previous iteration.
// 2. A leading `]` was stripped too (the leading `[` strip
// above handles its counterpart for `[`).
// 3. `..` and `[[` collapse to a single boundary.
prev !== CC_CLOSE &&
!(prev === -1 && char === CC_CLOSE) &&
!(prev === char && (char === CC_DOT || char === CC_OPEN))
) {
result.push('')
}
// Start a new segment.
segStart = i + 1
allDigits = true
} else if (char < CC_ZERO || char > CC_NINE) {
allDigits = false
}
prev = char
}
// If the input was effectively all phantom chars (e.g. ']', '[]',
// '[]]'), the loop produces no segments. The old impl returned ['']
// for these because.
if (!result.length) result.push('')
return result
}

@@ -195,0 +247,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display