fuse-importer 0.25.9 → 0.26.1

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 (80) hide show
  1. package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +11 -1
  2. package/lib/esm/Importer/Review/ReviewWithContext.js +4 -8
  3. package/lib/esm/Importer/Uploader/HeadersPreview.js +5 -9
  4. package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.d.ts +3 -3
  5. package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.js +35 -12
  6. package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +28 -2
  7. package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.d.ts +1 -2
  8. package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +21 -10
  9. package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +4 -2
  10. package/lib/esm/Importer/common/Spreadsheet/hooks.js +5 -68
  11. package/lib/esm/Importer/common/Spreadsheet/index.d.ts +1 -2
  12. package/lib/esm/Importer/common/Spreadsheet/index.js +2 -2
  13. package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +1 -1
  14. package/lib/esm/Importer/common/Spreadsheet/styles.js +2 -2
  15. package/lib/esm/Importer/common/index.js +1 -1
  16. package/lib/esm/Importer/common/utils.d.ts +4 -1
  17. package/lib/esm/Importer/common/utils.js +15 -4
  18. package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +2 -1
  19. package/lib/esm/Importer/contexts/ImporterContextProvider.js +27 -7
  20. package/lib/esm/Importer/data/index.d.ts +7 -2
  21. package/lib/esm/Importer/data/index.js +18 -10
  22. package/lib/esm/Importer/index.d.ts +3 -2
  23. package/lib/esm/Importer/index.js +2 -4
  24. package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +10 -25
  25. package/lib/esm/common/Table/TableActions/ExportData.js +3 -1
  26. package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.d.ts +1 -0
  27. package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +37 -0
  28. package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.styles.d.ts +6 -0
  29. package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.styles.js +24 -0
  30. package/lib/esm/common/Table/TableActions/FilterByErrors/functions.d.ts +11 -0
  31. package/lib/esm/common/Table/TableActions/FilterByErrors/functions.js +35 -0
  32. package/lib/esm/common/Table/TableActions/FilterByErrors/index.d.ts +1 -0
  33. package/lib/esm/common/Table/TableActions/FilterByErrors/index.js +1 -0
  34. package/lib/esm/common/Table/TableActions/SearchRows.js +3 -1
  35. package/lib/esm/common/Table/TableActions/TableActions.js +2 -1
  36. package/lib/esm/common/Table/TableActions/TableActions.styles.js +1 -1
  37. package/lib/esm/common/Table/TableActions/hooks.d.ts +20 -0
  38. package/lib/esm/common/Table/TableActions/hooks.js +96 -0
  39. package/lib/esm/common/Table/TableView/TableHeaders.d.ts +6 -8
  40. package/lib/esm/common/Table/TableView/TableHeaders.js +15 -14
  41. package/lib/esm/common/Table/TableView/{TableRow.d.ts → TableRows/TableRow.d.ts} +5 -5
  42. package/lib/esm/common/Table/TableView/{TableRow.js → TableRows/TableRow.js} +9 -6
  43. package/lib/esm/common/Table/TableView/TableRows/index.d.ts +4 -0
  44. package/lib/esm/common/Table/TableView/{TableCells.js → TableRows/index.js} +13 -11
  45. package/lib/esm/common/Table/TableView/common/index.d.ts +5 -0
  46. package/lib/esm/common/Table/TableView/{common.js → common/index.js} +18 -5
  47. package/lib/esm/common/Table/TableView/index.d.ts +4 -39
  48. package/lib/esm/common/Table/TableView/index.js +48 -65
  49. package/lib/esm/common/Table/TableView/types.d.ts +37 -0
  50. package/lib/esm/common/Table/TableView/types.js +1 -0
  51. package/lib/esm/common/Table/index.d.ts +2 -2
  52. package/lib/esm/common/Table/index.js +20 -16
  53. package/lib/esm/common/columnsValidations.d.ts +45 -0
  54. package/lib/esm/common/columnsValidations.js +351 -0
  55. package/lib/esm/common/index.d.ts +1 -0
  56. package/lib/esm/common/index.js +1 -0
  57. package/lib/esm/common/inputs/Autocomplete.d.ts +2 -1
  58. package/lib/esm/common/inputs/Autocomplete.js +2 -2
  59. package/lib/esm/common/inputs/SelectMenu.d.ts +1 -1
  60. package/lib/esm/common/inputs/SelectMenu.js +17 -9
  61. package/lib/esm/index.d.ts +4 -1
  62. package/lib/esm/index.js +56 -10
  63. package/lib/esm/locales/de.d.ts +20 -0
  64. package/lib/esm/locales/de.js +20 -0
  65. package/lib/esm/locales/en.d.ts +20 -0
  66. package/lib/esm/locales/en.js +20 -0
  67. package/lib/esm/locales/es.d.ts +20 -0
  68. package/lib/esm/locales/es.js +20 -0
  69. package/lib/esm/locales/fr.d.ts +20 -0
  70. package/lib/esm/locales/fr.js +20 -0
  71. package/lib/esm/types.d.ts +53 -1
  72. package/lib/esm/types.js +31 -0
  73. package/lib/esm/utils/index.d.ts +10 -0
  74. package/lib/esm/utils/index.js +31 -0
  75. package/lib/main.js +23 -23
  76. package/package.json +3 -2
  77. package/lib/esm/Importer/useFullscreenOverlay.d.ts +0 -1
  78. package/lib/esm/Importer/useFullscreenOverlay.js +0 -14
  79. package/lib/esm/common/Table/TableView/TableCells.d.ts +0 -4
  80. package/lib/esm/common/Table/TableView/common.d.ts +0 -9
