@rowslint/importer-js 0.0.7 → 0.0.8
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/README.md +189 -141
- package/dist/rowslint.js +4 -4
- package/dist/rowslint.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
# @rowslint/importer-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# JavaScript
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The Rowslint JavaScript package provides access to the prebuilt widget importer component. The package interacts directly with the Rowslint APIs using your API key.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
There are 2 ways to use the importer, either using the `@rowslint/importer-js` npm package or directly from the CDN.
|
|
10
|
+
|
|
11
|
+
### npm package module (recommended)
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install @rowslint/importer-js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### CDN
|
|
6
18
|
|
|
7
19
|
Include a script tag with the import statement pointing to the CDN URL where the `@rowslint/importer-js` package is hosted:
|
|
8
20
|
|
|
@@ -10,41 +22,45 @@ Include a script tag with the import statement pointing to the CDN URL where the
|
|
|
10
22
|
<script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
|
|
11
23
|
```
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
## Usage
|
|
14
26
|
|
|
15
|
-
|
|
16
|
-
import { RowslintConfig } from '@rowslint/importer-js/dist/models/importer.model';
|
|
17
|
-
```
|
|
27
|
+
:::info
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
In the following examples we will use the npm package. if you wish to use the CDN script, simply change `launchRowslint({})` by `rowslint.launchRowslint({})`.
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
<script>
|
|
23
|
-
const launch = () => {
|
|
24
|
-
rowslint.launch({
|
|
25
|
-
// Your organization API key here.
|
|
26
|
-
apiKey: "ORGANIZATION_API_KEY",
|
|
27
|
-
config: {
|
|
28
|
-
// Your template key here.
|
|
29
|
-
templateKey: "TEMPLATE_KEY"
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
</script>
|
|
31
|
+
:::
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
Call the `launchRowslint()` method with the [organization API key](https://app.rowslint.io/settings/organization) and the template key parameters to display the importer UI.
|
|
34
|
+
|
|
35
|
+
Get the template key from the "**Settings**" tab in the template edit page.
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
import { launchRowslint } from '@rowslint/importer-js';
|
|
39
|
+
|
|
40
|
+
const launch = () => {
|
|
41
|
+
launchRowslint({
|
|
42
|
+
// Your organization API key here.
|
|
43
|
+
apiKey: 'ORGANIZATION_API_KEY',
|
|
44
|
+
config: {
|
|
45
|
+
// Your template key here.
|
|
46
|
+
templateKey: 'TEMPLATE_KEY',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
<button onclick="launch()">Launch</button>;
|
|
36
52
|
```
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
### Headless UI
|
|
39
55
|
|
|
40
|
-
You can also use your custom upload UI and then use Rowslint importer only to format and validate data (this will display the import modal without the first upload step). To do so, call the `
|
|
56
|
+
You can also use your custom upload UI and then use Rowslint importer SDK only to format and validate data (this will display the import modal without the first upload step). To do so, call the `launchRowslint()` method with the uploaded XLSX or CSV file (in `File` type).
|
|
41
57
|
|
|
42
58
|
```jsx
|
|
43
|
-
|
|
59
|
+
launchRowslint({
|
|
44
60
|
apiKey: 'ORGANIZATION_API_KEY',
|
|
45
61
|
config: {
|
|
46
62
|
templateKey: 'TEMPLATE_KEY',
|
|
47
|
-
// `inputFile` in `
|
|
63
|
+
// `inputFile` in `File` type.
|
|
48
64
|
file: inputFile,
|
|
49
65
|
},
|
|
50
66
|
});
|
|
@@ -52,12 +68,15 @@ rowslint.launch({
|
|
|
52
68
|
|
|
53
69
|
### Events
|
|
54
70
|
|
|
55
|
-
The `
|
|
71
|
+
The `launchRowslint()` method provide a callback parameter which is triggered on the importer modal closes. You can use it to handle the closing of the importer after the import has been completed.
|
|
72
|
+
|
|
73
|
+
See an example of the return format [here](#get-data).
|
|
56
74
|
|
|
57
75
|
```jsx
|
|
58
|
-
|
|
76
|
+
launchRowslint({
|
|
59
77
|
apiKey: 'ORGANIZATION_API_KEY',
|
|
60
78
|
config: { templateKey: 'TEMPLATE_KEY' },
|
|
79
|
+
// Callback.
|
|
61
80
|
onImport: (result) => {
|
|
62
81
|
switch (result.status) {
|
|
63
82
|
case 'success':
|
|
@@ -76,7 +95,7 @@ rowslint.launch({
|
|
|
76
95
|
|
|
77
96
|
## Parameters
|
|
78
97
|
|
|
79
|
-
The `
|
|
98
|
+
The `launchRowslint()` method take one object parameter with 4 properties:
|
|
80
99
|
|
|
81
100
|
| Name | Type | Required | Description |
|
|
82
101
|
| -------- | ---------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -119,30 +138,27 @@ Represents the return of the importer after the modal is closed.
|
|
|
119
138
|
|
|
120
139
|
### Importer UI
|
|
121
140
|
|
|
122
|
-
This example demonstrates how to use the importer by displaying the importer
|
|
141
|
+
This example demonstrates how to use the importer by displaying the importer modal and trigger the `onImport` callback when the import process is complete.
|
|
123
142
|
|
|
124
143
|
```jsx
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
<button onclick="launch()">Launch</button>
|
|
145
|
-
</body>
|
|
144
|
+
import { launchRowslint } from '@rowslint/importer-js';
|
|
145
|
+
|
|
146
|
+
const launch = () => {
|
|
147
|
+
launchRowslint({
|
|
148
|
+
apiKey: 'ORGANIZATION_API_KEY',
|
|
149
|
+
config: {
|
|
150
|
+
templateKey: 'TEMPLATE_KEY',
|
|
151
|
+
returnType: 'json',
|
|
152
|
+
},
|
|
153
|
+
onImport: (result) => {
|
|
154
|
+
if (result.status === 'success' && result.metadata?.is_valid) {
|
|
155
|
+
// Continue the import process.
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
<button onclick="launch()">Launch</button>;
|
|
146
162
|
```
|
|
147
163
|
|
|
148
164
|
### Headless importer UI
|
|
@@ -150,112 +166,144 @@ This example demonstrates how to use the importer by displaying the importer UI
|
|
|
150
166
|
In this example, we will use the importer in the headless mode without the first upload step. To do so, we will use our custom file input field to upload the file, then we will set it to the importer.
|
|
151
167
|
|
|
152
168
|
```jsx
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<input id="file" type="file" />
|
|
173
|
-
<button onclick="launch()">Launch</button>
|
|
174
|
-
</body>
|
|
169
|
+
import { launchRowslint } from '@rowslint/importer-js';
|
|
170
|
+
|
|
171
|
+
const launch = () => {
|
|
172
|
+
const inputFile = document.getElementById('file');
|
|
173
|
+
launchRowslint({
|
|
174
|
+
apiKey: 'ORGANIZATION_API_KEY',
|
|
175
|
+
config: {
|
|
176
|
+
templateKey: 'TEMPLATE_KEY',
|
|
177
|
+
returnType: 'xslx',
|
|
178
|
+
},
|
|
179
|
+
file: inputFile.files[0],
|
|
180
|
+
onImport: (result) => {
|
|
181
|
+
// Continue the import process.
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
<input id="file" type="file" />
|
|
187
|
+
<button onclick="launch()">Launch</button>
|
|
175
188
|
```
|
|
176
189
|
|
|
177
190
|
### Custom validations
|
|
178
191
|
|
|
179
|
-
We can define a custom configuration of validations from the code. Let's say our template has a "firstname" column. In this example, we will
|
|
192
|
+
We can define a custom configuration of validations from the code. Let's say our template has a "firstname" column. In this example, we will set a custom the validation of this column to accept only values starting with the letter "A".
|
|
180
193
|
|
|
181
194
|
```jsx
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
<button onclick="launch()">Launch</button>
|
|
211
|
-
</body>
|
|
195
|
+
import { launchRowslint } from '@rowslint/importer-js';
|
|
196
|
+
|
|
197
|
+
const launch = () => {
|
|
198
|
+
launchRowslint({
|
|
199
|
+
apiKey: 'ORGANIZATION_API_KEY',
|
|
200
|
+
config: {
|
|
201
|
+
templateKey: 'TEMPLATE_KEY',
|
|
202
|
+
},
|
|
203
|
+
customValidators: {
|
|
204
|
+
firstname: (columnValue) => {
|
|
205
|
+
if (typeof columnValue === 'string' && columnValue.startsWith('A')) {
|
|
206
|
+
// Return `true` if the value is valid.
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
// Return custom message if the value is invalid.
|
|
210
|
+
return {
|
|
211
|
+
message: 'Must start with the letter "A".',
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
onImport: (result) => {
|
|
216
|
+
// Continue the import process.
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
<button onclick="launch()">Launch</button>;
|
|
212
222
|
```
|
|
213
223
|
|
|
214
224
|
Note that:
|
|
215
225
|
|
|
216
226
|
- `firstname` property is the column name and must already be added to the template columns.
|
|
217
|
-
- By defining a column
|
|
227
|
+
- By defining a custom column validation, this will override the column validation type already defined in the template edition page.
|
|
218
228
|
|
|
219
229
|
We can also return a list of valid values to be displayed in a select field.
|
|
220
230
|
|
|
221
231
|
```jsx
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
<button onclick="launch()">Launch</button>
|
|
256
|
-
</body>
|
|
232
|
+
import { launchRowslint } from '@rowslint/importer-js';
|
|
233
|
+
|
|
234
|
+
const validValues = ['A', 'B'];
|
|
235
|
+
const launch = () => {
|
|
236
|
+
launchRowslint({
|
|
237
|
+
apiKey: 'ORGANIZATION_API_KEY',
|
|
238
|
+
config: {
|
|
239
|
+
templateKey: 'TEMPLATE_KEY',
|
|
240
|
+
},
|
|
241
|
+
customValidators: {
|
|
242
|
+
firstname: (columnValue) => {
|
|
243
|
+
if (typeof columnValue === 'string' && validValues.includes(columnValue)) {
|
|
244
|
+
// Return `true` if the value is valid.
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
// Return custom message if the value is invalid.
|
|
248
|
+
return {
|
|
249
|
+
message: 'Must be "A" or "B".',
|
|
250
|
+
validationType: 'choiceList',
|
|
251
|
+
validationOptions: {
|
|
252
|
+
list: validValues,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
onImport: (result) => {
|
|
258
|
+
// Continue the import process.
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
<button onclick="launch()">Launch</button>;
|
|
257
264
|
```
|
|
258
265
|
|
|
259
|
-
##
|
|
266
|
+
## Get data
|
|
267
|
+
|
|
268
|
+
The SDK data return type of the `onImport` callback is:
|
|
260
269
|
|
|
261
|
-
|
|
270
|
+
```ts
|
|
271
|
+
export interface RowslintImportResult {
|
|
272
|
+
status: RowslintImportResultStatus;
|
|
273
|
+
data?: {
|
|
274
|
+
file?: File;
|
|
275
|
+
rows?: Array<Record<string, unknown>>;
|
|
276
|
+
};
|
|
277
|
+
metadata?: {
|
|
278
|
+
is_valid: boolean;
|
|
279
|
+
file_name: string;
|
|
280
|
+
sheet_name?: string;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
enum RowslintImportResultStatus {
|
|
285
|
+
SUCCESS = 'success',
|
|
286
|
+
ERROR = 'error',
|
|
287
|
+
CANCELLED = 'cancelled',
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Here's an example:
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
{
|
|
295
|
+
status: "success",
|
|
296
|
+
metadata: {
|
|
297
|
+
is_valid: true,
|
|
298
|
+
file_name: "myFile.xlsx",
|
|
299
|
+
sheet_name: "Sheet1"
|
|
300
|
+
},
|
|
301
|
+
rows: [
|
|
302
|
+
{
|
|
303
|
+
firstname: "Jean",
|
|
304
|
+
lastname: "Pierre",
|
|
305
|
+
email: "jean@pierre.com"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
```
|
package/dist/rowslint.js
CHANGED
|
@@ -8,12 +8,12 @@ const d = (t) => {
|
|
|
8
8
|
"No API key provided to Rowslint. You may have forgotten to provide a valid API key to finish initializing Rowslint."
|
|
9
9
|
);
|
|
10
10
|
const e = document.createElement("rowslint-element");
|
|
11
|
-
e.apiKey = t.apiKey, e.config = t.config, e.file = t.file ?? null, e.
|
|
11
|
+
e.apiKey = t.apiKey, e.config = t.config, e.file = t.file ?? null, e.addEventListener("import", function o(i) {
|
|
12
12
|
var n;
|
|
13
|
-
const
|
|
14
|
-
(n = t.onImport) == null || n.call(t,
|
|
13
|
+
const l = i;
|
|
14
|
+
(n = t.onImport) == null || n.call(t, l.detail), s(), window.removeEventListener("import", o, !1);
|
|
15
15
|
}), document.body.appendChild(e);
|
|
16
|
-
},
|
|
16
|
+
}, s = () => {
|
|
17
17
|
const t = document.querySelector("rowslint-element");
|
|
18
18
|
t == null || t.remove();
|
|
19
19
|
};
|
package/dist/rowslint.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,
|
|
1
|
+
(function(t,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.rowslint={}))})(this,function(t){"use strict";(()=>{const e=document.createElement("script");e.src="https://cdn.jsdelivr.net/npm/@rowslint/importer@latest/browser/rowslint-element.js",document.head.appendChild(e)})();const n=e=>{if(!e.apiKey)throw new Error("No API key provided to Rowslint. You may have forgotten to provide a valid API key to finish initializing Rowslint.");const o=document.createElement("rowslint-element");o.apiKey=e.apiKey,o.config=e.config,o.file=e.file??null,o.addEventListener("import",function l(d){var i;const m=d;(i=e.onImport)==null||i.call(e,m.detail),s(),window.removeEventListener("import",l,!1)}),document.body.appendChild(o)},s=()=>{const e=document.querySelector("rowslint-element");e==null||e.remove()};t.launchRowslint=n,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|