fuse-importer 0.26.0 → 0.26.2

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.
Files changed (36) hide show
  1. package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.js +7 -2
  2. package/lib/esm/Importer/common/Spreadsheet/hooks.js +3 -3
  3. package/lib/esm/Importer/common/index.js +1 -1
  4. package/lib/esm/Importer/common/utils.d.ts +4 -0
  5. package/lib/esm/Importer/common/utils.js +15 -0
  6. package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +2 -1
  7. package/lib/esm/Importer/contexts/ImporterContextProvider.js +27 -7
  8. package/lib/esm/Importer/index.d.ts +3 -2
  9. package/lib/esm/Importer/index.js +2 -2
  10. package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +1 -22
  11. package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +3 -1
  12. package/lib/esm/common/Table/TableActions/hooks.d.ts +5 -6
  13. package/lib/esm/common/Table/TableActions/hooks.js +34 -22
  14. package/lib/esm/common/Table/index.js +15 -11
  15. package/lib/esm/common/columnsValidations.d.ts +45 -0
  16. package/lib/esm/common/columnsValidations.js +351 -0
  17. package/lib/esm/common/index.d.ts +1 -0
  18. package/lib/esm/common/index.js +1 -0
  19. package/lib/esm/common/inputs/SelectMenu.d.ts +1 -1
  20. package/lib/esm/common/inputs/SelectMenu.js +17 -9
  21. package/lib/esm/index.d.ts +3 -1
  22. package/lib/esm/index.js +41 -10
  23. package/lib/esm/locales/de.d.ts +0 -1
  24. package/lib/esm/locales/de.js +0 -1
  25. package/lib/esm/locales/en.d.ts +0 -1
  26. package/lib/esm/locales/en.js +0 -1
  27. package/lib/esm/locales/es.d.ts +0 -1
  28. package/lib/esm/locales/es.js +0 -1
  29. package/lib/esm/locales/fr.d.ts +0 -1
  30. package/lib/esm/locales/fr.js +0 -1
  31. package/lib/esm/types.d.ts +52 -1
  32. package/lib/esm/types.js +31 -0
  33. package/lib/esm/utils/index.d.ts +10 -0
  34. package/lib/esm/utils/index.js +31 -0
  35. package/lib/main.js +22 -22
  36. package/package.json +9 -4
