| 103 | } |
| 104 | |
| 105 | function moveFieldArrayKey<T extends Record<string, unknown>>( |
| 106 | field: keyof T, |
| 107 | from: number, |
| 108 | to: number, |
| 109 | fieldArrayKeysRef: FieldArrayKeysRef<T>, |
| 110 | ): void { |
| 111 | const existing = [...(fieldArrayKeysRef.current[field] ?? [])]; |
| 112 | if (from < 0 || to < 0 || from >= existing.length || to >= existing.length || from === to) { |
| 113 | return; |
| 114 | } |
| 115 | const [moved] = existing.splice(from, 1); |
| 116 | if (moved === undefined) { |
| 117 | return; |
| 118 | } |
| 119 | existing.splice(to, 0, moved); |
| 120 | fieldArrayKeysRef.current[field] = existing; |
| 121 | } |
| 122 | |
| 123 | function remapFieldArrayErrors( |
| 124 | fieldError: FieldErrorValue | undefined, |