@importcsv/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +470 -0
- package/build/App.d.ts +2 -0
- package/build/api.d.ts +17 -0
- package/build/components/CSVImporter/CSVImporter.stories.d.ts +44 -0
- package/build/components/CSVImporter/index.d.ts +26 -0
- package/build/config/environments.d.ts +12 -0
- package/build/config/index.d.ts +5 -0
- package/build/config.d.ts +10 -0
- package/build/i18n/de.d.ts +32 -0
- package/build/i18n/es.d.ts +32 -0
- package/build/i18n/fr.d.ts +32 -0
- package/build/i18n/i18n.d.ts +2 -0
- package/build/i18n/it.d.ts +32 -0
- package/build/importer/components/Box/index.d.ts +2 -0
- package/build/importer/components/Box/types/index.d.ts +5 -0
- package/build/importer/components/Checkbox/index.d.ts +2 -0
- package/build/importer/components/Checkbox/types/index.d.ts +4 -0
- package/build/importer/components/Errors/index.d.ts +4 -0
- package/build/importer/components/Input/index.d.ts +2 -0
- package/build/importer/components/Input/types/index.d.ts +18 -0
- package/build/importer/components/Portal/index.d.ts +3 -0
- package/build/importer/components/Portal/types/index.d.ts +5 -0
- package/build/importer/components/Stepper/hooks/useStepper.d.ts +2 -0
- package/build/importer/components/Stepper/index.d.ts +2 -0
- package/build/importer/components/Stepper/types/index.d.ts +13 -0
- package/build/importer/components/Table/index.d.ts +9 -0
- package/build/importer/components/Table/storyData.d.ts +36 -0
- package/build/importer/components/Table/types/index.d.ts +42 -0
- package/build/importer/components/ToggleFilter/ToggleFilter.stories.d.ts +18 -0
- package/build/importer/components/ToggleFilter/index.d.ts +3 -0
- package/build/importer/components/ToggleFilter/types/index.d.ts +11 -0
- package/build/importer/components/Tooltip/index.d.ts +2 -0
- package/build/importer/components/Tooltip/types/index.d.ts +11 -0
- package/build/importer/components/UploaderWrapper/UploaderWrapper.d.ts +2 -0
- package/build/importer/components/UploaderWrapper/types/index.d.ts +2 -0
- package/build/importer/features/complete/index.d.ts +2 -0
- package/build/importer/features/complete/types/index.d.ts +5 -0
- package/build/importer/features/main/hooks/useMutableLocalStorage.d.ts +1 -0
- package/build/importer/features/main/hooks/useStepNavigation.d.ts +17 -0
- package/build/importer/features/main/index.d.ts +2 -0
- package/build/importer/features/main/types/index.d.ts +16 -0
- package/build/importer/features/map-columns/components/DropDownFields.d.ts +19 -0
- package/build/importer/features/map-columns/hooks/useMapColumnsTable.d.ts +15 -0
- package/build/importer/features/map-columns/hooks/useNameChange.d.ts +5 -0
- package/build/importer/features/map-columns/index.d.ts +2 -0
- package/build/importer/features/map-columns/types/index.d.ts +23 -0
- package/build/importer/features/row-selection/index.d.ts +2 -0
- package/build/importer/features/row-selection/types/index.d.ts +8 -0
- package/build/importer/features/uploader/hooks/useTemplateTable.d.ts +10 -0
- package/build/importer/features/uploader/index.d.ts +2 -0
- package/build/importer/features/uploader/types/index.d.ts +9 -0
- package/build/importer/features/validate/index.d.ts +24 -0
- package/build/importer/features/validation/AIFixModal.d.ts +23 -0
- package/build/importer/features/validation/SimpleValidation.d.ts +2 -0
- package/build/importer/features/validation/Validation.d.ts +2 -0
- package/build/importer/features/validation/ValidationFixed.d.ts +2 -0
- package/build/importer/features/validation/components/AISuggestionsPanel.d.ts +15 -0
- package/build/importer/features/validation/components/InlineFixSuggestion.d.ts +8 -0
- package/build/importer/features/validation/index.d.ts +1 -0
- package/build/importer/features/validation/types.d.ts +31 -0
- package/build/importer/hooks/useClickOutside.d.ts +1 -0
- package/build/importer/hooks/useCustomStyles.d.ts +1 -0
- package/build/importer/hooks/useDelayLoader.d.ts +2 -0
- package/build/importer/hooks/useEventListener.d.ts +4 -0
- package/build/importer/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
- package/build/importer/hooks/useRect.d.ts +12 -0
- package/build/importer/hooks/useWindowSize.d.ts +1 -0
- package/build/importer/providers/Theme.d.ts +4 -0
- package/build/importer/providers/index.d.ts +2 -0
- package/build/importer/providers/types/index.d.ts +4 -0
- package/build/importer/services/api.d.ts +0 -0
- package/build/importer/services/validation-api.d.ts +14 -0
- package/build/importer/settings/chakra/components/alert.d.ts +31 -0
- package/build/importer/settings/chakra/components/button.d.ts +37 -0
- package/build/importer/settings/chakra/components/index.d.ts +2 -0
- package/build/importer/settings/chakra/foundations/blur.d.ts +11 -0
- package/build/importer/settings/chakra/foundations/borders.d.ts +8 -0
- package/build/importer/settings/chakra/foundations/breakpoints.d.ts +9 -0
- package/build/importer/settings/chakra/foundations/colors.d.ts +247 -0
- package/build/importer/settings/chakra/foundations/index.d.ts +487 -0
- package/build/importer/settings/chakra/foundations/radius.d.ts +12 -0
- package/build/importer/settings/chakra/foundations/shadows.d.ts +14 -0
- package/build/importer/settings/chakra/foundations/sizes.d.ts +60 -0
- package/build/importer/settings/chakra/foundations/spacing.d.ts +35 -0
- package/build/importer/settings/chakra/foundations/transition.d.ts +24 -0
- package/build/importer/settings/chakra/foundations/typography.d.ts +61 -0
- package/build/importer/settings/chakra/foundations/z-index.d.ts +16 -0
- package/build/importer/settings/chakra/index.d.ts +592 -0
- package/build/importer/settings/chakra/semantic-tokens.d.ts +32 -0
- package/build/importer/settings/chakra/styles.d.ts +2 -0
- package/build/importer/settings/chakra/theme.types.d.ts +93 -0
- package/build/importer/settings/chakra/utils/is-chakra-theme.d.ts +3 -0
- package/build/importer/settings/chakra/utils/run-if-fn.d.ts +1 -0
- package/build/importer/settings/theme/colors.d.ts +4 -0
- package/build/importer/settings/theme/index.d.ts +2 -0
- package/build/importer/settings/theme/sizes.d.ts +7 -0
- package/build/importer/stores/theme.d.ts +17 -0
- package/build/importer/types/index.d.ts +17 -0
- package/build/importer/utils/classes.d.ts +2 -0
- package/build/importer/utils/debounce.d.ts +2 -0
- package/build/importer/utils/getStringLengthOfChildren.d.ts +2 -0
- package/build/importer/utils/stringSimilarity.d.ts +1 -0
- package/build/importer/utils/template.d.ts +2 -0
- package/build/importer/utils/utils.d.ts +11 -0
- package/build/index.d.ts +2 -0
- package/build/index.esm.js +54893 -0
- package/build/index.esm.js.map +1 -0
- package/build/index.js +54919 -0
- package/build/index.js.map +1 -0
- package/build/js.d.ts +31 -0
- package/build/services/api.d.ts +18 -0
- package/build/services/apiClient.d.ts +21 -0
- package/build/settings/defaults.d.ts +3 -0
- package/build/types/index.d.ts +24 -0
- package/build/types.d.ts +91 -0
- package/package.json +122 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Portola Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# ImportCSV Frontend
|
|
4
|
+
|
|
5
|
+
<em>React-based embeddable CSV and spreadsheet importer with streamlined column mapping</em>
|
|
6
|
+
|
|
7
|
+
[](https://reactjs.org/)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](./LICENSE)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## 🚀 Overview
|
|
14
|
+
|
|
15
|
+
The ImportCSV Frontend provides a polished, user-friendly interface for importing CSV, XLS, XLSX, and TSV files. It can be embedded in any React application and offers intuitive column mapping functionality.
|
|
16
|
+
|
|
17
|
+
> **Note**: This component was forked from [TableFlow's CSV Import](https://github.com/tableflowhq/csv-import) and enhanced with additional features.
|
|
18
|
+
|
|
19
|
+
## ✨ Key Features
|
|
20
|
+
|
|
21
|
+
- **📊 Multi-Format Support** - Import from CSV, XLS, XLSX, and TSV files
|
|
22
|
+
- **🔄 Smart Column Mapping** - Intuitive interface for mapping columns
|
|
23
|
+
- **🔍 Data Validation** - Immediate feedback on data quality issues
|
|
24
|
+
- **🎨 Customizable UI** - Theming and component customization options
|
|
25
|
+
- **🔌 Flexible Integration** - Available as React component or vanilla JavaScript
|
|
26
|
+
|
|
27
|
+
## 🏗️ Architecture
|
|
28
|
+
|
|
29
|
+
The frontend is built as a React library with TypeScript and can be used in two ways:
|
|
30
|
+
|
|
31
|
+
1. **React Component** - Direct integration into React applications
|
|
32
|
+
2. **JavaScript SDK** - For use in non-React applications
|
|
33
|
+
|
|
34
|
+
## 🛠️ Technical Details
|
|
35
|
+
|
|
36
|
+
### Key Components
|
|
37
|
+
|
|
38
|
+
- **CSVImporter** - Main React component for the import flow
|
|
39
|
+
- **ColumnMapper** - Handles column mapping with smart suggestions
|
|
40
|
+
- **DataValidator** - Validates data against schema requirements
|
|
41
|
+
- **ImportSummary** - Displays import results and validation issues
|
|
42
|
+
|
|
43
|
+
## 🚀 Getting Started
|
|
44
|
+
|
|
45
|
+
### Installation
|
|
46
|
+
|
|
47
|
+
Use NPM or Yarn to install the SDK:
|
|
48
|
+
|
|
49
|
+
**NPM**
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install csv-import-react
|
|
53
|
+
# or for non-React applications
|
|
54
|
+
npm install csv-import-js
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Yarn**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
yarn add csv-import-react
|
|
61
|
+
# or for non-React applications
|
|
62
|
+
yarn add csv-import-js
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Basic Usage
|
|
66
|
+
|
|
67
|
+
#### Using React
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { CSVImporter } from "csv-import-react";
|
|
71
|
+
import { useState } from "react";
|
|
72
|
+
|
|
73
|
+
function MyComponent() {
|
|
74
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<button onClick={() => setIsOpen(true)}>Open CSV Importer</button>
|
|
79
|
+
|
|
80
|
+
<CSVImporter
|
|
81
|
+
modalIsOpen={isOpen}
|
|
82
|
+
modalOnCloseTriggered={() => setIsOpen(false)}
|
|
83
|
+
darkMode={true}
|
|
84
|
+
onComplete={(data) => console.log(data)}
|
|
85
|
+
template={{
|
|
86
|
+
columns: [
|
|
87
|
+
{
|
|
88
|
+
name: "First Name",
|
|
89
|
+
key: "first_name",
|
|
90
|
+
required: true,
|
|
91
|
+
description: "The first name of the user",
|
|
92
|
+
suggested_mappings: ["First", "Name"],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "Age",
|
|
96
|
+
data_type: "number",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Using JavaScript
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<head>
|
|
110
|
+
<script src="https://unpkg.com/csv-import-js@latest/index.js"></script>
|
|
111
|
+
</head>
|
|
112
|
+
<body>
|
|
113
|
+
<button id="uploadButton">Open CSV Importer</button>
|
|
114
|
+
<div id="app"></div>
|
|
115
|
+
<script>
|
|
116
|
+
const importer = CSVImporter.createCSVImporter({
|
|
117
|
+
domElement: document.getElementById("app"),
|
|
118
|
+
modalOnCloseTriggered: () => importer?.closeModal(),
|
|
119
|
+
onComplete: (data) => console.log(data),
|
|
120
|
+
darkMode: true,
|
|
121
|
+
template: {
|
|
122
|
+
columns: [
|
|
123
|
+
{
|
|
124
|
+
name: "First Name",
|
|
125
|
+
key: "first_name",
|
|
126
|
+
required: true,
|
|
127
|
+
description: "The first name of the user",
|
|
128
|
+
suggested_mappings: ["First", "Name"],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "Age",
|
|
132
|
+
data_type: "number",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const uploadButton = document.getElementById("uploadButton");
|
|
139
|
+
uploadButton.addEventListener("click", () => {
|
|
140
|
+
importer?.showModal();
|
|
141
|
+
});
|
|
142
|
+
</script>
|
|
143
|
+
</body>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## SDK Reference
|
|
147
|
+
|
|
148
|
+
### isModal (_boolean_, default: `true`)
|
|
149
|
+
|
|
150
|
+
When set to `true` (default value), the importer will behave as a modal with its open state controlled by `modalIsOpen`. When set to `false`, the importer will be embedded directly in your page.
|
|
151
|
+
|
|
152
|
+
### modalIsOpen (_boolean_, default: `false`)
|
|
153
|
+
|
|
154
|
+
Only used when `isModal` is `true`: Controls the importer modal being open or closed.
|
|
155
|
+
\
|
|
156
|
+
**React SDK Only**: For the JavaScript SDK, use `.showModal()` and `.closeModal()` to operate the modal.
|
|
157
|
+
|
|
158
|
+
### modalOnCloseTriggered (_function_)
|
|
159
|
+
|
|
160
|
+
Only used when `isModal` is `true`: A function called when the user clicks the close button or clicks outside of (when used with `modalCloseOnOutsideClick`) the importer. `useState` can be used to control the importer modal opening and closing.
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```jsx
|
|
167
|
+
<button onClick={() => setIsOpen(true)}>Open CSV Importer</button>
|
|
168
|
+
<CSVImporter
|
|
169
|
+
modalIsOpen={isOpen}
|
|
170
|
+
modalOnCloseTriggered={() => setIsOpen(false)}
|
|
171
|
+
...
|
|
172
|
+
/>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### modalCloseOnOutsideClick (_boolean_, default: `false`)
|
|
176
|
+
|
|
177
|
+
Only used when `isModal` is `true`: Clicking outside the modal will call the `modalOnCloseTriggered` function.
|
|
178
|
+
|
|
179
|
+
### template (_object_)
|
|
180
|
+
|
|
181
|
+
Configure the columns used for the import.
|
|
182
|
+
|
|
183
|
+
```jsx
|
|
184
|
+
template={{
|
|
185
|
+
columns: [
|
|
186
|
+
{
|
|
187
|
+
name: "First Name",
|
|
188
|
+
key: "first_name",
|
|
189
|
+
required: true,
|
|
190
|
+
description: "The first name of the user",
|
|
191
|
+
suggested_mappings: ["First", "Name"],
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "Age",
|
|
195
|
+
data_type: "number",
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
}}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### onComplete (_function_)
|
|
202
|
+
|
|
203
|
+
Callback function that fires when a user completes an import. It returns `data`, an object that contains the row data, column definitions, and other information about the import.
|
|
204
|
+
|
|
205
|
+
```jsx
|
|
206
|
+
onComplete={(data) => console.log(data)}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Example `data`:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"num_rows": 2,
|
|
214
|
+
"num_columns": 3,
|
|
215
|
+
"columns": [
|
|
216
|
+
{
|
|
217
|
+
"key": "age",
|
|
218
|
+
"name": "Age"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"key": "email",
|
|
222
|
+
"name": "Email"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"key": "first_name",
|
|
226
|
+
"name": "First Name"
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
"rows": [
|
|
230
|
+
{
|
|
231
|
+
"index": 0,
|
|
232
|
+
"values": {
|
|
233
|
+
"age": 23,
|
|
234
|
+
"email": "maria@example.com",
|
|
235
|
+
"first_name": "Maria"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"index": 1,
|
|
240
|
+
"values": {
|
|
241
|
+
"age": 32,
|
|
242
|
+
"email": "robert@example.com",
|
|
243
|
+
"first_name": "Robert"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### darkMode (_boolean_, default: `false`)
|
|
251
|
+
|
|
252
|
+
Toggle between dark mode (`true`) and light mode (`false`).
|
|
253
|
+
|
|
254
|
+
### primaryColor (_string_)
|
|
255
|
+
|
|
256
|
+
Specifies the primary color for the importer in hex format. Use `customStyles` to customize the UI in more detail.
|
|
257
|
+
|
|
258
|
+
```jsx
|
|
259
|
+
primaryColor = "#7A5EF8";
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### customStyles (_object_)
|
|
263
|
+
|
|
264
|
+
Apply custom styles to the importer with an object containing CSS properties and values. Note that custom style properties will override `primaryColor` and any default styles from `darkMode`.
|
|
265
|
+
Available options:
|
|
266
|
+
|
|
267
|
+
```jsx
|
|
268
|
+
customStyles={{
|
|
269
|
+
"font-family": "cursive",
|
|
270
|
+
"font-size": "15px",
|
|
271
|
+
"base-spacing": "2rem",
|
|
272
|
+
"border-radius": "8px",
|
|
273
|
+
"color-primary": "salmon",
|
|
274
|
+
"color-primary-hover": "crimson",
|
|
275
|
+
"color-secondary": "indianRed",
|
|
276
|
+
"color-secondary-hover": "crimson",
|
|
277
|
+
"color-tertiary": "indianRed",
|
|
278
|
+
"color-tertiary-hover": "crimson",
|
|
279
|
+
"color-border": "lightCoral",
|
|
280
|
+
"color-text": "brown",
|
|
281
|
+
"color-text-soft": "rgba(165, 42, 42, .5)",
|
|
282
|
+
"color-text-on-primary": "#fff",
|
|
283
|
+
"color-text-on-secondary": "#ffffff",
|
|
284
|
+
"color-background": "bisque",
|
|
285
|
+
"color-background-modal": "blanchedAlmond",
|
|
286
|
+
"color-input-background": "blanchedAlmond",
|
|
287
|
+
"color-input-background-soft": "white",
|
|
288
|
+
"color-background-menu-hover": "bisque",
|
|
289
|
+
"color-importer-link": "indigo",
|
|
290
|
+
"color-progress-bar": "darkGreen"
|
|
291
|
+
}}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Internationalization
|
|
295
|
+
|
|
296
|
+
### Predefined languages
|
|
297
|
+
|
|
298
|
+
- Out-of-the-box support for various languages.
|
|
299
|
+
- Common languages are available through the language prop (i.e., `language="fr"` for French).
|
|
300
|
+
- Available predefined languages:
|
|
301
|
+
- en
|
|
302
|
+
- es
|
|
303
|
+
- fr
|
|
304
|
+
|
|
305
|
+
### Customizable language
|
|
306
|
+
|
|
307
|
+
- Language keys can be exported and overridden.
|
|
308
|
+
- Labels and messages can be customized to any text.
|
|
309
|
+
- Translations key examples can be found in `src/i18n/es.ts`
|
|
310
|
+
|
|
311
|
+
```javascript
|
|
312
|
+
// Set up custom translations
|
|
313
|
+
const customTranslations = {
|
|
314
|
+
jp: {
|
|
315
|
+
Upload: "アップロード",
|
|
316
|
+
"Browse files": "ファイルを参照",
|
|
317
|
+
},
|
|
318
|
+
pt: {
|
|
319
|
+
Upload: "Carregar",
|
|
320
|
+
"Browse files": "Procurar arquivos",
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<CSVImporter language="jp" customTranslations={customTranslations} ...props />
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### showDownloadTemplateButton (_boolean_, default: `true`)
|
|
331
|
+
|
|
332
|
+
When set to `false`, hide the Download Template button on the first screen of the importer.
|
|
333
|
+
|
|
334
|
+
### skipHeaderRowSelection (_boolean_, default: `false`)
|
|
335
|
+
|
|
336
|
+
When set to `true`, the importer will not display and skip the Header Row Selection step and always choose the first row in the file as the header.
|
|
337
|
+
|
|
338
|
+
## Contributing
|
|
339
|
+
|
|
340
|
+
### Setting Up the Project
|
|
341
|
+
|
|
342
|
+
To set up the project locally, follow these steps:
|
|
343
|
+
|
|
344
|
+
1. **Clone the repository**
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
git clone https://github.com/tableflowhq/csv-import.git
|
|
348
|
+
cd csv-import
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
2. **Install dependencies**
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
yarn install
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
3. **Build the project**
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
yarn build
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Running Storybook
|
|
364
|
+
|
|
365
|
+
To run Storybook locally, follow these steps:
|
|
366
|
+
|
|
367
|
+
1. **Start Storybook**
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
yarn storybook
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
2. **Open Storybook in your browser:**
|
|
374
|
+
Storybook should automatically open in your default browser. If it doesn't, navigate to [http://localhost:6006](http://localhost:6006).
|
|
375
|
+
|
|
376
|
+
### Modifying the project and testing with the demo app
|
|
377
|
+
|
|
378
|
+
The project includes a demo app that you can use to test your changes. The demo app has its own `README.md` file with detailed instructions on how to set it up and run it.
|
|
379
|
+
|
|
380
|
+
1. Make your changes in the codebase.
|
|
381
|
+
2. Follow the instructions in the demo app's `README.md` to set up and run the demo app. This will help you verify that your changes work as expected in a real application.
|
|
382
|
+
3. Commit your changes and push them to your forked repository.
|
|
383
|
+
4. Create a pull request to the main repository.
|
|
384
|
+
|
|
385
|
+
## Publishing the Library
|
|
386
|
+
|
|
387
|
+
### Using Yarn Publish
|
|
388
|
+
|
|
389
|
+
To publish the library to npm:
|
|
390
|
+
|
|
391
|
+
1. Update the version in `package.json`:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Increment version - choose one of:
|
|
395
|
+
npm version patch # for bug fixes
|
|
396
|
+
npm version minor # for new features
|
|
397
|
+
npm version major # for breaking changes
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
2. Build the library:
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
yarn build
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
3. Publish to npm:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# If you're publishing for the first time
|
|
410
|
+
npm login
|
|
411
|
+
|
|
412
|
+
# Publish the package
|
|
413
|
+
yarn publish
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
4. To use the published package in another project:
|
|
417
|
+
```bash
|
|
418
|
+
# In your project
|
|
419
|
+
yarn add csv-import-react
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Using Yalc (for Local Development)
|
|
423
|
+
|
|
424
|
+
[Yalc](https://github.com/wclr/yalc) is a tool for local package development and sharing. It's useful when you want to test your library in another project without publishing to npm.
|
|
425
|
+
|
|
426
|
+
1. Install yalc globally:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
npm install -g yalc
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
2. Build the library:
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
yarn build
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
3. Publish to local yalc store:
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
yalc publish
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
4. Add to your project:
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
# In your project directory
|
|
448
|
+
yalc add csv-import-react
|
|
449
|
+
yarn install # or npm install
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
5. When you make changes to the library:
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
# In the library directory
|
|
456
|
+
yarn build
|
|
457
|
+
yalc push # Updates all linked projects
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
6. To remove the yalc link:
|
|
461
|
+
```bash
|
|
462
|
+
# In your project directory
|
|
463
|
+
yalc remove csv-import-react
|
|
464
|
+
yarn install # Restore to regular dependencies
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
## Get In Touch
|
|
468
|
+
|
|
469
|
+
Let us know your feedback or feature requests! Submit a GitHub
|
|
470
|
+
issue [here](https://github.com/tableflowhq/csv-import/issues/new).
|
package/build/App.d.ts
ADDED
package/build/api.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client for the CSV importer
|
|
3
|
+
*/
|
|
4
|
+
export declare class ImporterApi {
|
|
5
|
+
private importerId;
|
|
6
|
+
/**
|
|
7
|
+
* Create a new API client
|
|
8
|
+
* @param importerId The ID of the importer to use
|
|
9
|
+
*/
|
|
10
|
+
constructor(importerId: string);
|
|
11
|
+
/**
|
|
12
|
+
* Process CSV data
|
|
13
|
+
* @param data The data to process
|
|
14
|
+
* @returns The response from the server
|
|
15
|
+
*/
|
|
16
|
+
processData(data: any): Promise<any>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, {
|
|
3
|
+
darkMode?: boolean | undefined;
|
|
4
|
+
primaryColor?: string | undefined;
|
|
5
|
+
className?: string | undefined;
|
|
6
|
+
onComplete?: ((data: any) => void) | undefined;
|
|
7
|
+
waitOnComplete?: boolean | undefined;
|
|
8
|
+
customStyles?: string | Record<string, string> | undefined;
|
|
9
|
+
showDownloadTemplateButton?: boolean | undefined;
|
|
10
|
+
skipHeaderRowSelection?: boolean | undefined;
|
|
11
|
+
language?: string | undefined;
|
|
12
|
+
customTranslations?: import("i18next").Resource | undefined;
|
|
13
|
+
importerKey?: string | undefined;
|
|
14
|
+
backendUrl?: string | undefined;
|
|
15
|
+
user?: Record<string, any> | undefined;
|
|
16
|
+
metadata?: Record<string, any> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
isModal?: boolean | undefined;
|
|
19
|
+
modalIsOpen?: boolean | undefined;
|
|
20
|
+
modalOnCloseTriggered?: (() => void) | undefined;
|
|
21
|
+
modalCloseOnOutsideClick?: boolean | undefined;
|
|
22
|
+
} & import("react").RefAttributes<unknown>>;
|
|
23
|
+
export default _default;
|
|
24
|
+
export declare const Importer: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, {
|
|
25
|
+
darkMode?: boolean | undefined;
|
|
26
|
+
primaryColor?: string | undefined;
|
|
27
|
+
className?: string | undefined;
|
|
28
|
+
onComplete?: ((data: any) => void) | undefined;
|
|
29
|
+
waitOnComplete?: boolean | undefined;
|
|
30
|
+
customStyles?: string | Record<string, string> | undefined;
|
|
31
|
+
showDownloadTemplateButton?: boolean | undefined;
|
|
32
|
+
skipHeaderRowSelection?: boolean | undefined;
|
|
33
|
+
language?: string | undefined;
|
|
34
|
+
customTranslations?: import("i18next").Resource | undefined;
|
|
35
|
+
importerKey?: string | undefined;
|
|
36
|
+
backendUrl?: string | undefined;
|
|
37
|
+
user?: Record<string, any> | undefined;
|
|
38
|
+
metadata?: Record<string, any> | undefined;
|
|
39
|
+
} & {
|
|
40
|
+
isModal?: boolean | undefined;
|
|
41
|
+
modalIsOpen?: boolean | undefined;
|
|
42
|
+
modalOnCloseTriggered?: (() => void) | undefined;
|
|
43
|
+
modalCloseOnOutsideClick?: boolean | undefined;
|
|
44
|
+
} & import("react").RefAttributes<unknown>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import "../../i18n/i18n";
|
|
3
|
+
import "../../importer/style/index.scss";
|
|
4
|
+
import "./style/csv-importer.css";
|
|
5
|
+
declare const CSVImporter: React.ForwardRefExoticComponent<{
|
|
6
|
+
darkMode?: boolean | undefined;
|
|
7
|
+
primaryColor?: string | undefined;
|
|
8
|
+
className?: string | undefined;
|
|
9
|
+
onComplete?: ((data: any) => void) | undefined;
|
|
10
|
+
waitOnComplete?: boolean | undefined;
|
|
11
|
+
customStyles?: string | Record<string, string> | undefined;
|
|
12
|
+
showDownloadTemplateButton?: boolean | undefined;
|
|
13
|
+
skipHeaderRowSelection?: boolean | undefined;
|
|
14
|
+
language?: string | undefined;
|
|
15
|
+
customTranslations?: import("i18next").Resource | undefined;
|
|
16
|
+
importerKey?: string | undefined;
|
|
17
|
+
backendUrl?: string | undefined;
|
|
18
|
+
user?: Record<string, any> | undefined;
|
|
19
|
+
metadata?: Record<string, any> | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
isModal?: boolean | undefined;
|
|
22
|
+
modalIsOpen?: boolean | undefined;
|
|
23
|
+
modalOnCloseTriggered?: (() => void) | undefined;
|
|
24
|
+
modalCloseOnOutsideClick?: boolean | undefined;
|
|
25
|
+
} & React.RefAttributes<unknown>>;
|
|
26
|
+
export default CSVImporter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface EnvironmentConfig {
|
|
2
|
+
backendUrl: string;
|
|
3
|
+
}
|
|
4
|
+
interface Environments {
|
|
5
|
+
local: EnvironmentConfig;
|
|
6
|
+
dev: EnvironmentConfig;
|
|
7
|
+
prod: EnvironmentConfig;
|
|
8
|
+
[key: string]: EnvironmentConfig;
|
|
9
|
+
}
|
|
10
|
+
export declare const environments: Environments;
|
|
11
|
+
export declare const config: EnvironmentConfig;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const translations: {
|
|
2
|
+
Upload: string;
|
|
3
|
+
"Select Header": string;
|
|
4
|
+
"Map Columns": string;
|
|
5
|
+
"Expected Column": string;
|
|
6
|
+
Required: string;
|
|
7
|
+
"Drop your file here": string;
|
|
8
|
+
or: string;
|
|
9
|
+
"Browse files": string;
|
|
10
|
+
"Download Template": string;
|
|
11
|
+
"Only CSV, XLS, and XLSX files can be uploaded": string;
|
|
12
|
+
"Select Header Row": string;
|
|
13
|
+
"Select the row which contains the column headers": string;
|
|
14
|
+
"Only the first sheet ("{{sheet}}") of the Excel file will be imported. To import multiple sheets, please upload each sheet individually.": string;
|
|
15
|
+
Cancel: string;
|
|
16
|
+
Continue: string;
|
|
17
|
+
"Your File Column": string;
|
|
18
|
+
"Your Sample Data": string;
|
|
19
|
+
"Destination Column": string;
|
|
20
|
+
Include: string;
|
|
21
|
+
Submit: string;
|
|
22
|
+
"Loading...": string;
|
|
23
|
+
"Please include all required columns": string;
|
|
24
|
+
Back: string;
|
|
25
|
+
"- Select one -": string;
|
|
26
|
+
"- empty -": string;
|
|
27
|
+
"Import Successful": string;
|
|
28
|
+
"Upload Successful": string;
|
|
29
|
+
Done: string;
|
|
30
|
+
"Upload another file": string;
|
|
31
|
+
};
|
|
32
|
+
export default translations;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const translations: {
|
|
2
|
+
Upload: string;
|
|
3
|
+
"Select Header": string;
|
|
4
|
+
"Map Columns": string;
|
|
5
|
+
"Expected Column": string;
|
|
6
|
+
Required: string;
|
|
7
|
+
"Drop your file here": string;
|
|
8
|
+
or: string;
|
|
9
|
+
"Browse files": string;
|
|
10
|
+
"Download Template": string;
|
|
11
|
+
"Only CSV, XLS, and XLSX files can be uploaded": string;
|
|
12
|
+
"Select Header Row": string;
|
|
13
|
+
"Select the row which contains the column headers": string;
|
|
14
|
+
"Only the first sheet ("{{sheet}}") of the Excel file will be imported. To import multiple sheets, please upload each sheet individually.": string;
|
|
15
|
+
Cancel: string;
|
|
16
|
+
Continue: string;
|
|
17
|
+
"Your File Column": string;
|
|
18
|
+
"Your Sample Data": string;
|
|
19
|
+
"Destination Column": string;
|
|
20
|
+
Include: string;
|
|
21
|
+
Submit: string;
|
|
22
|
+
"Loading...": string;
|
|
23
|
+
"Please include all required columns": string;
|
|
24
|
+
Back: string;
|
|
25
|
+
"- Select one -": string;
|
|
26
|
+
"- empty -": string;
|
|
27
|
+
"Import Successful": string;
|
|
28
|
+
"Upload Successful": string;
|
|
29
|
+
Done: string;
|
|
30
|
+
"Upload another file": string;
|
|
31
|
+
};
|
|
32
|
+
export default translations;
|