@@ -0,0 +1,351 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import * as yup from "yup";
47
+ import { FieldTypes, mutableValidationTypes, } from "../types";
48
+ var commonValidations = [
49
+ {
50
+ value: "regex",
51
+ label: "Must Match Regex",
52
+ options: [
53
+ {
54
+ type: "text",
55
+ key: "pattern",
56
+ tooltip: "Regex Pattern",
57
+ },
58
+ ],
59
+ },
60
+ ];
61
+ var uniqueValidation = [
62
+ { value: "unique_case_sensitive", label: "Must be Unique (case sensitive)" },
63
+ {
64
+ value: "unique_case_insensitive",
65
+ label: "Must be Unique (case insensitive)",
66
+ },
67
+ ];
68
+ var containsValidations = [
69
+ {
70
+ value: "cannot_contain",
71
+ label: "Cannot Contain",
72
+ options: [
73
+ {
74
+ type: "text",
75
+ key: "pattern",
76
+ tooltip: "It must be a word that you want to exclude",
77
+ },
78
+ ],
79
+ },
80
+ {
81
+ value: "contain",
82
+ label: "Must Contain",
83
+ options: [
84
+ {
85
+ type: "text",
86
+ key: "pattern",
87
+ tooltip: "It must be a word to be included mandatorily",
88
+ },
89
+ ],
90
+ },
91
+ ];
92
+ var stringValidations = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], containsValidations, true), [
93
+ {
94
+ value: "max_length",
95
+ label: "Length (shorter than)",
96
+ options: [
97
+ {
98
+ type: "number",
99
+ key: "max_length",
100
+ tooltip: "Number of characters",
101
+ },
102
+ ],
103
+ },
104
+ {
105
+ value: "min_length",
106
+ label: "Length (longer than)",
107
+ options: [
108
+ {
109
+ type: "number",
110
+ key: "min_length",
111
+ tooltip: "Number of characters",
112
+ },
113
+ ],
114
+ },
115
+ {
116
+ value: "length_exactly",
117
+ label: "Length (exactly)",
118
+ options: [
119
+ {
120
+ type: "number",
121
+ key: "length",
122
+ tooltip: "Number of characters",
123
+ },
124
+ ],
125
+ }
126
+ ], false), uniqueValidation, true), commonValidations, true);
127
+ var numericValidations = __spreadArray(__spreadArray([
128
+ {
129
+ value: "less_than",
130
+ label: "Must Be Less Than",
131
+ options: [
132
+ {
133
+ type: "number",
134
+ key: "max",
135
+ tooltip: "The max allowed value",
136
+ },
137
+ ],
138
+ },
139
+ {
140
+ value: "greater_than",
141
+ label: "Must Be Greater Than",
142
+ options: [
143
+ {
144
+ type: "number",
145
+ key: "min",
146
+ tooltip: "The minimum allowed value",
147
+ },
148
+ ],
149
+ },
150
+ { value: "even", label: "Must be Even" },
151
+ { value: "odd", label: "Must be Odd" }
152
+ ], uniqueValidation, true), commonValidations, true);
153
+ var emailValidations = __spreadArray([
154
+ { value: "email", label: "Must be an email", isDefaultValidation: true }
155
+ ], stringValidations, true);
156
+ var urlValidations = __spreadArray([
157
+ { value: "url", label: "Must be a URL", isDefaultValidation: true }
158
+ ], stringValidations, true);
159
+ var booleanValidations = [
160
+ {
161
+ value: "boolean",
162
+ label: "Must be True or False",
163
+ isDefaultValidation: true,
164
+ },
165
+ ];
166
+ var structuredDataValidations = __spreadArray([], uniqueValidation, true);
167
+ var dateValidations = __spreadArray(__spreadArray([], uniqueValidation, true), [
168
+ {
169
+ value: "before_date",
170
+ label: "Must Be Before Date",
171
+ options: [
172
+ {
173
+ type: "date",
174
+ key: "max",
175
+ tooltip: "The maximum allowed date",
176
+ },
177
+ ],
178
+ },
179
+ {
180
+ value: "after_date",
181
+ label: "Must Be After Date",
182
+ options: [
183
+ {
184
+ type: "date",
185
+ key: "min",
186
+ tooltip: "The minimum allowed date",
187
+ },
188
+ ],
189
+ },
190
+ ], false);
191
+ export var validationsByColumnType = {
192
+ string: stringValidations,
193
+ integer: __spreadArray([
194
+ {
195
+ value: "integer",
196
+ label: "Must be an integer",
197
+ isDefaultValidation: true,
198
+ }
199
+ ], numericValidations, true),
200
+ float: __spreadArray([
201
+ {
202
+ value: "float",
203
+ label: "Must be a float",
204
+ isDefaultValidation: true,
205
+ }
206
+ ], numericValidations, true),
207
+ email: emailValidations,
208
+ enum: structuredDataValidations,
209
+ url: urlValidations,
210
+ boolean: booleanValidations,
211
+ date: dateValidations,
212
+ datetime: dateValidations,
213
+ time: uniqueValidation,
214
+ };
215
+ export var validationsByType = Object.values(validationsByColumnType)
216
+ .reduce(function (acc, arr) { return acc.concat(arr); }, [])
217
+ .reduce(function (result, p) {
218
+ result[p.value] = p;
219
+ return result;
220
+ }, {});
221
+ export var availableColumnTypes = Object.keys(validationsByColumnType);
222
+ export var datePatterns = [
223
+ {
224
+ value: "MM/dd/yyyy",
225
+ label: "MM/dd/yyyy",
226
+ },
227
+ ];
228
+ export var dateTimePatterns = [
229
+ {
230
+ value: "MM/dd/yyyy HH:mm",
231
+ label: "MM/dd/yyyy HH:mm",
232
+ },
233
+ {
234
+ value: "MM/dd/yyyy HH:mm:ss",
235
+ label: "MM/dd/yyyy HH:mm:ss",
236
+ },
237
+ ];
238
+ export var timePatterns = [
239
+ {
240
+ value: "HH:mm",
241
+ label: "HH:mm",
242
+ },
243
+ {
244
+ value: "HH:mm:ss",
245
+ label: "HH:mm:ss",
246
+ },
247
+ ];
248
+ export var allowedPatterns = {
249
+ date: datePatterns,
250
+ datetime: dateTimePatterns,
251
+ time: timePatterns,
252
+ };
253
+ export var patternsColumnTypes = Object.keys(allowedPatterns);
254
+ var iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
255
+ var schema = yup
256
+ .mixed()
257
+ .test("validations", "Invalid validations", function (value) {
258
+ var isAnArray = Array.isArray(value);
259
+ if (isAnArray) {
260
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
261
+ var validation = value_1[_i];
262
+ var validation_type = validation.validation_type, options = validation.options;
263
+ var optionsPropertyIsNotRequiredFor = [
264
+ "unique_case_insensitive",
265
+ "unique_case_sensitive",
266
+ ];
267
+ if (mutableValidationTypes.includes(validation_type)) {
268
+ if (optionsPropertyIsNotRequiredFor.includes(validation_type)) {
269
+ continue;
270
+ }
271
+ if (!options) {
272
+ return this.createError({
273
+ path: "validations",
274
+ message: "Options is required for this validation type",
275
+ });
276
+ }
277
+ var min = options.min, max = options.max;
278
+ var minOptionDoesNotMatchISO = min && !min.match(iso8601Regex);
279
+ var maxOptionDoesNotMatchISO = max && !max.match(iso8601Regex);
280
+ if (minOptionDoesNotMatchISO || maxOptionDoesNotMatchISO) {
281
+ return this.createError({
282
+ path: "validations",
283
+ message: "Invalid ISO 8601 format for min or max",
284
+ });
285
+ }
286
+ }
287
+ else {
288
+ return this.createError({
289
+ path: "validations",
290
+ message: "".concat(validation_type, " is not a valid validation type. Please check the values you inserted."),
291
+ });
292
+ }
293
+ }
294
+ return true;
295
+ }
296
+ var arrayIsNotDefined = !["undefined", "null"].includes(typeof value);
297
+ if (arrayIsNotDefined && !isAnArray) {
298
+ return this.createError({
299
+ path: "validations",
300
+ message: "Validations must be an array",
301
+ });
302
+ }
303
+ return true;
304
+ });
305
+ var columnSchema = yup.object().shape({
306
+ column_type: yup.string().oneOf(availableColumnTypes).required(),
307
+ internal_key: yup.string().required(),
308
+ label: yup.string().required(),
309
+ required: yup.boolean().required(),
310
+ validations: schema,
311
+ });
312
+ var dateColumnSchema = columnSchema.shape({
313
+ pattern: yup.string().oneOf(datePatterns.map(function (p) { return p.value; })),
314
+ });
315
+ var dateTimeColumnSchema = columnSchema.shape({
316
+ pattern: yup.string().oneOf(dateTimePatterns.map(function (p) { return p.value; })),
317
+ });
318
+ var timeColumnSchema = columnSchema.shape({
319
+ pattern: yup.string().oneOf(timePatterns.map(function (p) { return p.value; })),
320
+ });
321
+ var enumColumnSchema = columnSchema.shape({
322
+ values: yup.array().of(yup.string()).min(1).required(),
323
+ });
324
+ export var validateColumn = function (columnData) { return __awaiter(void 0, void 0, void 0, function () {
325
+ var schema, error_1;
326
+ return __generator(this, function (_a) {
327
+ switch (_a.label) {
328
+ case 0:
329
+ schema = columnData.column_type === FieldTypes.date
330
+ ? dateColumnSchema
331
+ : columnData.column_type === FieldTypes.datetime
332
+ ? dateTimeColumnSchema
333
+ : columnData.column_type === FieldTypes.time
334
+ ? timeColumnSchema
335
+ : columnData.column_type === FieldTypes.enum
336
+ ? enumColumnSchema
337
+ : columnSchema;
338
+ _a.label = 1;
339
+ case 1:
340
+ _a.trys.push([1, 3, , 4]);
341
+ return [4 /*yield*/, schema.validate(columnData, { abortEarly: true })];
342
+ case 2:
343
+ _a.sent();
344
+ return [3 /*break*/, 4];
345
+ case 3:
346
+ error_1 = _a.sent();
347
+ throw new Error("Error on custom column creation: ".concat(error_1.message));
348
+ case 4: return [2 /*return*/];
349
+ }
350
+ });
351
+ }); };
@@ -23,3 +23,4 @@ export * from "./Modal";
23
23
  export * from "./Spinner";
