@cosmotech/core 1.7.2 → 1.8.0
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/CHANGELOG.md +6 -0
- package/dist/index.cjs.js +41 -15
- package/dist/index.esm.js +41 -15
- package/package.json +1 -1
- package/dist/bundle.min.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## **1.8.0** <sub><sup>2022-05-09 (5d61a0e...5317d94)</sup></sub>
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
* support empty fields in table component ([5d61a0e](https://github.com/Cosmo-Tech/webapp-component-core/commit/5d61a0e))
|
|
5
|
+
|
|
6
|
+
|
|
1
7
|
## **1.7.2** <sub><sup>2022-04-29</sup></sub>
|
|
2
8
|
|
|
3
9
|
- update dependencies
|
package/dist/index.cjs.js
CHANGED
|
@@ -20042,7 +20042,7 @@ var _castCellValueToStr = cellValue => {
|
|
|
20042
20042
|
};
|
|
20043
20043
|
|
|
20044
20044
|
var read = /*#__PURE__*/function () {
|
|
20045
|
-
var _ref = _asyncToGenerator(function* (fileBlob, forceStr) {
|
|
20045
|
+
var _ref = _asyncToGenerator(function* (fileBlob, forceStr, emptyCols) {
|
|
20046
20046
|
var data;
|
|
20047
20047
|
|
|
20048
20048
|
try {
|
|
@@ -20050,7 +20050,10 @@ var read = /*#__PURE__*/function () {
|
|
|
20050
20050
|
var workbook = readSync(buffer);
|
|
20051
20051
|
var worksheetName = workbook.SheetNames[0];
|
|
20052
20052
|
var worksheet = workbook.Sheets[worksheetName];
|
|
20053
|
-
data = utils.sheet_to_json(worksheet, {
|
|
20053
|
+
data = utils.sheet_to_json(worksheet, emptyCols ? {
|
|
20054
|
+
header: 1,
|
|
20055
|
+
defval: ''
|
|
20056
|
+
} : {
|
|
20054
20057
|
header: 1
|
|
20055
20058
|
});
|
|
20056
20059
|
} catch (err) {
|
|
@@ -20066,7 +20069,7 @@ var read = /*#__PURE__*/function () {
|
|
|
20066
20069
|
return data;
|
|
20067
20070
|
});
|
|
20068
20071
|
|
|
20069
|
-
return function read(_x, _x2) {
|
|
20072
|
+
return function read(_x, _x2, _x3) {
|
|
20070
20073
|
return _ref.apply(this, arguments);
|
|
20071
20074
|
};
|
|
20072
20075
|
}();
|
|
@@ -31952,7 +31955,13 @@ var isString = data => {
|
|
|
31952
31955
|
return typeof data === 'string';
|
|
31953
31956
|
};
|
|
31954
31957
|
|
|
31955
|
-
var isValid = (dataStr, type, options)
|
|
31958
|
+
var isValid = function isValid(dataStr, type, options) {
|
|
31959
|
+
var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
31960
|
+
|
|
31961
|
+
if (canBeEmpty && dataStr === '') {
|
|
31962
|
+
return true;
|
|
31963
|
+
}
|
|
31964
|
+
|
|
31956
31965
|
switch (type) {
|
|
31957
31966
|
case 'bool':
|
|
31958
31967
|
return isBool(dataStr);
|
|
@@ -32013,9 +32022,9 @@ class Error$1 {
|
|
|
32013
32022
|
}
|
|
32014
32023
|
|
|
32015
32024
|
var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row) => {
|
|
32016
|
-
var errorSummary = "Missing
|
|
32025
|
+
var errorSummary = "Missing field".concat(missingColsCount > 1 ? 's' : '');
|
|
32017
32026
|
var errorLoc = "Line ".concat(rowIndex);
|
|
32018
|
-
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, "
|
|
32027
|
+
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, " fields expected, ") + "but only ".concat(colsCount, " field").concat(colsCount > 1 ? 's' : '', " found\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
|
|
32019
32028
|
return new Error$1(errorSummary, errorLoc, errorContext);
|
|
32020
32029
|
};
|
|
32021
32030
|
|
|
@@ -32039,7 +32048,7 @@ var DEFAULT_CSV_EXPORT_OPTIONS = {
|
|
|
32039
32048
|
};
|
|
32040
32049
|
|
|
32041
32050
|
var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
|
|
32042
|
-
var colsCount = row.length;
|
|
32051
|
+
var colsCount = Object.values(row).filter(el => el !== undefined).length;
|
|
32043
32052
|
var expectedColsCount = expectedCols.length;
|
|
32044
32053
|
var expectedColsName = expectedCols.map(col => col.field).join();
|
|
32045
32054
|
var missingColsCount = expectedColsCount - colsCount;
|
|
@@ -32085,7 +32094,7 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32085
32094
|
var _loop = function _loop(rowIndex) {
|
|
32086
32095
|
var row = rows[rowIndex];
|
|
32087
32096
|
|
|
32088
|
-
if (row.length < knownColsCount) {
|
|
32097
|
+
if (row.length < knownColsCount || row.includes(undefined)) {
|
|
32089
32098
|
errors.push(_forgeColumnsCountError(rows[rowIndex], rowIndex, colsData));
|
|
32090
32099
|
}
|
|
32091
32100
|
|
|
@@ -32093,8 +32102,8 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32093
32102
|
if (colIndex < knownColsCount) {
|
|
32094
32103
|
var colType = colsData[colIndex].type;
|
|
32095
32104
|
|
|
32096
|
-
if (colType) {
|
|
32097
|
-
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c;
|
|
32105
|
+
if (colType && rowCell !== undefined) {
|
|
32106
|
+
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c, _colsData$colIndex$ce, _colsData$colIndex$ce2;
|
|
32098
32107
|
|
|
32099
32108
|
var enumValues = ((_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) || ((_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 ? void 0 : (_colsData$colIndex2$c = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2$c === void 0 ? void 0 : _colsData$colIndex2$c.enumValues);
|
|
32100
32109
|
|
|
@@ -32102,7 +32111,9 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32102
32111
|
enumValues: enumValues
|
|
32103
32112
|
});
|
|
32104
32113
|
|
|
32105
|
-
|
|
32114
|
+
var acceptsEmptyFields = (_colsData$colIndex$ce = (_colsData$colIndex$ce2 = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce2 === void 0 ? void 0 : _colsData$colIndex$ce2.acceptsEmptyFields) !== null && _colsData$colIndex$ce !== void 0 ? _colsData$colIndex$ce : false;
|
|
32115
|
+
|
|
32116
|
+
if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
|
|
32106
32117
|
errors.push(_forgeTypeError(rowCell, rowIndex, colType, colOptions, colsData, colIndex));
|
|
32107
32118
|
}
|
|
32108
32119
|
}
|
|
@@ -32125,8 +32136,6 @@ var _reformatBoolValue = csvCellValue => {
|
|
|
32125
32136
|
} else if (['1', 'true', 'yes'].includes(csvCellValue)) {
|
|
32126
32137
|
return 'true';
|
|
32127
32138
|
}
|
|
32128
|
-
|
|
32129
|
-
return null;
|
|
32130
32139
|
};
|
|
32131
32140
|
|
|
32132
32141
|
var _reformatValue = (csvCellValue, colTypes) => {
|
|
@@ -32141,6 +32150,18 @@ var _buildCols = header => header.map(col => ({
|
|
|
32141
32150
|
field: col
|
|
32142
32151
|
}));
|
|
32143
32152
|
|
|
32153
|
+
var _calculateEmptyCols = cols => {
|
|
32154
|
+
return cols.map((_, index) => index).filter(colIndex => {
|
|
32155
|
+
var _cols$colIndex$cellEd;
|
|
32156
|
+
|
|
32157
|
+
return (_cols$colIndex$cellEd = cols[colIndex].cellEditorParams) === null || _cols$colIndex$cellEd === void 0 ? void 0 : _cols$colIndex$cellEd.acceptsEmptyFields;
|
|
32158
|
+
});
|
|
32159
|
+
};
|
|
32160
|
+
|
|
32161
|
+
var _processTableToTransformNonAcceptableEmptyCols = (lines, emptyCols) => {
|
|
32162
|
+
return lines.map(line => line.map((cell, index) => cell === '' && !emptyCols.includes(index) ? undefined : cell));
|
|
32163
|
+
};
|
|
32164
|
+
|
|
32144
32165
|
var _buildRows = (rows, hasHeader, cols) => {
|
|
32145
32166
|
var formattedData = [];
|
|
32146
32167
|
var startIndex = hasHeader ? 1 : 0;
|
|
@@ -32180,8 +32201,10 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
32180
32201
|
var rows = [];
|
|
32181
32202
|
var csvLines;
|
|
32182
32203
|
|
|
32204
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32205
|
+
|
|
32183
32206
|
try {
|
|
32184
|
-
csvLines = CSVUtils.read(dataStr);
|
|
32207
|
+
csvLines = _processTableToTransformNonAcceptableEmptyCols(CSVUtils.read(dataStr), emptyCols);
|
|
32185
32208
|
} catch (err) {
|
|
32186
32209
|
return {
|
|
32187
32210
|
error: [err]
|
|
@@ -32270,8 +32293,11 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
32270
32293
|
var rows = [];
|
|
32271
32294
|
var xlsxLines;
|
|
32272
32295
|
|
|
32296
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32297
|
+
|
|
32273
32298
|
try {
|
|
32274
|
-
xlsxLines = yield XLSXUtils.read(fileBlob, true);
|
|
32299
|
+
xlsxLines = yield XLSXUtils.read(fileBlob, true, emptyCols.length > 0);
|
|
32300
|
+
if (emptyCols.length > 0) xlsxLines = _processTableToTransformNonAcceptableEmptyCols(xlsxLines, emptyCols);
|
|
32275
32301
|
} catch (err) {
|
|
32276
32302
|
return {
|
|
32277
32303
|
error: [new Error$1((err === null || err === void 0 ? void 0 : err.message) || err, fileBlob.name, (err === null || err === void 0 ? void 0 : err.stack) || null)]
|
package/dist/index.esm.js
CHANGED
|
@@ -20034,7 +20034,7 @@ var _castCellValueToStr = cellValue => {
|
|
|
20034
20034
|
};
|
|
20035
20035
|
|
|
20036
20036
|
var read = /*#__PURE__*/function () {
|
|
20037
|
-
var _ref = _asyncToGenerator(function* (fileBlob, forceStr) {
|
|
20037
|
+
var _ref = _asyncToGenerator(function* (fileBlob, forceStr, emptyCols) {
|
|
20038
20038
|
var data;
|
|
20039
20039
|
|
|
20040
20040
|
try {
|
|
@@ -20042,7 +20042,10 @@ var read = /*#__PURE__*/function () {
|
|
|
20042
20042
|
var workbook = readSync(buffer);
|
|
20043
20043
|
var worksheetName = workbook.SheetNames[0];
|
|
20044
20044
|
var worksheet = workbook.Sheets[worksheetName];
|
|
20045
|
-
data = utils.sheet_to_json(worksheet, {
|
|
20045
|
+
data = utils.sheet_to_json(worksheet, emptyCols ? {
|
|
20046
|
+
header: 1,
|
|
20047
|
+
defval: ''
|
|
20048
|
+
} : {
|
|
20046
20049
|
header: 1
|
|
20047
20050
|
});
|
|
20048
20051
|
} catch (err) {
|
|
@@ -20058,7 +20061,7 @@ var read = /*#__PURE__*/function () {
|
|
|
20058
20061
|
return data;
|
|
20059
20062
|
});
|
|
20060
20063
|
|
|
20061
|
-
return function read(_x, _x2) {
|
|
20064
|
+
return function read(_x, _x2, _x3) {
|
|
20062
20065
|
return _ref.apply(this, arguments);
|
|
20063
20066
|
};
|
|
20064
20067
|
}();
|
|
@@ -31944,7 +31947,13 @@ var isString = data => {
|
|
|
31944
31947
|
return typeof data === 'string';
|
|
31945
31948
|
};
|
|
31946
31949
|
|
|
31947
|
-
var isValid = (dataStr, type, options)
|
|
31950
|
+
var isValid = function isValid(dataStr, type, options) {
|
|
31951
|
+
var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
31952
|
+
|
|
31953
|
+
if (canBeEmpty && dataStr === '') {
|
|
31954
|
+
return true;
|
|
31955
|
+
}
|
|
31956
|
+
|
|
31948
31957
|
switch (type) {
|
|
31949
31958
|
case 'bool':
|
|
31950
31959
|
return isBool(dataStr);
|
|
@@ -32005,9 +32014,9 @@ class Error$1 {
|
|
|
32005
32014
|
}
|
|
32006
32015
|
|
|
32007
32016
|
var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row) => {
|
|
32008
|
-
var errorSummary = "Missing
|
|
32017
|
+
var errorSummary = "Missing field".concat(missingColsCount > 1 ? 's' : '');
|
|
32009
32018
|
var errorLoc = "Line ".concat(rowIndex);
|
|
32010
|
-
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, "
|
|
32019
|
+
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, " fields expected, ") + "but only ".concat(colsCount, " field").concat(colsCount > 1 ? 's' : '', " found\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
|
|
32011
32020
|
return new Error$1(errorSummary, errorLoc, errorContext);
|
|
32012
32021
|
};
|
|
32013
32022
|
|
|
@@ -32031,7 +32040,7 @@ var DEFAULT_CSV_EXPORT_OPTIONS = {
|
|
|
32031
32040
|
};
|
|
32032
32041
|
|
|
32033
32042
|
var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
|
|
32034
|
-
var colsCount = row.length;
|
|
32043
|
+
var colsCount = Object.values(row).filter(el => el !== undefined).length;
|
|
32035
32044
|
var expectedColsCount = expectedCols.length;
|
|
32036
32045
|
var expectedColsName = expectedCols.map(col => col.field).join();
|
|
32037
32046
|
var missingColsCount = expectedColsCount - colsCount;
|
|
@@ -32077,7 +32086,7 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32077
32086
|
var _loop = function _loop(rowIndex) {
|
|
32078
32087
|
var row = rows[rowIndex];
|
|
32079
32088
|
|
|
32080
|
-
if (row.length < knownColsCount) {
|
|
32089
|
+
if (row.length < knownColsCount || row.includes(undefined)) {
|
|
32081
32090
|
errors.push(_forgeColumnsCountError(rows[rowIndex], rowIndex, colsData));
|
|
32082
32091
|
}
|
|
32083
32092
|
|
|
@@ -32085,8 +32094,8 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32085
32094
|
if (colIndex < knownColsCount) {
|
|
32086
32095
|
var colType = colsData[colIndex].type;
|
|
32087
32096
|
|
|
32088
|
-
if (colType) {
|
|
32089
|
-
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c;
|
|
32097
|
+
if (colType && rowCell !== undefined) {
|
|
32098
|
+
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c, _colsData$colIndex$ce, _colsData$colIndex$ce2;
|
|
32090
32099
|
|
|
32091
32100
|
var enumValues = ((_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) || ((_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 ? void 0 : (_colsData$colIndex2$c = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2$c === void 0 ? void 0 : _colsData$colIndex2$c.enumValues);
|
|
32092
32101
|
|
|
@@ -32094,7 +32103,9 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32094
32103
|
enumValues: enumValues
|
|
32095
32104
|
});
|
|
32096
32105
|
|
|
32097
|
-
|
|
32106
|
+
var acceptsEmptyFields = (_colsData$colIndex$ce = (_colsData$colIndex$ce2 = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce2 === void 0 ? void 0 : _colsData$colIndex$ce2.acceptsEmptyFields) !== null && _colsData$colIndex$ce !== void 0 ? _colsData$colIndex$ce : false;
|
|
32107
|
+
|
|
32108
|
+
if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
|
|
32098
32109
|
errors.push(_forgeTypeError(rowCell, rowIndex, colType, colOptions, colsData, colIndex));
|
|
32099
32110
|
}
|
|
32100
32111
|
}
|
|
@@ -32117,8 +32128,6 @@ var _reformatBoolValue = csvCellValue => {
|
|
|
32117
32128
|
} else if (['1', 'true', 'yes'].includes(csvCellValue)) {
|
|
32118
32129
|
return 'true';
|
|
32119
32130
|
}
|
|
32120
|
-
|
|
32121
|
-
return null;
|
|
32122
32131
|
};
|
|
32123
32132
|
|
|
32124
32133
|
var _reformatValue = (csvCellValue, colTypes) => {
|
|
@@ -32133,6 +32142,18 @@ var _buildCols = header => header.map(col => ({
|
|
|
32133
32142
|
field: col
|
|
32134
32143
|
}));
|
|
32135
32144
|
|
|
32145
|
+
var _calculateEmptyCols = cols => {
|
|
32146
|
+
return cols.map((_, index) => index).filter(colIndex => {
|
|
32147
|
+
var _cols$colIndex$cellEd;
|
|
32148
|
+
|
|
32149
|
+
return (_cols$colIndex$cellEd = cols[colIndex].cellEditorParams) === null || _cols$colIndex$cellEd === void 0 ? void 0 : _cols$colIndex$cellEd.acceptsEmptyFields;
|
|
32150
|
+
});
|
|
32151
|
+
};
|
|
32152
|
+
|
|
32153
|
+
var _processTableToTransformNonAcceptableEmptyCols = (lines, emptyCols) => {
|
|
32154
|
+
return lines.map(line => line.map((cell, index) => cell === '' && !emptyCols.includes(index) ? undefined : cell));
|
|
32155
|
+
};
|
|
32156
|
+
|
|
32136
32157
|
var _buildRows = (rows, hasHeader, cols) => {
|
|
32137
32158
|
var formattedData = [];
|
|
32138
32159
|
var startIndex = hasHeader ? 1 : 0;
|
|
@@ -32172,8 +32193,10 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
32172
32193
|
var rows = [];
|
|
32173
32194
|
var csvLines;
|
|
32174
32195
|
|
|
32196
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32197
|
+
|
|
32175
32198
|
try {
|
|
32176
|
-
csvLines = CSVUtils.read(dataStr);
|
|
32199
|
+
csvLines = _processTableToTransformNonAcceptableEmptyCols(CSVUtils.read(dataStr), emptyCols);
|
|
32177
32200
|
} catch (err) {
|
|
32178
32201
|
return {
|
|
32179
32202
|
error: [err]
|
|
@@ -32262,8 +32285,11 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
32262
32285
|
var rows = [];
|
|
32263
32286
|
var xlsxLines;
|
|
32264
32287
|
|
|
32288
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32289
|
+
|
|
32265
32290
|
try {
|
|
32266
|
-
xlsxLines = yield XLSXUtils.read(fileBlob, true);
|
|
32291
|
+
xlsxLines = yield XLSXUtils.read(fileBlob, true, emptyCols.length > 0);
|
|
32292
|
+
if (emptyCols.length > 0) xlsxLines = _processTableToTransformNonAcceptableEmptyCols(xlsxLines, emptyCols);
|
|
32267
32293
|
} catch (err) {
|
|
32268
32294
|
return {
|
|
32269
32295
|
error: [new Error$1((err === null || err === void 0 ? void 0 : err.message) || err, fileBlob.name, (err === null || err === void 0 ? void 0 : err.stack) || null)]
|