@vuu-ui/vuu-table-extras 5.0.0-alpha.3 → 5.0.0-alpha.4

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.0.0-alpha.3",
2
+ "version": "5.0.0-alpha.4",
3
3
  "author": "heswell",
4
4
  "main": "./src/index.js",
5
5
  "license": "Apache-2.0",
@@ -11,25 +11,25 @@
11
11
  "lezer-generate:column": "lezer-generator --output ./src/column-expression-input/column-language-parser/generated/column-parser.ts ./src/column-expression-input/column-language-parser/grammar/column.grammar"
12
12
  },
13
13
  "devDependencies": {
14
- "@vuu-ui/vuu-filter-types": "5.0.0-alpha.3",
15
- "@vuu-ui/vuu-protocol-types": "5.0.0-alpha.3"
14
+ "@vuu-ui/vuu-filter-types": "5.0.0-alpha.4",
15
+ "@vuu-ui/vuu-protocol-types": "5.0.0-alpha.4"
16
16
  },
17
17
  "dependencies": {
18
- "@vuu-ui/vuu-codemirror": "5.0.0-alpha.3",
19
- "@vuu-ui/vuu-data-editing": "5.0.0-alpha.3",
20
- "@vuu-ui/vuu-data-react": "5.0.0-alpha.3",
21
- "@vuu-ui/vuu-data-types": "5.0.0-alpha.3",
22
- "@vuu-ui/vuu-table-types": "5.0.0-alpha.3",
23
- "@vuu-ui/vuu-popups": "5.0.0-alpha.3",
24
- "@vuu-ui/vuu-table": "5.0.0-alpha.3",
25
- "@vuu-ui/vuu-utils": "5.0.0-alpha.3",
26
- "@vuu-ui/vuu-ui-controls": "5.0.0-alpha.3",
18
+ "@vuu-ui/vuu-codemirror": "5.0.0-alpha.4",
19
+ "@vuu-ui/vuu-data-editing": "5.0.0-alpha.4",
20
+ "@vuu-ui/vuu-data-react": "5.0.0-alpha.4",
21
+ "@vuu-ui/vuu-data-types": "5.0.0-alpha.4",
22
+ "@vuu-ui/vuu-table-types": "5.0.0-alpha.4",
23
+ "@vuu-ui/vuu-popups": "5.0.0-alpha.4",
24
+ "@vuu-ui/vuu-table": "5.0.0-alpha.4",
25
+ "@vuu-ui/vuu-utils": "5.0.0-alpha.4",
26
+ "@vuu-ui/vuu-ui-controls": "5.0.0-alpha.4",
27
27
  "@lezer/lr": "1.4.2",
28
28
  "@salt-ds/core": "1.74.0",
29
29
  "@salt-ds/styles": "0.4.2",
30
30
  "@salt-ds/window": "0.1.2",
31
31
  "csv-parse": "^7.0.0",
32
- "@vuu-ui/core": "5.0.0-alpha.3"
32
+ "@vuu-ui/core": "5.0.0-alpha.4"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@floating-ui/react": "^0.27.19",
@@ -47,8 +47,8 @@ const parseCsv = (csvText, options)=>{
47
47
  relax_column_count: true,
48
48
  skip_empty_lines: true
49
49
  });
50
- } catch (err) {
51
- addCsvFileError(errorState, "*", CsvParseErrorEnum.INVALID_FORMAT, err instanceof Error ? err.message : "Invalid CSV format.");
50
+ } catch {
51
+ addCsvFileError(errorState, "*", CsvParseErrorEnum.INVALID_FORMAT, "Invalid CSV format.");
52
52
  return withError("Invalid CSV format.", errorState.errorMap, errorState.errors);
53
53
  }
54
54
  if (0 === records.length) {
@@ -75,6 +75,10 @@ const parseCsv = (csvText, options)=>{
75
75
  addCsvFileError(errorState, duplicateHeader, CsvParseErrorEnum.DUPLICATE_HEADER_COLUMN, `CSV header contains duplicate column '${duplicateHeader}'.`, duplicateHeader);
76
76
  return withError(`CSV header contains duplicate column '${duplicateHeader}'.`, errorState.errorMap, errorState.errors, header, []);
77
77
  }
78
+ if (0 === rows.length) {
79
+ addCsvFileError(errorState, "*", CsvParseErrorEnum.EMPTY_FILE, "CSV file is empty.");
80
+ return withError("CSV file is empty.", errorState.errorMap, errorState.errors, header, []);
81
+ }
78
82
  const firstDataRowNumber = options?.customHeaders && false === options.hasHeaderRow ? 1 : CSV_FIRST_DATA_ROW_NUMBER;
79
83
  rows.forEach((row, rowIndex)=>{
80
84
  if (row.length !== header.length) addCsvRowError(errorState, rowIndex + firstDataRowNumber, "*", CsvParseErrorEnum.ROW_COLUMN_COUNT_MISMATCH, "This row has too many or too few columns compared to the header line. Check for extra or missing commas.", row.join(","));
@@ -5,6 +5,14 @@ import { CsvValidationErrorEnum, validateCsvAgainstSchema } from "./parse/csv-sc
5
5
  import { createUploadError, hasFileParseErrors, isCsvParseError, mapCsvHeaders, mergeValidationWithParseErrors, toErrorMessage } from "./parse/csv-upload-utils.js";
6
6
  import { useImportSchema } from "./session/useImportSchema.js";
7
7
  import { useImportSession } from "./session/useImportSession.js";
8
+ const CSV_MIME_TYPES = new Set([
9
+ "",
10
+ "text/csv",
11
+ "text/plain",
12
+ "application/csv",
13
+ "application/vnd.ms-excel"
14
+ ]);
15
+ const isCsvFile = (file)=>file.name.toLowerCase().endsWith(".csv") && CSV_MIME_TYPES.has(file.type.toLowerCase());
8
16
  const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importTable, onImportSessionEnded, onImportSessionReady, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, customHeaders, hasHeaderRow, headerMapping, rowDefaults, validators })=>{
9
17
  const [validation, setValidation] = useState();
10
18
  const [isProcessingFile, setIsProcessingFile] = useState(false);
@@ -58,6 +66,15 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
58
66
  }
59
67
  if (void 0 === schema) throw Error("Table schema is not yet available.");
60
68
  if (void 0 === table) throw Error("CsvUpload requires dataSource.table to be defined.");
69
+ if (!isCsvFile(file)) {
70
+ const errorMessage = "Invalid file type. Only .csv files are supported.";
71
+ handleError({
72
+ errors: {
73
+ validationError: createUploadError("validation", errorMessage)
74
+ }
75
+ });
76
+ return;
77
+ }
61
78
  const effectiveParseOptions = {
62
79
  ...parseOptions,
63
80
  ...void 0 !== customHeaders ? {
@@ -66,14 +66,6 @@ const useInlineAddRow = ({ columns })=>{
66
66
  newRowState.values,
67
67
  visibleInsertColumns
68
68
  ]);
69
- useEffect(()=>{
70
- const firstInvalidIndex = visibleColumns.findIndex(({ name })=>void 0 !== newRowState.errors[name]);
71
- if (-1 !== firstInvalidIndex) focusEditor(firstInvalidIndex);
72
- }, [
73
- focusEditor,
74
- newRowState.errors,
75
- visibleColumns
76
- ]);
77
69
  useEffect(()=>{
78
70
  const previousValues = previousValuesRef.current;
79
71
  previousValuesRef.current = newRowState.values;