fuse-importer 0.1.8-testing → 0.2.0-testing
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/lib/esm/Importer/ImporterWithContext.js +11 -9
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +3 -3
- package/lib/esm/Importer/PreviewFirstTime.js +1 -1
- package/lib/esm/Importer/PreviewModeBanner.js +2 -2
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +2 -2
- package/lib/esm/Importer/Review/ReviewContextProvider.js +6 -6
- package/lib/esm/Importer/Stepper/StepperSubmitModal.js +21 -4
- package/lib/esm/Importer/Stepper/index.js +19 -17
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterSectionHeader/index.js +1 -1
- package/lib/esm/Importer/WarningsBanner.d.ts +3 -0
- package/lib/esm/Importer/WarningsBanner.js +42 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.d.ts +5 -4
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.js +104 -50
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.d.ts +1 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.js +6 -1
- package/lib/esm/Importer/common/Spreadsheet/KeyboardEventContextProvider/index.d.ts +7 -0
- package/lib/esm/Importer/common/Spreadsheet/KeyboardEventContextProvider/index.js +73 -0
- package/lib/esm/Importer/common/Spreadsheet/SearchContextProvider/index.d.ts +15 -0
- package/lib/esm/Importer/common/Spreadsheet/SearchContextProvider/index.js +43 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.d.ts +3 -2
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.js +40 -26
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.d.ts +2 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.js +2 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts +2 -2
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js +13 -4
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useCellSelection.d.ts +24 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useCellSelection.js +207 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts +4 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +101 -24
- package/lib/esm/Importer/common/Spreadsheet/UndoRedoContextProvider/index.d.ts +16 -0
- package/lib/esm/Importer/common/Spreadsheet/UndoRedoContextProvider/index.js +104 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.js +28 -12
- package/lib/esm/Importer/common/Spreadsheet/common/index.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +13 -5
- package/lib/esm/Importer/common/Spreadsheet/components/FindAndReplace/index.js +65 -15
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData/CellContextProvider.d.ts +23 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData/CellContextProvider.js +128 -0
- package/lib/esm/Importer/common/Spreadsheet/components/{SpreadsheetData.d.ts → SpreadsheetData/index.d.ts} +1 -1
- package/lib/esm/Importer/common/Spreadsheet/components/{SpreadsheetData.js → SpreadsheetData/index.js} +19 -18
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +8 -8
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpeadsheetAutocomplete.js +3 -4
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.js +8 -8
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.d.ts +11 -0
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.js +26 -18
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +2 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +8 -1
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +18 -5
- package/lib/esm/Importer/hooks/useSubmitToServer.d.ts +1 -1
- package/lib/esm/Importer/hooks/useSubmitToServer.js +55 -9
- package/lib/esm/common/CircleSpinner.d.ts +1 -0
- package/lib/esm/common/CircleSpinner.js +13 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.js +56 -21
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.js +28 -23
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +3 -3
- package/lib/esm/common/Table/TableActions/RowFilters.js +2 -2
- package/lib/esm/common/Table/TableActions/SearchRows.js +18 -26
- package/lib/esm/common/Table/TableActions/TableActions.js +7 -4
- package/lib/esm/common/Table/TableActions/TableActions.styles.js +1 -1
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +3 -3
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +1 -1
- package/lib/esm/common/Table/TableView/index.d.ts +1 -1
- package/lib/esm/common/Table/TableView/index.js +2 -2
- package/lib/esm/common/Table/TableView/types.d.ts +1 -0
- package/lib/esm/common/Toast.d.ts +9 -1
- package/lib/esm/common/Toast.js +29 -8
- package/lib/esm/common/icons/index.js +3 -3
- package/lib/esm/common/inputs/Autocomplete.js +2 -2
- package/lib/esm/common/inputs/TextInput.d.ts +1 -0
- package/lib/esm/common/inputs/TextInput.js +10 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/locales/de.d.ts +10 -0
- package/lib/esm/locales/de.js +10 -0
- package/lib/esm/locales/en.d.ts +10 -0
- package/lib/esm/locales/en.js +10 -0
- package/lib/esm/locales/es.d.ts +10 -0
- package/lib/esm/locales/es.js +10 -0
- package/lib/esm/locales/fr.d.ts +10 -0
- package/lib/esm/locales/fr.js +10 -0
- package/lib/esm/types.d.ts +1 -0
- package/lib/main.js +8 -8
- package/package.json +1 -1
- package/lib/esm/Importer/TrialModeBanner.d.ts +0 -1
- package/lib/esm/Importer/TrialModeBanner.js +0 -22
|
@@ -2,6 +2,7 @@ import React, { MutableRefObject } from "react";
|
|
|
2
2
|
import { SpreadsheetFilter } from "../SpreadsheetContextProvider/useSpreadsheetFilter";
|
|
3
3
|
import { SortBy } from "../common/types";
|
|
4
4
|
export type State = {
|
|
5
|
+
isSortingOrFiltering: boolean;
|
|
5
6
|
filteredDataIds: string[];
|
|
6
7
|
filteredInputValue: string;
|
|
7
8
|
setFilteredInputValue: (value: string) => void;
|
|
@@ -43,7 +43,7 @@ export var FilteredDataContextProvider = function (_a) {
|
|
|
43
43
|
var _h = useState(false), recalculateFilters = _h[0], setRecalculateFilters = _h[1];
|
|
44
44
|
var lastFilteredRecordId = useRef(null);
|
|
45
45
|
var _j = useEventManagerContext(), on = _j.on, off = _j.off, EVENTS = _j.EVENTS;
|
|
46
|
-
var _k = useDataSetContext(), getRecord = _k.getRecord, dataSet = _k.dataSet;
|
|
46
|
+
var _k = useDataSetContext(), getRecord = _k.getRecord, dataSet = _k.dataSet, dataSetLength = _k.dataSetLength;
|
|
47
47
|
var duplicateRecordIds = useDuplicateDataContext().duplicateRecordIds;
|
|
48
48
|
var _l = useValidationContext(), errors = _l.errors, warnings = _l.warnings;
|
|
49
49
|
var reset = function () {
|
|
@@ -127,7 +127,12 @@ export var FilteredDataContextProvider = function (_a) {
|
|
|
127
127
|
setSortByFieldErrors(null);
|
|
128
128
|
setSortBy(null);
|
|
129
129
|
}, [sortByFieldWarnings]);
|
|
130
|
+
var isSortingOrFiltering = filteredDataIds.length !== dataSetLength.current ||
|
|
131
|
+
!!sortByFieldErrors ||
|
|
132
|
+
!!sortByFieldWarnings ||
|
|
133
|
+
!!sortBy;
|
|
130
134
|
var value = {
|
|
135
|
+
isSortingOrFiltering: isSortingOrFiltering,
|
|
131
136
|
filteredDataIds: filteredDataIds,
|
|
132
137
|
filteredInputValue: filteredInputValue,
|
|
133
138
|
setFilteredInputValue: setFilteredInputValue,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type State = {};
|
|
3
|
+
export declare const KeyboardEventContext: React.Context<State>;
|
|
4
|
+
export declare const KeyboardEventContextProvider: ({ children }: {
|
|
5
|
+
children: any;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
export declare const useDataSetContext: () => State;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useImporterContext } from "../../../../Importer/contexts/ImporterContextProvider";
|
|
14
|
+
import { fuseImporterId } from "../../../../common";
|
|
15
|
+
import { createContext, useContext, useEffect, } from "react";
|
|
16
|
+
import { useUndoRedoContext } from "../UndoRedoContextProvider";
|
|
17
|
+
import { useSearchContext } from "../SearchContextProvider";
|
|
18
|
+
export var KeyboardEventContext = createContext({});
|
|
19
|
+
export var KeyboardEventContextProvider = function (_a) {
|
|
20
|
+
var children = _a.children;
|
|
21
|
+
var layoutRef = useImporterContext().layoutRef;
|
|
22
|
+
var _b = useUndoRedoContext(), undo = _b.undo, redo = _b.redo;
|
|
23
|
+
var setFindAndReplaceModalOpen = useSearchContext().setFindAndReplaceModalOpen;
|
|
24
|
+
var openSearchInput = useSearchContext().openSearchInput;
|
|
25
|
+
var onKeyDown = function (e) {
|
|
26
|
+
// cmd+y
|
|
27
|
+
if (e.keyCode === 89 && (e.ctrlKey || e.metaKey)) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
redo();
|
|
30
|
+
}
|
|
31
|
+
// cmd+shift+z
|
|
32
|
+
if (e.keyCode === 90 && (e.ctrlKey || e.metaKey) && e.shiftKey) {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
redo();
|
|
35
|
+
}
|
|
36
|
+
// cmd+z
|
|
37
|
+
if (e.keyCode === 90 && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
undo();
|
|
40
|
+
}
|
|
41
|
+
// cmd+f
|
|
42
|
+
if ((e.ctrlKey || e.metaKey) && !e.shiftKey && e.keyCode === 70) {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
openSearchInput();
|
|
45
|
+
}
|
|
46
|
+
// cmd+shift+f
|
|
47
|
+
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.keyCode === 70) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
setFindAndReplaceModalOpen(true);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
useEffect(function () {
|
|
53
|
+
var iframeElement = document.getElementById(fuseImporterId);
|
|
54
|
+
if (iframeElement.contentDocument) {
|
|
55
|
+
iframeElement.contentDocument.body.addEventListener("keydown", onKeyDown);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// this is used in testing
|
|
59
|
+
layoutRef.current.addEventListener("keydown", onKeyDown);
|
|
60
|
+
}
|
|
61
|
+
return function () {
|
|
62
|
+
if (iframeElement.contentDocument) {
|
|
63
|
+
iframeElement.contentDocument.body.removeEventListener("keydown", onKeyDown);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
layoutRef.current.removeEventListener("keydown", onKeyDown);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, [layoutRef.current]);
|
|
70
|
+
var value = {};
|
|
71
|
+
return (_jsx(KeyboardEventContext.Provider, __assign({ value: value }, { children: children })));
|
|
72
|
+
};
|
|
73
|
+
export var useDataSetContext = function () { return useContext(KeyboardEventContext); };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type State = {
|
|
3
|
+
findAndReplaceModalOpen: boolean;
|
|
4
|
+
setFindAndReplaceModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
|
+
openSearchInput: () => void;
|
|
8
|
+
closeSearchInput: () => void;
|
|
9
|
+
searchInputRef: React.MutableRefObject<HTMLInputElement>;
|
|
10
|
+
};
|
|
11
|
+
export declare const SearchContext: React.Context<State>;
|
|
12
|
+
export declare const SearchContextProvider: ({ children }: {
|
|
13
|
+
children: any;
|
|
14
|
+
}) => JSX.Element;
|
|
15
|
+
export declare const useSearchContext: () => State;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useRef, useState } from "react";
|
|
14
|
+
export var SearchContext = createContext({});
|
|
15
|
+
export var SearchContextProvider = function (_a) {
|
|
16
|
+
var children = _a.children;
|
|
17
|
+
var _b = useState(false), findAndReplaceModalOpen = _b[0], setFindAndReplaceModalOpen = _b[1];
|
|
18
|
+
var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
19
|
+
var searchInputRef = useRef(null);
|
|
20
|
+
var openSearchInput = function () {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!isOpen) {
|
|
23
|
+
setIsOpen(true);
|
|
24
|
+
if (searchInputRef === null || searchInputRef === void 0 ? void 0 : searchInputRef.current) {
|
|
25
|
+
(_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var closeSearchInput = function () {
|
|
30
|
+
setIsOpen(false);
|
|
31
|
+
};
|
|
32
|
+
var value = {
|
|
33
|
+
findAndReplaceModalOpen: findAndReplaceModalOpen,
|
|
34
|
+
setFindAndReplaceModalOpen: setFindAndReplaceModalOpen,
|
|
35
|
+
isOpen: isOpen,
|
|
36
|
+
setIsOpen: setIsOpen,
|
|
37
|
+
openSearchInput: openSearchInput,
|
|
38
|
+
searchInputRef: searchInputRef,
|
|
39
|
+
closeSearchInput: closeSearchInput,
|
|
40
|
+
};
|
|
41
|
+
return (_jsx(SearchContext.Provider, __assign({ value: value }, { children: children })));
|
|
42
|
+
};
|
|
43
|
+
export var useSearchContext = function () { return useContext(SearchContext); };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Field, RecordDataSet } from "../../../../types";
|
|
1
2
|
export declare const RecordHashCalculator: () => {
|
|
2
|
-
computeHashesForRecords: (dataSet:
|
|
3
|
+
computeHashesForRecords: (dataSet: RecordDataSet, fields: Field[], _onHashesComputed: (x: any) => void) => Promise<void>;
|
|
3
4
|
};
|
|
4
5
|
export declare const RecordValueHashCalculator: () => {
|
|
5
|
-
computeDuplicateValueHashes: (dataSet:
|
|
6
|
+
computeDuplicateValueHashes: (dataSet: RecordDataSet, _field: Field, _onDuplicateHashesComputed: (x: any[]) => void) => Promise<void>;
|
|
6
7
|
};
|
|
@@ -74,21 +74,30 @@ export var RecordHashCalculator = function () {
|
|
|
74
74
|
return hashMap;
|
|
75
75
|
};
|
|
76
76
|
var calculatingHashes = false;
|
|
77
|
-
var computeHashesForRecords = function (dataSet, fields, _onHashesComputed) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
var computeHashesForRecords = function (dataSet, fields, _onHashesComputed) { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
+
var processInBatches, results, duplicateHashes;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (!dataSet || calculatingHashes) {
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
processInBatches = useBatchProcessing().processInBatches;
|
|
86
|
+
calculatingHashes = true;
|
|
87
|
+
results = [];
|
|
88
|
+
return [4 /*yield*/, processInBatches(dataSet, function (batch) {
|
|
89
|
+
results = results.concat(computeHashesForBatch(batch, fields));
|
|
90
|
+
})];
|
|
91
|
+
case 1:
|
|
92
|
+
_a.sent();
|
|
93
|
+
results.sort(compareHashes);
|
|
94
|
+
duplicateHashes = findDuplicateHashes(results);
|
|
95
|
+
_onHashesComputed(duplicateHashes);
|
|
96
|
+
calculatingHashes = false;
|
|
97
|
+
return [2 /*return*/];
|
|
98
|
+
}
|
|
86
99
|
});
|
|
87
|
-
|
|
88
|
-
var duplicateHashes = findDuplicateHashes(results);
|
|
89
|
-
_onHashesComputed(duplicateHashes);
|
|
90
|
-
calculatingHashes = false;
|
|
91
|
-
};
|
|
100
|
+
}); };
|
|
92
101
|
return {
|
|
93
102
|
computeHashesForRecords: computeHashesForRecords,
|
|
94
103
|
};
|
|
@@ -117,19 +126,24 @@ export var RecordValueHashCalculator = function () {
|
|
|
117
126
|
var computeDuplicateValueHashes = function (dataSet, _field, _onDuplicateHashesComputed) { return __awaiter(void 0, void 0, void 0, function () {
|
|
118
127
|
var processInBatches, results;
|
|
119
128
|
return __generator(this, function (_a) {
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
if (!dataSet || columnsBeingCalculated[_field.name]) {
|
|
132
|
+
return [2 /*return*/];
|
|
133
|
+
}
|
|
134
|
+
columnsBeingCalculated[_field.name] = true;
|
|
135
|
+
processInBatches = useBatchProcessing().processInBatches;
|
|
136
|
+
results = [];
|
|
137
|
+
return [4 /*yield*/, processInBatches(dataSet, function (batch) {
|
|
138
|
+
results = results.concat(computeHashesForBatch(batch, _field));
|
|
139
|
+
})];
|
|
140
|
+
case 1:
|
|
141
|
+
_a.sent();
|
|
142
|
+
results.sort(compareHashes);
|
|
143
|
+
_onDuplicateHashesComputed(results);
|
|
144
|
+
columnsBeingCalculated[_field.name] = false;
|
|
145
|
+
return [2 /*return*/];
|
|
122
146
|
}
|
|
123
|
-
columnsBeingCalculated[_field.name] = true;
|
|
124
|
-
processInBatches = useBatchProcessing().processInBatches;
|
|
125
|
-
results = [];
|
|
126
|
-
processInBatches(dataSet, function (batch) {
|
|
127
|
-
results = results.concat(computeHashesForBatch(batch, _field));
|
|
128
|
-
});
|
|
129
|
-
results.sort(compareHashes);
|
|
130
|
-
_onDuplicateHashesComputed(results);
|
|
131
|
-
columnsBeingCalculated[_field.name] = false;
|
|
132
|
-
return [2 /*return*/];
|
|
133
147
|
});
|
|
134
148
|
}); };
|
|
135
149
|
return {
|
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { SpreadsheetOptions } from "../../../..";
|
|
3
3
|
import { Field, RecordDataSet } from "../../../../types";
|
|
4
4
|
import { SpreadsheetProps } from "../common/types";
|
|
5
|
+
import { CellSelectionState } from "./useCellSelection";
|
|
5
6
|
export type OnDataSetChanged = (dataSet: RecordDataSet) => void;
|
|
6
7
|
type State = {
|
|
7
8
|
filteredDataIds: string[];
|
|
@@ -14,7 +15,7 @@ type State = {
|
|
|
14
15
|
checkboxColumnWidth: number;
|
|
15
16
|
inefficientRerender: boolean;
|
|
16
17
|
setInefficientRerender: React.Dispatch<React.SetStateAction<boolean>>;
|
|
17
|
-
};
|
|
18
|
+
} & CellSelectionState;
|
|
18
19
|
type Props = SpreadsheetProps & {
|
|
19
20
|
children: JSX.Element;
|
|
20
21
|
};
|
|
@@ -24,6 +24,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
24
24
|
import { createContext, useContext, useMemo, useRef, useState, } from "react";
|
|
25
25
|
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
26
26
|
import { useValidationContext } from "../ValidationContextProvider";
|
|
27
|
+
import { useCellSelection } from "./useCellSelection";
|
|
27
28
|
var SpreadsheetContext = createContext({});
|
|
28
29
|
export var SpreadsheetContextProvider = function (_a) {
|
|
29
30
|
var fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, children = _a.children, onValidateRecord = _a.onValidateRecord, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows;
|
|
@@ -38,7 +39,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
38
39
|
var baseCheckboxColumnWidth = lastRowIndexLength * singleLetterWidth + horizontalSpacing;
|
|
39
40
|
return baseCheckboxColumnWidth < 40 ? 40 : baseCheckboxColumnWidth;
|
|
40
41
|
}, [filteredDataIds.length]);
|
|
41
|
-
var value = __assign(__assign({ filteredDataIds: filteredDataIds, fields: fields }, validationState), { isReadOnly: isReadOnly, options: options, onValidateRecord: onValidateRecord, selectedRows: selectedRows, setSelectedRows: setSelectedRows, lastClickedIndexRef: lastClickedIndexRef, checkboxColumnWidth: checkboxColumnWidth, inefficientRerender: inefficientRerender, setInefficientRerender: setInefficientRerender });
|
|
42
|
+
var value = __assign(__assign(__assign({ filteredDataIds: filteredDataIds, fields: fields }, validationState), { isReadOnly: isReadOnly, options: options, onValidateRecord: onValidateRecord, selectedRows: selectedRows, setSelectedRows: setSelectedRows, lastClickedIndexRef: lastClickedIndexRef, checkboxColumnWidth: checkboxColumnWidth, inefficientRerender: inefficientRerender, setInefficientRerender: setInefficientRerender }), useCellSelection(fields));
|
|
42
43
|
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
43
44
|
};
|
|
44
45
|
export var useSpreadsheetContext = function () { return useContext(SpreadsheetContext); };
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Record, RecordDataSet } from "../../../../types";
|
|
2
2
|
export declare const useBatchProcessing: (batchPageSize?: number) => {
|
|
3
|
-
processRecordsInBatches: (records: Record[], handleBatch: any) => Promise<void>;
|
|
4
|
-
processInBatches: (dataSet: RecordDataSet, handleBatch: any) => void
|
|
3
|
+
processRecordsInBatches: (records: Record[], handleBatch: (x: any) => void) => Promise<void>;
|
|
4
|
+
processInBatches: (dataSet: RecordDataSet, handleBatch: (x: any) => void) => Promise<void>;
|
|
5
5
|
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js
CHANGED
|
@@ -61,10 +61,19 @@ export var useBatchProcessing = function (batchPageSize) {
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
}); };
|
|
64
|
-
var processInBatches = function (dataSet, handleBatch) {
|
|
65
|
-
var records
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
var processInBatches = function (dataSet, handleBatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
+
var records;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
records = Object.values(dataSet);
|
|
70
|
+
return [4 /*yield*/, processRecordsInBatches(records, handleBatch)];
|
|
71
|
+
case 1:
|
|
72
|
+
_a.sent();
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}); };
|
|
68
77
|
return {
|
|
69
78
|
processRecordsInBatches: processRecordsInBatches,
|
|
70
79
|
processInBatches: processInBatches,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Field } from "../../../../types";
|
|
3
|
+
export type SelectedCellRect = {
|
|
4
|
+
start: {
|
|
5
|
+
rowIndex: number;
|
|
6
|
+
colIndex: number;
|
|
7
|
+
};
|
|
8
|
+
end: {
|
|
9
|
+
rowIndex: number;
|
|
10
|
+
colIndex: number;
|
|
11
|
+
};
|
|
12
|
+
initialCell: {
|
|
13
|
+
rowIndex: number;
|
|
14
|
+
colIndex: number;
|
|
15
|
+
};
|
|
16
|
+
isDashed?: boolean;
|
|
17
|
+
editMode?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const defaultSelectionRect: SelectedCellRect;
|
|
20
|
+
export type CellSelectionState = {
|
|
21
|
+
selectedCellRect: SelectedCellRect;
|
|
22
|
+
setSelectedCellRect: React.Dispatch<React.SetStateAction<SelectedCellRect>>;
|
|
23
|
+
};
|
|
24
|
+
export declare const useCellSelection: (fields?: Field[]) => CellSelectionState;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { useEffect, useState } from "react";
|
|
49
|
+
import { fuseImporterId } from "../../../../common";
|
|
50
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
51
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
52
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
53
|
+
import { useImporterContext } from "../../../contexts/ImporterContextProvider";
|
|
54
|
+
import { useDataSetManipulation } from "./useDataSetManipulation";
|
|
55
|
+
import { parseValue } from "../common";
|
|
56
|
+
import { useSpreadsheetContext } from ".";
|
|
57
|
+
export var defaultSelectionRect = {
|
|
58
|
+
start: { rowIndex: 0, colIndex: 0 },
|
|
59
|
+
end: { rowIndex: 0, colIndex: 0 },
|
|
60
|
+
initialCell: { rowIndex: 0, colIndex: 0 },
|
|
61
|
+
};
|
|
62
|
+
var getIframeBody = function (layoutRef) {
|
|
63
|
+
var iframeElement = document.getElementById(fuseImporterId);
|
|
64
|
+
var isCypressTestingEnv = !iframeElement.contentDocument;
|
|
65
|
+
if (isCypressTestingEnv)
|
|
66
|
+
return layoutRef.current;
|
|
67
|
+
return iframeElement.contentDocument.body;
|
|
68
|
+
};
|
|
69
|
+
export var useCellSelection = function (fields) {
|
|
70
|
+
var getRecord = useDataSetContext().getRecord;
|
|
71
|
+
var _a = useFilteredDataContext(), filteredDataIds = _a.filteredDataIds, isSortingOrFiltering = _a.isSortingOrFiltering;
|
|
72
|
+
var updateRecordAndRevalidate = useValidationContext().updateRecordAndRevalidate;
|
|
73
|
+
var layoutRef = useImporterContext().layoutRef;
|
|
74
|
+
var _b = useState(defaultSelectionRect), selectedCellRect = _b[0], setSelectedCellRect = _b[1];
|
|
75
|
+
var enumFieldValueMatchings = useImporterContext().enumFieldValueMatchings;
|
|
76
|
+
var isReadOnly = useSpreadsheetContext().isReadOnly;
|
|
77
|
+
var _c = useDataSetManipulation(), insertRecordsIntoSpreadsheet = _c.insertRecordsIntoSpreadsheet, addNewRecord = _c.addNewRecord;
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
var iframeBody = getIframeBody(layoutRef);
|
|
80
|
+
iframeBody.addEventListener("paste", onPaste, true);
|
|
81
|
+
return function () {
|
|
82
|
+
iframeBody.removeEventListener("paste", onPaste, true);
|
|
83
|
+
};
|
|
84
|
+
}, [
|
|
85
|
+
selectedCellRect,
|
|
86
|
+
filteredDataIds,
|
|
87
|
+
isSortingOrFiltering,
|
|
88
|
+
enumFieldValueMatchings,
|
|
89
|
+
insertRecordsIntoSpreadsheet,
|
|
90
|
+
updateRecordAndRevalidate,
|
|
91
|
+
fields,
|
|
92
|
+
]);
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
var handleCopy = function () { return handleCopyCutOperation(false); };
|
|
95
|
+
var handleCut = function () { return handleCopyCutOperation(true); };
|
|
96
|
+
var iframeBody = getIframeBody(layoutRef);
|
|
97
|
+
iframeBody.addEventListener("copy", handleCopy);
|
|
98
|
+
iframeBody.addEventListener("cut", handleCut);
|
|
99
|
+
return function () {
|
|
100
|
+
iframeBody.removeEventListener("copy", handleCopy);
|
|
101
|
+
iframeBody.removeEventListener("cut", handleCut);
|
|
102
|
+
};
|
|
103
|
+
}, [selectedCellRect]);
|
|
104
|
+
var onPaste = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
+
var text, rows, maxCells, structuredData, startRowIndex, startColIndex, pastedRecordIds, newRecordId, pastedRecordValues;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
if (isReadOnly)
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
text = event.clipboardData.getData("text");
|
|
112
|
+
if (!text.includes("\t") && !text.includes("\n")) {
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
rows = text.split(/\r\n|\n|\r/);
|
|
116
|
+
maxCells = rows.reduce(function (max, row) { return Math.max(max, row.split("\t").length); }, 0);
|
|
117
|
+
structuredData = rows.map(function (row) {
|
|
118
|
+
var cells = row.split("\t");
|
|
119
|
+
while (cells.length < maxCells) {
|
|
120
|
+
cells.push("");
|
|
121
|
+
}
|
|
122
|
+
return cells;
|
|
123
|
+
});
|
|
124
|
+
startRowIndex = selectedCellRect.start.rowIndex;
|
|
125
|
+
startColIndex = selectedCellRect.start.colIndex;
|
|
126
|
+
pastedRecordIds = filteredDataIds.slice(startRowIndex, startRowIndex + structuredData.length);
|
|
127
|
+
if (!isSortingOrFiltering) {
|
|
128
|
+
while (pastedRecordIds.length < structuredData.length) {
|
|
129
|
+
newRecordId = addNewRecord();
|
|
130
|
+
pastedRecordIds.push(newRecordId);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
pastedRecordValues = pastedRecordIds.map(function (id) { return (__assign({}, getRecord(id))); });
|
|
134
|
+
structuredData.forEach(function (row, startRowIndex) {
|
|
135
|
+
row.forEach(function (value, colIndex) {
|
|
136
|
+
var field = fields[startColIndex + colIndex];
|
|
137
|
+
if (!field)
|
|
138
|
+
return;
|
|
139
|
+
var pastedRecordValue = pastedRecordValues[startRowIndex];
|
|
140
|
+
if (pastedRecordValue) {
|
|
141
|
+
var enumSet = Object.keys(enumFieldValueMatchings).length > 0
|
|
142
|
+
? enumFieldValueMatchings[field.label]
|
|
143
|
+
: field.options.reduce(function (acc, option) {
|
|
144
|
+
acc[option] = option;
|
|
145
|
+
return acc;
|
|
146
|
+
}, {});
|
|
147
|
+
pastedRecordValue[field.name] = parseValue(field.type, value, enumSet);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
if (!!isSortingOrFiltering) return [3 /*break*/, 2];
|
|
152
|
+
return [4 /*yield*/, insertRecordsIntoSpreadsheet(pastedRecordValues)];
|
|
153
|
+
case 1:
|
|
154
|
+
_a.sent();
|
|
155
|
+
return [3 /*break*/, 4];
|
|
156
|
+
case 2: return [4 /*yield*/, updateRecordAndRevalidate(pastedRecordValues)];
|
|
157
|
+
case 3:
|
|
158
|
+
_a.sent();
|
|
159
|
+
_a.label = 4;
|
|
160
|
+
case 4:
|
|
161
|
+
setSelectedCellRect({
|
|
162
|
+
start: { rowIndex: startRowIndex, colIndex: startColIndex },
|
|
163
|
+
end: {
|
|
164
|
+
rowIndex: startRowIndex + structuredData.length - 1,
|
|
165
|
+
colIndex: startColIndex + maxCells - 1,
|
|
166
|
+
},
|
|
167
|
+
initialCell: { rowIndex: startRowIndex, colIndex: startColIndex },
|
|
168
|
+
});
|
|
169
|
+
return [2 /*return*/];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}); };
|
|
173
|
+
var handleCopyCutOperation = function (isCut) {
|
|
174
|
+
var start = selectedCellRect.start, end = selectedCellRect.end;
|
|
175
|
+
var selectedCellsCount = (end.rowIndex - start.rowIndex + 1) * (end.colIndex - start.colIndex + 1);
|
|
176
|
+
if (selectedCellsCount <= 1)
|
|
177
|
+
return;
|
|
178
|
+
var updatedRecords = [];
|
|
179
|
+
var data = [];
|
|
180
|
+
for (var i = start.rowIndex; i <= end.rowIndex; i++) {
|
|
181
|
+
var rowData = [];
|
|
182
|
+
for (var j = start.colIndex; j <= end.colIndex; j++) {
|
|
183
|
+
var recordId = filteredDataIds[i];
|
|
184
|
+
var record = getRecord(recordId);
|
|
185
|
+
var cellData = record[fields[j].name];
|
|
186
|
+
rowData.push(cellData);
|
|
187
|
+
if (isCut) {
|
|
188
|
+
record[fields[j].name] = "";
|
|
189
|
+
updatedRecords.push(record);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
data.push(rowData);
|
|
193
|
+
}
|
|
194
|
+
if (isCut)
|
|
195
|
+
updateRecordAndRevalidate(updatedRecords);
|
|
196
|
+
var clipboardText = data.map(function (row) { return row.join("\t"); }).join("\n");
|
|
197
|
+
navigator.clipboard.writeText(clipboardText);
|
|
198
|
+
setSelectedCellRect(__assign(__assign({}, selectedCellRect), { isDashed: true }));
|
|
199
|
+
};
|
|
200
|
+
useEffect(function () {
|
|
201
|
+
setSelectedCellRect(defaultSelectionRect);
|
|
202
|
+
}, [filteredDataIds]);
|
|
203
|
+
return {
|
|
204
|
+
selectedCellRect: selectedCellRect,
|
|
205
|
+
setSelectedCellRect: setSelectedCellRect,
|
|
206
|
+
};
|
|
207
|
+
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { Record } from "../../../../types";
|
|
1
2
|
export declare const useDataSetManipulation: () => {
|
|
3
|
+
addNewRecord: () => string;
|
|
4
|
+
insertRecordsIntoSpreadsheet: (records: Record[]) => Promise<void>;
|
|
2
5
|
appendNewRecordToSpreadsheet: () => void;
|
|
3
6
|
deleteRecordsFromSpreadsheet: (recordIds: string[]) => void;
|
|
4
|
-
findAndReplaceInSpreadsheet: (searchText: string, replaceText: string, matchCase: boolean, useRegex: boolean) => any[]
|
|
7
|
+
findAndReplaceInSpreadsheet: (searchText: string, replaceText: string, matchCase: boolean, useRegex: boolean) => Promise<any[]>;
|
|
5
8
|
};
|