react-csv-importer
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -20,9 +20,26 @@ // Generated by dts-bundle-generator v5.4.0 | ||
}; | ||
export declare type ParseCallback<Row extends BaseRow> = (rows: Row[]) => void | Promise<void>; | ||
export declare type ParseCallback<Row extends BaseRow> = (rows: Row[], info: { | ||
startIndex: number; | ||
}) => void | Promise<void>; | ||
export interface ImporterPreviewColumn { | ||
index: number; | ||
header?: string; | ||
values: string[]; | ||
} | ||
export interface ImporterFilePreview { | ||
rawData: string; | ||
columns: ImporterPreviewColumn[]; | ||
skipHeaders: boolean; | ||
parseWarning?: Papa.ParseError; | ||
} | ||
export interface ImportInfo { | ||
file: File; | ||
preview: ImporterFilePreview; | ||
fields: string[]; | ||
columns: (string | undefined)[]; | ||
skipHeaders: boolean; | ||
columnFields: (string | undefined)[]; | ||
} | ||
export declare type ImporterContentRenderProp = (info: { | ||
file: File | null; | ||
preview: ImporterFilePreview | null; | ||
}) => React.ReactNode; | ||
export interface ImporterFieldProps { | ||
@@ -41,6 +58,7 @@ name: string; | ||
onClose?: (info: ImportInfo) => void; | ||
children?: ImporterContentRenderProp | React.ReactNode; | ||
} | ||
export declare const ImporterField: React.FC<ImporterFieldProps>; | ||
export declare function Importer<Row extends BaseRow>({ children, ...props }: React.PropsWithChildren<ImporterProps<Row>>): React.ReactElement; | ||
export declare function Importer<Row extends BaseRow>({ chunkSize, assumeNoHeaders, restartable, processChunk, onStart, onComplete, onClose, children: content, ...customPapaParseConfig }: React.PropsWithChildren<ImporterProps<Row>>): React.ReactElement; | ||
export {}; |
{ | ||
"name": "react-csv-importer", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "React CSV import widget with user-customizable mapping", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -60,3 +60,3 @@ # React CSV Importer | ||
}} | ||
processChunk={async (rows) => { | ||
processChunk={async (rows, { startIndex }) => { | ||
// required, receives a list of parsed objects based on defined fields and user column mapping; | ||
@@ -69,7 +69,7 @@ // may be called several times if file is large | ||
}} | ||
onComplete={({ file, fields, columns, skipHeaders }) => { | ||
onComplete={({ file, preview, fields, columnFields }) => { | ||
// optional, invoked right after import is done (but user did not dismiss/reset the widget yet) | ||
showMyAppToastNotification(); | ||
}} | ||
onClose={({ file, fields, columns, skipHeaders }) => { | ||
onClose={({ file, preview, fields, columnFields }) => { | ||
// optional, invoked when import is done and user clicked "Finish" | ||
@@ -98,2 +98,17 @@ // (if this is not specified, the widget lets the user upload another file) | ||
The `preview` object contains a snippet of CSV file information (only the first portion of the file is read, not the entire thing). The structure is: | ||
```js | ||
{ | ||
rawData: '...', // raw string contents of first file chunk | ||
columns: [ // array of preview columns, e.g.: | ||
{ index: 0, header: 'Date', values: [ '2020-09-20', '2020-09-25' ] }, | ||
{ index: 1, header: 'Name', values: [ 'Alice', 'Bob' ] } | ||
], | ||
skipHeaders: false // true when user selected that data has no headers | ||
} | ||
``` | ||
Importer component children may be defined as a render-prop function that receives the above `preview` and also the original file reference. It can then, for example, dynamically return different fields depending which headers are present in the CSV. | ||
## Dependencies | ||
@@ -131,2 +146,5 @@ | ||
- 0.5.0 | ||
- report file preview to callbacks and render-prop | ||
- report startIndex in processChunk callback | ||
- 0.4.1 | ||
@@ -133,0 +151,0 @@ - clearer error display |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165599
1289
169