From 5bea4853782c110052bac6183b6c1df0d200f6e1 Mon Sep 17 00:00:00 2001 From: CPTProgrammer <46586216+CPTProgrammer@users.noreply.github.com> Date: Wed, 15 Jul 2026 12:50:45 +0800 Subject: [PATCH] Add debounce configuration to field validation definitions --- src/components/ConfigModal.tsx | 4 ++++ src/hooks/useFieldValidations.tsx | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/ConfigModal.tsx b/src/components/ConfigModal.tsx index a3be5a0..38da390 100644 --- a/src/components/ConfigModal.tsx +++ b/src/components/ConfigModal.tsx @@ -75,6 +75,7 @@ const STATIC_DEFS: StaticValidationDef[] = [ { target: "minecraft_properties_dir", deps: ["project_dir", "minecraft_properties_dir"], + debounce: 50, async validate(getVal) { const dir = getVal("project_dir") as string | undefined; const mcDir = getVal("minecraft_properties_dir") as string | undefined; @@ -89,6 +90,7 @@ const STATIC_DEFS: StaticValidationDef[] = [ { target: "mod_version_field", deps: ["project_dir", "project_properties_path", "mod_version_field"], + debounce: 50, async validate(getVal) { const dir = getVal("project_dir") as string | undefined; const path = getVal("project_properties_path") as string | undefined; @@ -105,6 +107,7 @@ const STATIC_DEFS: StaticValidationDef[] = [ { target: "filename_format", deps: ["project_dir", "project_properties_path", "mod_version_field", "filename_format", "minecraft_properties_dir"], + debounce: 50, async validate(getVal) { const dir = getVal("project_dir") as string | undefined; const propsPath = getVal("project_properties_path") as string | undefined; @@ -124,6 +127,7 @@ const STATIC_DEFS: StaticValidationDef[] = [ { target: "source_filename_format", deps: ["project_dir", "project_properties_path", "mod_version_field", "source_filename_format", "minecraft_properties_dir"], + debounce: 50, async validate(getVal) { const dir = getVal("project_dir") as string | undefined; const propsPath = getVal("project_properties_path") as string | undefined; diff --git a/src/hooks/useFieldValidations.tsx b/src/hooks/useFieldValidations.tsx index 0ce5fb2..670e484 100644 --- a/src/hooks/useFieldValidations.tsx +++ b/src/hooks/useFieldValidations.tsx @@ -63,6 +63,8 @@ export interface StaticValidationDef { target: StaticOnly>; /** 依赖字段,任一变化即触发校验 */ deps: StaticOnly>[]; + /** 防抖延迟(ms),默认 800 */ + debounce?: number; /** 校验逻辑,返回 null 表示不更新状态(如必填字段未填) */ validate( getVal: (name: FormNamePath) => unknown, @@ -77,6 +79,8 @@ interface _ListValidationDef { target: string; /** 列表项中依赖的子字段名 */ deps: string[]; + /** 防抖延迟(ms),默认 800 */ + debounce?: number; /** 校验逻辑,row 为当前行号(0-based) */ validate( getVal: (name: string) => unknown, @@ -92,6 +96,7 @@ export type ListValidationDef> = list: L; target: StaticOnly>; deps: StaticOnly>[]; + debounce?: number; validate( getVal: (name: FormNamePath) => unknown, row: number, @@ -171,7 +176,7 @@ export function useFieldValidations( if (slot) next[defKey] = slot; else delete next[defKey]; return next; }); - }, 800); + }, def.debounce ?? 800); } // ── 列表 def 逐行 diff ── @@ -219,7 +224,7 @@ export function useFieldValidations( if (slot) next[rowKey] = slot; else delete next[rowKey]; return next; }); - }, 800); + }, ld.debounce ?? 800); } } }