From 08d194723b1f74671b2a81d63f00111116dc5527 Mon Sep 17 00:00:00 2001 From: Avram Walden Date: Fri, 14 Mar 2025 15:52:08 -0700 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20changes=20lodash=20t?= =?UTF-8?q?o=20es-toolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- rollup.config.js | 1 - src/Inputs/useDynamicInputs.ts | 2 +- src/useInertiaForm.ts | 3 ++- src/utils/fillEmptyValues.ts | 2 +- src/utils/isUnset.ts | 2 +- src/utils/renameObjectWithAttributes.ts | 2 +- src/utils/unsetCompact.ts | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 5c2c0c4..1a4606f 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "circular-json": "^0.5.9", "commitizen": "^4.3.1", "cz-conventional-changelog": "^3.3.0", + "es-toolkit": "^1.33.0", "eslint": "^9.17.0", "eslint-config-airbnb-typescript": "^18.0.0", "eslint-import-resolver-typescript": "^3.7.0", @@ -94,7 +95,6 @@ "jest-fixed-jsdom": "^0.0.9", "jest-mock-axios": "^4.8.0", "lint-staged": "^15.3.0", - "lodash": "^4.17.21", "msw": "^2.7.0", "react": "^19.0.0", "react-dom": "^19.0.0", @@ -114,7 +114,6 @@ "peerDependencies": { "@inertiajs/react": "^1.0.0 || ^2.0.0", "axios": "^1.7.8", - "lodash": "^2.0.0 || ^3.0.0 || ^4.0.0", "react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" }, diff --git a/rollup.config.js b/rollup.config.js index 1d3e385..ea0b0d1 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,7 +14,6 @@ const externalDeps = [ 'react-dom', '@inertiajs/core', '@inertiajs/react', - 'lodash', 'axios', 'react/jsx-runtime', ]; diff --git a/src/Inputs/useDynamicInputs.ts b/src/Inputs/useDynamicInputs.ts index 8688669..3b94195 100644 --- a/src/Inputs/useDynamicInputs.ts +++ b/src/Inputs/useDynamicInputs.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react' import { useForm, useFormMeta } from '../Form' -import { get, set } from 'lodash' +import { get, set } from 'es-toolkit/compat' import { useNestedAttribute } from './NestedFields' export interface DynamicInputsProps> { diff --git a/src/useInertiaForm.ts b/src/useInertiaForm.ts index 2a4ba78..7949924 100644 --- a/src/useInertiaForm.ts +++ b/src/useInertiaForm.ts @@ -25,7 +25,8 @@ import { type Path, type PathValue, } from './utils' -import { get, isEqual, isPlainObject, set } from 'lodash' +import { isEqual, isPlainObject } from 'es-toolkit' +import { get, set } from 'es-toolkit/compat' import { useFormMeta } from './Form/FormMetaWrapper' import axios, { AxiosResponse } from 'axios' diff --git a/src/utils/fillEmptyValues.ts b/src/utils/fillEmptyValues.ts index 8eb1d4e..93f57d4 100644 --- a/src/utils/fillEmptyValues.ts +++ b/src/utils/fillEmptyValues.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from 'lodash' +import { isPlainObject } from 'es-toolkit' /** * Replaces undefined or null values with empty values, diff --git a/src/utils/isUnset.ts b/src/utils/isUnset.ts index 25cca93..a7b631f 100644 --- a/src/utils/isUnset.ts +++ b/src/utils/isUnset.ts @@ -1,4 +1,4 @@ -import { isEmpty } from 'lodash' +import { isEmpty } from 'es-toolkit/compat' /** * Returns whether a value should be considered empty in the context of a form input diff --git a/src/utils/renameObjectWithAttributes.ts b/src/utils/renameObjectWithAttributes.ts index 3560a6a..681d60e 100644 --- a/src/utils/renameObjectWithAttributes.ts +++ b/src/utils/renameObjectWithAttributes.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from 'lodash' +import { isPlainObject } from 'es-toolkit' import { NestedObject } from '../useInertiaForm' /** diff --git a/src/utils/unsetCompact.ts b/src/utils/unsetCompact.ts index c5825e7..e64e2e4 100644 --- a/src/utils/unsetCompact.ts +++ b/src/utils/unsetCompact.ts @@ -1,4 +1,4 @@ -import { unset, get } from 'lodash' +import { unset, get } from 'es-toolkit/compat' import { type NestedObject } from '../useInertiaForm' /** From cb238cf996c262777001ff621b9a96a4e25a32f5 Mon Sep 17 00:00:00 2001 From: Avram Walden Date: Fri, 14 Mar 2025 17:21:36 -0700 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20changes=20back?= =?UTF-8?q?=20to=20es-toolkit=20after=20merging=20main?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Inputs/useDynamicInputs.ts | 2 +- src/useInertiaForm.ts | 3 ++- src/utils/fillEmptyValues.ts | 2 +- src/utils/isUnset.ts | 2 +- src/utils/renameObjectWithAttributes.ts | 2 +- src/utils/unsetCompact.ts | 2 +- yarn.lock | 15 +++++++++++++-- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Inputs/useDynamicInputs.ts b/src/Inputs/useDynamicInputs.ts index 173447e..2ca32dc 100644 --- a/src/Inputs/useDynamicInputs.ts +++ b/src/Inputs/useDynamicInputs.ts @@ -1,6 +1,6 @@ import { useCallback } from "react" import { useForm, useFormMeta } from "../Form" -import { get, set } from "lodash" +import { get, set } from "es-toolkit/compat" import { useNestedAttribute } from "./NestedFields" export interface DynamicInputsProps> { diff --git a/src/useInertiaForm.ts b/src/useInertiaForm.ts index c38173b..4e991fd 100644 --- a/src/useInertiaForm.ts +++ b/src/useInertiaForm.ts @@ -25,7 +25,8 @@ import { type Path, type PathValue, } from "./utils" -import { get, isEqual, isPlainObject, set } from "lodash" +import { isEqual, isPlainObject } from "es-toolkit" +import { get, set } from "es-toolkit/compat" import { useFormMeta } from "./Form/FormMetaWrapper" import axios, { AxiosResponse } from "axios" diff --git a/src/utils/fillEmptyValues.ts b/src/utils/fillEmptyValues.ts index 45bdcdf..63821b4 100644 --- a/src/utils/fillEmptyValues.ts +++ b/src/utils/fillEmptyValues.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from "lodash" +import { isPlainObject } from "es-toolkit" /** * Replaces undefined or null values with empty values, diff --git a/src/utils/isUnset.ts b/src/utils/isUnset.ts index 9eb1ca2..3a177ec 100644 --- a/src/utils/isUnset.ts +++ b/src/utils/isUnset.ts @@ -1,4 +1,4 @@ -import { isEmpty } from "lodash" +import { isEmpty } from "es-toolkit/compat" /** * Returns whether a value should be considered empty in the context of a form input diff --git a/src/utils/renameObjectWithAttributes.ts b/src/utils/renameObjectWithAttributes.ts index c5fd393..ee037c4 100644 --- a/src/utils/renameObjectWithAttributes.ts +++ b/src/utils/renameObjectWithAttributes.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from "lodash" +import { isPlainObject } from "es-toolkit" import { NestedObject } from "../useInertiaForm" /** diff --git a/src/utils/unsetCompact.ts b/src/utils/unsetCompact.ts index e4b1b32..c30a68a 100644 --- a/src/utils/unsetCompact.ts +++ b/src/utils/unsetCompact.ts @@ -1,4 +1,4 @@ -import { unset, get } from "lodash" +import { unset, get } from "es-toolkit/compat" import { type NestedObject } from "../useInertiaForm" /** diff --git a/yarn.lock b/yarn.lock index de59820..9a1e719 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6025,6 +6025,18 @@ __metadata: languageName: node linkType: hard +"es-toolkit@npm:^1.33.0": + version: 1.33.0 + resolution: "es-toolkit@npm:1.33.0" + dependenciesMeta: + "@trivago/prettier-plugin-sort-imports@4.3.0": + unplugged: true + prettier-plugin-sort-re-exports@0.0.1: + unplugged: true + checksum: 10/db613d885c407dc3b84b3939b8b0c9976f658bfb03fa0f9cd3a3fe8383a60a75e1e4f34584e86c3fbf00def50ea0ca5f1a5264a1014018286dedbed08426b5f0 + languageName: node + linkType: hard + "escalade@npm:^3.1.1, escalade@npm:^3.2.0": version: 3.2.0 resolution: "escalade@npm:3.2.0" @@ -13816,6 +13828,7 @@ __metadata: circular-json: "npm:^0.5.9" commitizen: "npm:^4.3.1" cz-conventional-changelog: "npm:^3.3.0" + es-toolkit: "npm:^1.33.0" eslint: "npm:^9.17.0" eslint-config-airbnb-typescript: "npm:^18.0.0" eslint-import-resolver-typescript: "npm:^3.7.0" @@ -13833,7 +13846,6 @@ __metadata: jest-fixed-jsdom: "npm:^0.0.9" jest-mock-axios: "npm:^4.8.0" lint-staged: "npm:^15.3.0" - lodash: "npm:^4.17.21" msw: "npm:^2.7.0" react: "npm:^19.0.0" react-dom: "npm:^19.0.0" @@ -13853,7 +13865,6 @@ __metadata: peerDependencies: "@inertiajs/react": ^1.0.0 || ^2.0.0 axios: ^1.7.8 - lodash: ^2.0.0 || ^3.0.0 || ^4.0.0 react: ^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 react-dom: ^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 languageName: unknown From a611c4508351278f8c568dd5ed2de253a072e1ac Mon Sep 17 00:00:00 2001 From: Avram Walden Date: Thu, 3 Apr 2025 11:05:23 -0700 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=F0=9F=92=8D=20adds=20test=20for=20?= =?UTF-8?q?deleting=20input=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/useInertiaInput.test.tsx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/useInertiaInput.test.tsx b/tests/useInertiaInput.test.tsx index 6f475dd..eb80cbf 100644 --- a/tests/useInertiaInput.test.tsx +++ b/tests/useInertiaInput.test.tsx @@ -66,4 +66,38 @@ describe ("useInertiaInput", () => { }) }) + + describe("Text input value changes", () => { + it("maintains empty value when all characters are deleted", () => { + render( +
+ +
, + ) + + const input = screen.getByRole("input") + + // Initial state + expect(input).toHaveValue("initial") + + // Delete some characters (backspace) + fireEvent.input(input, { target: { value: "init" } }) + expect(input).toHaveValue("init") + + // Delete all characters (backspace) + fireEvent.input(input, { target: { value: "" } }) + expect(input).toHaveValue("") + + // Delete all characters (select all + delete) + fireEvent.input(input, { target: { value: "" } }) + expect(input).toHaveValue("") + + // Try setting to undefined + fireEvent.input(input, { target: { value: undefined } }) + expect(input).toHaveValue("") + + // Verify value stays empty + expect(input).toHaveValue("") + }) + }) })