@@ -176,10 +176,10 @@ export const parseRawData = async <D extends { id?: string | number }>(
176176 errors : { } ,
177177 isIgnored : false ,
178178 }
179-
180179 const importedRowValue : Partial < D > = { }
181180
182181 const rawRowValues = Object . values ( row )
182+
183183 for ( let index = 0 ; index < rawRowValues . length ; index ++ ) {
184184 const rawCell = rawRowValues [ index ]
185185 const currentColumn = orderedColumns [ index ]
@@ -199,6 +199,22 @@ export const parseRawData = async <D extends { id?: string | number }>(
199199
200200 const ignoreEmpty = currentColumn . imex ?. ignoreEmpty ?? true
201201
202+ /**
203+ * Previous value
204+ */
205+ const prevValIdentifier = get ( importedRowValue , getPath ( identifierColumn ) )
206+ const prevValIndex = originalData . findIndex ( ( originalRow ) => {
207+ if ( options . findPrevValPredicate ) {
208+ return options . findPrevValPredicate ( originalRow , importedRowValue )
209+ }
210+ return (
211+ get ( originalRow , getPath ( identifierColumn ) ) ===
212+ prevValIdentifier
213+ )
214+ } )
215+
216+ importedRowMeta . prevVal = originalData [ prevValIndex ]
217+
202218 try {
203219 newCellValue = parseCell (
204220 rawCell ,
@@ -216,7 +232,12 @@ export const parseRawData = async <D extends { id?: string | number }>(
216232 }
217233
218234 const validate = currentColumn . imex ?. validate ?? ( ( ) => true )
219- const validateResponse = validate ( newCellValue , row )
235+ const validateResponse = validate (
236+ newCellValue ,
237+ row ,
238+ importedRowMeta . prevVal
239+ )
240+
220241 const isValid =
221242 typeof validateResponse === 'string'
222243 ? ! validateResponse . length
@@ -245,26 +266,6 @@ export const parseRawData = async <D extends { id?: string | number }>(
245266 set ( importedRowValue , columnDataPath , newCellValue )
246267 }
247268
248- /**
249- * Previous value
250- */
251- const prevValIdentifier = get (
252- importedRowValue ,
253- identifierColumn . accessor as string
254- )
255- const prevValIndex = originalData . findIndex ( ( originalRow ) => {
256- if ( options . findPrevValPredicate ) {
257- return options . findPrevValPredicate ( originalRow , importedRowValue )
258- }
259- return (
260- get ( originalRow , identifierColumn . accessor as string ) ===
261- prevValIdentifier
262- )
263- } )
264-
265- importedRowMeta . prevVal = originalData [ prevValIndex ]
266- originalData . splice ( prevValIndex , 1 ) // remove from original array
267-
268269 /**
269270 * Diff
270271 */
0 commit comments