24
24
  export * from "./TooltipProvider";
25
25
  export * from "./ConfirmationModal";
26
+ export * from "./columnsValidations";
@@ -40,4 +40,5 @@ export * from "./Modal";
40
40
  export * from "./Spinner";
41
41
  export * from "./TooltipProvider";
42
42
  export * from "./ConfirmationModal";
43
+ export * from "./columnsValidations";
43
44
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
@@ -1,5 +1,5 @@
1
- import { DivCSSProps } from "../../styled/utils";
2
1
  import { Placement } from "@popperjs/core";
2
+ import { DivCSSProps } from "../../styled/utils";
3
3
  export declare const SelectMenuBackdrop: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../styled/utils").CSSProps, never>;
4
4
  export declare const SelectMenuDiv: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../styled/utils").CSSProps, never>;
5
5
  export declare const SelectMenuScrollArea: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../styled/utils").CSSProps, never>;
@@ -25,21 +25,24 @@ var __rest = (this && this.__rest) || function (s, e) {
25
25
  return t;
26
26
  };
27
27
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
28
- import { useEffect, useMemo, useState } from "react";
29
- import styled, { css } from "styled-components";
28
+ import { useEffect, useLayoutEffect, useState } from "react";
30
29
  import { usePopper } from "react-popper";
