Add debounce configuration to field validation definitions

This commit is contained in:
CPTProgrammer 2026-07-15 12:50:45 +08:00
parent c1f07cc31e
commit 5bea485378
No known key found for this signature in database
2 changed files with 11 additions and 2 deletions

View File

@ -75,6 +75,7 @@ const STATIC_DEFS: StaticValidationDef<Config>[] = [
{
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<Config>[] = [
{
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<Config>[] = [
{
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<Config>[] = [
{
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;

View File

@ -63,6 +63,8 @@ export interface StaticValidationDef<T> {
target: StaticOnly<FormNamePath<T>>;
/** 依赖字段,任一变化即触发校验 */
deps: StaticOnly<FormNamePath<T>>[];
/** 防抖延迟ms默认 800 */
debounce?: number;
/** 校验逻辑,返回 null 表示不更新状态(如必填字段未填) */
validate(
getVal: (name: FormNamePath<T>) => unknown,
@ -77,6 +79,8 @@ interface _ListValidationDef<T> {
target: string;
/** 列表项中依赖的子字段名 */
deps: string[];
/** 防抖延迟ms默认 800 */
debounce?: number;
/** 校验逻辑row 为当前行号0-based */
validate(
getVal: (name: string) => unknown,
@ -92,6 +96,7 @@ export type ListValidationDef<T, L = FormNamePath<T>> =
list: L;
target: StaticOnly<FormNamePath<ItemType>>;
deps: StaticOnly<FormNamePath<ItemType>>[];
debounce?: number;
validate(
getVal: (name: FormNamePath<ItemType>) => unknown,
row: number,
@ -171,7 +176,7 @@ export function useFieldValidations<T>(
if (slot) next[defKey] = slot; else delete next[defKey];
return next;
});
}, 800);
}, def.debounce ?? 800);
}
// ── 列表 def 逐行 diff ──
@ -219,7 +224,7 @@ export function useFieldValidations<T>(
if (slot) next[rowKey] = slot; else delete next[rowKey];
return next;
});
}, 800);
}, ld.debounce ?? 800);
}
}
}