@@ -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;
@@ -16,6 +16,7 @@ export type Props = {
16
16
  onToggle?: (isOpen: boolean) => void;
17
17
  placement?: Placement;
18
18
  icon?: JSX.Element;
19
+ prefix?: string;
19
20
  } & DivCSSProps;
20
- declare const Autocomplete: ({ label, isDisabled, isInputDisabled, placeholder, value, icon, onChange, placement, options, onToggle, id, labelTooltip, ...props }: Props) => JSX.Element;
21
+ declare const Autocomplete: ({ label, isDisabled, isInputDisabled, placeholder, value, icon, onChange, placement, options, onToggle, id, labelTooltip, prefix, ...props }: Props) => JSX.Element;
21
22
  export { Autocomplete };
@@ -47,7 +47,7 @@ var ClickableArea = styled(Div)(function (_a) {
47
47
  return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", "\n "], ["\n ", "\n "])), isInputDisabled && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n :hover {\n cursor: pointer;\n opacity: 0.9;\n }\n "], ["\n :hover {\n cursor: pointer;\n opacity: 0.9;\n }\n "]))));
48
48
  });
49
49
  var Autocomplete = function (_a) {
50
- var _b = _a.label, label = _b === void 0 ? null : _b, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isInputDisabled, isInputDisabled = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? "general:autocomplete.placeholder" : _e, value = _a.value, icon = _a.icon, onChange = _a.onChange, placement = _a.placement, options = _a.options, onToggle = _a.onToggle, id = _a.id, labelTooltip = _a.labelTooltip, props = __rest(_a, ["label", "isDisabled", "isInputDisabled", "placeholder", "value", "icon", "onChange", "placement", "options", "onToggle", "id", "labelTooltip"]);
50
+ var _b = _a.label, label = _b === void 0 ? null : _b, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isInputDisabled, isInputDisabled = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? "general:autocomplete.placeholder" : _e, value = _a.value, icon = _a.icon, onChange = _a.onChange, placement = _a.placement, options = _a.options, onToggle = _a.onToggle, id = _a.id, labelTooltip = _a.labelTooltip, prefix = _a.prefix, props = __rest(_a, ["label", "isDisabled", "isInputDisabled", "placeholder", "value", "icon", "onChange", "placement", "options", "onToggle", "id", "labelTooltip", "prefix"]);
51
51
  var _f = useState(false), updatedText = _f[0], setUpdatedText = _f[1];
52
52
  var selectedLabel = useMemo(function () { var _a; return ((_a = options === null || options === void 0 ? void 0 : options.find(function (o) { return (o === null || o === void 0 ? void 0 : o.value) === value; })) === null || _a === void 0 ? void 0 : _a.label) || ""; }, [value]);
53
53
  var _g = useState(selectedLabel), text = _g[0], setText = _g[1];
@@ -92,7 +92,7 @@ var Autocomplete = function (_a) {
92
92
  setText(selectedLabel);
93
93
  setIsMenuOpen(false);
94
94
  }
95
- }, label: label, isDisabled: isDisabled || isInputDisabled, placeholder: t(placeholder), value: text, onChange: function (v) { return setText(v); }, icon: isDisabled ? null : inputIconUI, labelTooltip: labelTooltip }) })), !isDisabled && filteredOptions.length > 0 && (_jsx(SelectMenu, __assign({ referenceElement: referenceElement, placement: placement, isOpen: isMenuOpen, onClose: function () { return setIsMenuOpen(false); } }, { children: filteredOptions.map(function (o, index) { return (_jsx(Div, { children: _jsx(MenuItem, __assign({ id: id ? "".concat(id, "-option-").concat(o.label) : null, isSelected: value === (o === null || o === void 0 ? void 0 : o.value), onClick: function () { return onSelect(o === null || o === void 0 ? void 0 : o.value); } }, { children: o.label })) }, index)); }) })))] })));
95
+ }, label: label, isDisabled: isDisabled || isInputDisabled, placeholder: t(placeholder), value: prefix ? "".concat(prefix).concat(text) : text, onChange: function (v) { return setText(v); }, icon: isDisabled ? null : inputIconUI, labelTooltip: labelTooltip }) })), !isDisabled && filteredOptions.length > 0 && (_jsx(SelectMenu, __assign({ referenceElement: referenceElement, placement: placement, isOpen: isMenuOpen, onClose: function () { return setIsMenuOpen(false); } }, { children: filteredOptions.map(function (o, index) { return (_jsx(Div, { children: _jsx(MenuItem, __assign({ id: id ? "".concat(id, "-option-").concat(o.label) : null, isSelected: value === (o === null || o === void 0 ? void 0 : o.value), onClick: function () { return onSelect(o === null || o === void 0 ? void 0 : o.value); } }, { children: o.label })) }, index)); }) })))] })));
96
96
  };