30
+ import styled, { css } from "styled-components";
31
31
  import { Div } from "../../styled/utils";
32
32
  export var SelectMenuBackdrop = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: fixed;\n top: 0px;\n left: 0px;\n margin: 0px;\n width: 100vw;\n height: 100vh;\n z-index: 99999999;\n display: flex;\n"], ["\n position: fixed;\n top: 0px;\n left: 0px;\n margin: 0px;\n width: 100vw;\n height: 100vh;\n z-index: 99999999;\n display: flex;\n"])));
33
- export var SelectMenuDiv = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: white;\n border: solid 1px ", ";\n position: absolute;\n border-radius: 16px;\n width: 100%;\n overflow: hidden;\n z-index: 10000000000;\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.12);\n"], ["\n background-color: white;\n border: solid 1px ", ";\n position: absolute;\n border-radius: 16px;\n width: 100%;\n overflow: hidden;\n z-index: 10000000000;\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.12);\n"])), function (p) { return p.theme.colors.gray5; });
33
+ export var SelectMenuDiv = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: white;\n border: solid 1px ", ";\n position: absolute;\n border-radius: 16px;\n overflow: hidden;\n z-index: 10000000000;\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.12);\n"], ["\n background-color: white;\n border: solid 1px ", ";\n position: absolute;\n border-radius: 16px;\n overflow: hidden;\n z-index: 10000000000;\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.12);\n"])), function (p) { return p.theme.colors.gray5; });
34
34
  export var SelectMenuScrollArea = styled(Div)(function (_a) {
35
35
  var _b = _a.theme, colors = _b.colors, c = _b.css;
36
36
  return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: 16px;\n overflow-y: auto;\n max-height: 250px;\n ", ";\n "], ["\n padding: 16px;\n overflow-y: auto;\n max-height: 250px;\n ", ";\n "])), function (p) { return p.theme.css.scrollbarDark; });
37
37
  });