97
97
  var chevronDownIcon = (_jsx("svg", __assign({ width: "16", height: "9", viewBox: "0 0 16 9", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx("path", { d: "M14.9263 1L7.9631 7.96317L0.999928 1", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })));
98
98
  var clearIcon = (_jsxs("svg", __assign({ width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [_jsx("path", { d: "M4 4L12.5161 12.5161", stroke: "#333333", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M4 12.5161L12.5161 3.99998", stroke: "#333333", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })] })));
@@ -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,13 +6,16 @@ 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;
12
13
  onSubmit: OnSubmit;
13
14
  onClose: () => void;
15
+ private windowScrollPosition;
14
16
  close(): void;
15
17
  show(): Promise<void>;
18
+ addColumn<T extends FieldTypesAsUnion>({ options, ...requiredProps }: ColumnRequiredProps<T>): void;
16
19
  private renderImporterComponent;
17
20
  private createDivComponent;
18
21
  private createIframe;
package/lib/esm/index.js CHANGED
@@ -45,27 +45,45 @@ 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;
83
+ this.windowScrollPosition = {
84
+ x: 0,
85
+ y: 0,
86
+ };
69
87
  this.apiToken = apiToken;
70
88
  this.templateSlug = templateSlug;
71
89
  this.options = __assign({ env: "production", zIndex: 1000, batchValidationDelayMs: 500 }, options);
@@ -79,6 +97,9 @@ var FuseImporter = /** @class */ (function () {
79
97
  }
80
98
  var iframe = document.getElementById(fuseImporterId);
81
99
  document.body.removeChild(iframe);
100
+ // allow the scroll when the importer is closed
101
+ document.body.style.overflow = "auto";
102
+ window.scrollTo(this.windowScrollPosition.x, this.windowScrollPosition.y);
82
103
  };
83
104
  FuseImporter.prototype.show = function () {
84
105
  return __awaiter(this, void 0, void 0, function () {
@@ -96,12 +117,37 @@ var FuseImporter = /** @class */ (function () {
96
117
  }
97
118
  iframe = this.createIframe();
98
119
  importerComponent = this.createImporterComponent();
120
+ // saves the position of the page before the importer was opened
121
+ this.windowScrollPosition = {
122
+ x: window.scrollX,
123
+ y: window.scrollY,
124
+ };
125
+ // block the scroll when opening the importer
126
+ window.scrollTo(0, 0);
127
+ document.body.style.overflow = "hidden";
99
128
  this.configureIframe(iframe, importerComponent);
100
129
  return [2 /*return*/];
101
130
  }
102
131
  });
103
132
  });
104
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
+ };
105
151
  FuseImporter.prototype.renderImporterComponent = function () {
106
152
  var importerDiv = this.createDivComponent();
107
153
  var importerComponent = this.createImporterComponent();
@@ -125,7 +171,7 @@ var FuseImporter = /** @class */ (function () {
125
171
  var _this = this;
126
172
  return (_jsx(Importer, { apiToken: this.apiToken, templateSlug: this.templateSlug, options: this.options, formatRecord: this.formatRecord, onValidateRecord: this.onValidateRecord, onSubmit: this.onSubmit, onClose: function () {
127
173
  _this.close();
128
- } }));
174
+ }, dynamicColumns: this.dynamicColumns }));
129
175
  };
130
176
  FuseImporter.prototype.configureIframe = function (iframe, importerComponent) {
131
177
  var onLoadCallback = function () {
@@ -54,6 +54,26 @@ declare const _default: {
54
54
  manual_importer_title: string;
55
55
  export: string;
56
56
  description: string;
57
+ table_actions: {
58
+ search_rows: {
59
+ tooltip: string;
60
+ placeholder: string;
61
+ };
62
+ filter_by_errors: {
63
+ search_or_select: string;
64
+ filter_by_errors: string;
65
+ };
66
+ delete_rows: {
67
+ confirmation_modal: string;
68
+ modal_title: string;
69
+ yes_delete: string;
70
+ select_rows: string;
71
+ delete_row: string;
72
+ };
73
+ export_your_data: {
74
+ tooltip: string;
75
+ };
76
+ };
57
77
  };
58
78
  general: {
59
79
  autocomplete: {
@@ -55,6 +55,26 @@ export default {
55
55
  manual_importer_title: "Daten Eingeben und Senden",
56
56
  export: "Exportieren",
57
57
  description: "Einige Zellen im Dokument können Fehler im Format oder fehlende Informationen aufweisen. Bitte überprüfen Sie diese, um fortzufahren.",
58
+ table_actions: {
59
+ search_rows: {
60
+ tooltip: "Etwas suchen",
61
+ placeholder: "Etwas suchen...",
62
+ },
63
+ filter_by_errors: {
64
+ search_or_select: "Suchen oder auswählen",
65
+ filter_by_errors: "Nach Fehlern filtern",
66
+ },
67
+ delete_rows: {
68
+ confirmation_modal: "Möchtest du wirklich {{length}} Zeile löschen",
69
+ modal_title: "Ausgewählte Zeile löschen",
70
+ yes_delete: "Ja, löschen",
71
+ select_rows: "Wählen Sie Zeilen zum Löschen aus",
72
+ delete_row: "Zeile löschen",
73
+ },
74
+ export_your_data: {
75
+ tooltip: "Exportiere deine Daten",
76
+ },
77
+ },
58
78
  },
59
79
  general: {
60
80
  autocomplete: {