38
38
  export var SelectMenu = function (_a) {
39
- var _b = _a.isOpen, isOpen = _b === void 0 ? false : _b, _c = _a.onClose, onClose = _c === void 0 ? null : _c, _d = _a.placement, placement = _d === void 0 ? "auto" : _d, referenceElement = _a.referenceElement, children = _a.children, props = __rest(_a, ["isOpen", "onClose", "placement", "referenceElement", "children"]);
40
- var _e = useState(null), popperElement = _e[0], setPopperElement = _e[1];
41
- var options = useMemo(function () { return ({
39
+ var _b;
40
+ var _c = _a.isOpen, isOpen = _c === void 0 ? false : _c, _d = _a.onClose, onClose = _d === void 0 ? null : _d, _e = _a.placement, placement = _e === void 0 ? "auto" : _e, referenceElement = _a.referenceElement, children = _a.children, props = __rest(_a, ["isOpen", "onClose", "placement", "referenceElement", "children"]);
41
+ var _f = useState(null), popperElement = _f[0], setPopperElement = _f[1];
42
+ var _g = useState(null), width = _g[0], setWidth = _g[1];
43
+ var options = {
42
44
  placement: placement,
45
+ strategy: "fixed",
43
46
  modifiers: [
44
47
  {
45
48
  name: "offset",
@@ -48,12 +51,17 @@ export var SelectMenu = function (_a) {
48
51
  },
49
52
  },
50
53
  ],
51
- }); }, [placement]);
52
- var _f = usePopper(referenceElement, popperElement, options), styles = _f.styles, attributes = _f.attributes, update = _f.update;
54
+ };
55
+ var _h = usePopper(referenceElement, popperElement, options), styles = _h.styles, attributes = _h.attributes, update = _h.update;
53
56
  useEffect(function () {
54
57
  if (update)
55
58
  update();
56
59
  }, [isOpen]);
57
- return (_jsx(_Fragment, { children: isOpen && (_jsxs(Div, __assign({ pRelative: true }, props, { children: [_jsx(SelectMenuBackdrop, { onClick: onClose }), _jsx(SelectMenuDiv, __assign({ ref: setPopperElement, style: styles.popper }, attributes.popper, { children: _jsx(SelectMenuScrollArea, { children: children }) }))] }))) }));
60
+ var referenceElementWidth = (_b = referenceElement === null || referenceElement === void 0 ? void 0 : referenceElement.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width;
61
+ useLayoutEffect(function () {
62
+ if (referenceElement)
63
+ setWidth(referenceElementWidth);
64
+ }, [referenceElementWidth]);
65
+ return (_jsx(_Fragment, { children: isOpen && (_jsxs(Div, __assign({ pRelative: true }, props, { children: [_jsx(SelectMenuBackdrop, { onClick: onClose }), _jsx(SelectMenuDiv, __assign({ ref: setPopperElement, style: __assign(__assign({}, styles.popper), { width: width }) }, attributes.popper, { children: _jsx(SelectMenuScrollArea, { children: children }) }))] }))) }));
58
66
  };
59
67
  var templateObject_1, templateObject_2, templateObject_3;
@@ -1,4 +1,4 @@
1
- import { EnvironmentType, FormatRecord, ImporterOptions, OnSubmit, OnValidateRecord } from "./types";
1
+ import { ColumnRequiredProps, EnvironmentType, FieldTypesAsUnion, FormatRecord, ImporterOptions, OnSubmit, OnValidateRecord } from "./types";
2
2
  declare class FuseImporter {
3
3
  apiToken: string;
4
4
  templateSlug: string;
@@ -6,6 +6,7 @@ declare class FuseImporter {
6
6
  zIndex: number;
7
7
  options: ImporterOptions;
8
8
  constructor(apiToken: string, templateSlug: string, options?: ImporterOptions);
9
+ private dynamicColumns;
9
10
  private cleanupIframe;
10
11
  formatRecord: FormatRecord;
11
12
  onValidateRecord: OnValidateRecord;
@@ -14,6 +15,7 @@ declare class FuseImporter {
14
15
  private windowScrollPosition;
15
16
  close(): void;
16
17
  show(): Promise<void>;
18
+ addColumn<T extends FieldTypesAsUnion>({ options, ...requiredProps }: ColumnRequiredProps<T>): void;
17
19
  private renderImporterComponent;
18
20
  private createDivComponent;
19
21
  private createIframe;
package/lib/esm/index.js CHANGED
@@ -45,26 +45,40 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
59
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
61
+ if (ar || !(i in from)) {
62
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
63
+ ar[i] = from[i];
64
+ }
65
+ }
66
+ return to.concat(ar || Array.prototype.slice.call(from));
67
+ };
48
68
  import { jsx as _jsx } from "react/jsx-runtime";
49
69
  import ReactDOM from "react-dom";
50
70
  import { Importer } from "./Importer";
51
- import { fuseImporterId } from "./common";
71
+ import { fuseImporterId, validateColumn } from "./common";
52
72
  import i18n from "i18next";
53
73
  import { initReactI18next } from "react-i18next";
54
74
  import * as locales from "./locales";
55
75
  import { StyleSheetManager } from "styled-components";
56
76
  import { fontsURL } from "./styled/fontsURL";
57
- var addLinkToHead = function (document, head, href, rel, crossOrigin) {
58
- if (crossOrigin === void 0) { crossOrigin = ""; }
59
- var link = document.createElement("link");
60
- link.href = href;
61
- link.rel = rel;
62
- link.crossOrigin = crossOrigin;
63
- head.appendChild(link);
64
- };
77
+ import { addLinkToHead, getDefaultValidations } from "./utils";
65
78
  var FuseImporter = /** @class */ (function () {
66
79
  function FuseImporter(apiToken, templateSlug, options) {
67
80
  if (options === void 0) { options = {}; }
81
+ this.dynamicColumns = [];
68
82
  this.cleanupIframe = null;
69
83
  this.windowScrollPosition = {
70
84
  x: 0,
@@ -117,6 +131,23 @@ var FuseImporter = /** @class */ (function () {
117
131
  });
118
132
  });
119
133
  };
134
+ FuseImporter.prototype.addColumn = function (_a) {
135
+ var options = _a.options, requiredProps = __rest(_a, ["options"]);
136
+ validateColumn(__assign(__assign({}, options), requiredProps));
137
+ var validations = __spreadArray(__spreadArray([], getDefaultValidations(requiredProps.column_type), true), ((options === null || options === void 0 ? void 0 : options.validations) || []), true);
138
+ var column = {
139
+ column_type: requiredProps.column_type,
140
+ internal_key: requiredProps.internal_key,
141
+ label: requiredProps.label,
142
+ required: requiredProps.required,
143
+ pattern: (options === null || options === void 0 ? void 0 : options.pattern) || null,
144
+ position: (options === null || options === void 0 ? void 0 : options.position) || null,
145
+ unique: (options === null || options === void 0 ? void 0 : options.unique) || false,
146
+ values: requiredProps.column_type === "enum" ? (options === null || options === void 0 ? void 0 : options.values) || [] : [],
147
+ validations: validations,
148
+ };
149
+ this.dynamicColumns.push(column);
150
+ };
120
151
  FuseImporter.prototype.renderImporterComponent = function () {
121
152
  var importerDiv = this.createDivComponent();
122
153
  var importerComponent = this.createImporterComponent();
@@ -140,7 +171,7 @@ var FuseImporter = /** @class */ (function () {
140
171
  var _this = this;
141
172
  return (_jsx(Importer, { apiToken: this.apiToken, templateSlug: this.templateSlug, options: this.options, formatRecord: this.formatRecord, onValidateRecord: this.onValidateRecord, onSubmit: this.onSubmit, onClose: function () {
142
173
  _this.close();
143
- } }));
174
+ }, dynamicColumns: this.dynamicColumns }));
144
175
  };
145
176
  FuseImporter.prototype.configureIframe = function (iframe, importerComponent) {
146
177
  var onLoadCallback = function () {
@@ -64,7 +64,6 @@ declare const _default: {
64
64
  filter_by_errors: string;
65
65
  };
66
66
  delete_rows: {
67
- delete_toast: string;
68
67
  confirmation_modal: string;
69
68
  modal_title: string;
70
69
  yes_delete: string;
@@ -65,7 +65,6 @@ export default {
65
65
  filter_by_errors: "Nach Fehlern filtern",
66
66
  },
67
67
  delete_rows: {
68
- delete_toast: "Du hast alle Zeilen gelöscht. Du wirst zum Upload-Schritt weitergeleitet.",
69
68
  confirmation_modal: "Möchtest du wirklich {{length}} Zeile löschen",
70
69
  modal_title: "Ausgewählte Zeile löschen",
71
70
  yes_delete: "Ja, löschen",
@@ -64,7 +64,6 @@ declare const _default: {
64
64
  filter_by_errors: string;
65
65
  };
66
66
  delete_rows: {
67
- delete_toast: string;
68
67
  confirmation_modal: string;
69
68
  modal_title: string;
70
69
  yes_delete: string;
@@ -65,7 +65,6 @@ export default {
65
65
  filter_by_errors: "Filter by errors",
66
66
  },
67
67
  delete_rows: {
68
- delete_toast: "You have deleted all the rows. You will be redirect to the upload step.",
69
68
  confirmation_modal: "Are you sure you want to delete {{length}} row",
70
69
  modal_title: "Delete Selected Row",
71
70
  yes_delete: "Yes, delete",
@@ -64,7 +64,6 @@ declare const _default: {
64
64
  filter_by_errors: string;
65
65
  };
66
66
  delete_rows: {
67
- delete_toast: string;
68
67
  confirmation_modal: string;
69
68
  modal_title: string;
70
69
  yes_delete: string;
@@ -65,7 +65,6 @@ export default {
65
65
  filter_by_errors: "Filtrar por errores",
66
66
  },
67
67
  delete_rows: {
68
- delete_toast: "Has eliminado todas las filas. Serás redirigido al paso de carga.",
69
68
  confirmation_modal: "¿Seguro que quieres eliminar {{length}} fila",
70
69
  modal_title: "Eliminar la fila seleccionada",
71
70
  yes_delete: "Sí, eliminar",
@@ -64,7 +64,6 @@ declare const _default: {
64
64
  filter_by_errors: string;
65
65
  };
66
66
  delete_rows: {
67
- delete_toast: string;
68
67
  confirmation_modal: string;
69
68
  modal_title: string;
70
69
  yes_delete: string;
@@ -65,7 +65,6 @@ export default {
65
65
  filter_by_errors: "Filtrer par erreurs",
66
66
  },
67
67
  delete_rows: {
68
- delete_toast: "Vous avez supprimé toutes les lignes. Vous serez redirigé vers l'étape de téléchargement.",
69
68
  confirmation_modal: "Voulez-vous vraiment supprimer {{length}} ligne",
70
69
  modal_title: "Supprimer la ligne sélectionnée",
71
70
  yes_delete: "Oui, supprimer",