@cosmotech/core 1.11.6 → 1.12.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 +10 -0
- package/dist/index.cjs.js +26 -9
- package/dist/index.esm.js +26 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## **1.12.0** <sub><sup>2023-09-05 (e96188d...05e2b63)</sup></sub>
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- add new function getFlattenColumnsWithoutGroups ([e96188d](https://github.com/Cosmo-Tech/webapp-component-core/commit/e96188d))
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- fix import & export of CSV/XLSX files when some columns are grouped ([193ac62](https://github.com/Cosmo-Tech/webapp-component-core/commit/193ac62))
|
|
10
|
+
|
|
1
11
|
## **1.11.6** <sub><sup>2023-08-28 (a1a83d2...a1a83d2)</sup></sub>
|
|
2
12
|
|
|
3
13
|
### Bug Fixes
|
package/dist/index.cjs.js
CHANGED
|
@@ -41495,6 +41495,18 @@ let Error$1 = class Error {
|
|
|
41495
41495
|
}
|
|
41496
41496
|
};
|
|
41497
41497
|
|
|
41498
|
+
var getFlattenColumnsWithoutGroups = columns => {
|
|
41499
|
+
if (columns == null) {
|
|
41500
|
+
console.warn("Columns list shouldn't be null or undefined");
|
|
41501
|
+
return [];
|
|
41502
|
+
}
|
|
41503
|
+
return columns.flatMap(columnOrGroup => {
|
|
41504
|
+
if (columnOrGroup == null) {
|
|
41505
|
+
console.warn('Null or undefined values found in columns list');
|
|
41506
|
+
}
|
|
41507
|
+
return columnOrGroup !== null && columnOrGroup !== void 0 && columnOrGroup.children ? getFlattenColumnsWithoutGroups(columnOrGroup.children) : columnOrGroup;
|
|
41508
|
+
}).filter(column => column != null);
|
|
41509
|
+
};
|
|
41498
41510
|
var _buildEmptyFieldError = (rowLineNumber, expectedCols, colIndex) => {
|
|
41499
41511
|
var errorSummary = "Empty field";
|
|
41500
41512
|
var errorLoc = "Line ".concat(rowLineNumber, ", Column ").concat(colIndex + 1, " (\"").concat(expectedCols[colIndex].field, "\")");
|
|
@@ -41637,9 +41649,9 @@ var _buildRows = (rows, hasHeader, cols) => {
|
|
|
41637
41649
|
};
|
|
41638
41650
|
var fromCSV = function fromCSV(dataStr) {
|
|
41639
41651
|
var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
41640
|
-
var
|
|
41652
|
+
var nestedCols = arguments.length > 2 ? arguments[2] : undefined;
|
|
41641
41653
|
var options = arguments.length > 3 ? arguments[3] : undefined;
|
|
41642
|
-
if (!hasHeader && !
|
|
41654
|
+
if (!hasHeader && !nestedCols) {
|
|
41643
41655
|
return {
|
|
41644
41656
|
error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
|
|
41645
41657
|
};
|
|
@@ -41650,6 +41662,7 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
41650
41662
|
rows: []
|
|
41651
41663
|
};
|
|
41652
41664
|
}
|
|
41665
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41653
41666
|
var rows = [];
|
|
41654
41667
|
var csvLines;
|
|
41655
41668
|
var emptyCols = _calculateEmptyCols(cols);
|
|
@@ -41660,7 +41673,7 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
41660
41673
|
error: [err]
|
|
41661
41674
|
};
|
|
41662
41675
|
}
|
|
41663
|
-
if (!cols) {
|
|
41676
|
+
if (!cols || cols.length === 0) {
|
|
41664
41677
|
cols = _buildCols(csvLines[0]);
|
|
41665
41678
|
}
|
|
41666
41679
|
var errors = _validateFormat(csvLines, hasHeader, cols, options);
|
|
@@ -41689,12 +41702,13 @@ var _generateRows = function _generateRows(rows, cols) {
|
|
|
41689
41702
|
var rowSep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '\n';
|
|
41690
41703
|
return rows.map(row => _generateRow(row, cols, colSep)).join(rowSep);
|
|
41691
41704
|
};
|
|
41692
|
-
var toCSV = (rows,
|
|
41693
|
-
if (
|
|
41705
|
+
var toCSV = (rows, nestedCols, options) => {
|
|
41706
|
+
if (nestedCols == null || nestedCols.length === 0) {
|
|
41694
41707
|
return {
|
|
41695
41708
|
error: ["Cols must be defined"]
|
|
41696
41709
|
};
|
|
41697
41710
|
}
|
|
41711
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41698
41712
|
if (!rows) {
|
|
41699
41713
|
rows = [];
|
|
41700
41714
|
}
|
|
@@ -41712,10 +41726,11 @@ var toCSV = (rows, cols, options) => {
|
|
|
41712
41726
|
|
|
41713
41727
|
// TODO: some metadata of cols & options ('acceptsEmptyFields', columns types, dates format, ...) are not used right
|
|
41714
41728
|
// now, but they could be used in a future version to improve the format of the exported Excel file
|
|
41715
|
-
var toXLSX = (rows,
|
|
41729
|
+
var toXLSX = (rows, nestedCols, options) => {
|
|
41716
41730
|
if (!rows) {
|
|
41717
41731
|
rows = [];
|
|
41718
41732
|
}
|
|
41733
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41719
41734
|
options = _objectSpread2(_objectSpread2({}, DEFAULT_XLSX_EXPORT_OPTIONS), options);
|
|
41720
41735
|
var header = options.writeHeader ? cols.map(col => col.field) : null;
|
|
41721
41736
|
return XLSXUtils.write(rows, header);
|
|
@@ -41723,9 +41738,9 @@ var toXLSX = (rows, cols, options) => {
|
|
|
41723
41738
|
var fromXLSX = /*#__PURE__*/function () {
|
|
41724
41739
|
var _ref2 = _asyncToGenerator(function* (fileBlob) {
|
|
41725
41740
|
var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
41726
|
-
var
|
|
41741
|
+
var nestedCols = arguments.length > 2 ? arguments[2] : undefined;
|
|
41727
41742
|
var options = arguments.length > 3 ? arguments[3] : undefined;
|
|
41728
|
-
if (!hasHeader && !
|
|
41743
|
+
if (!hasHeader && !nestedCols) {
|
|
41729
41744
|
return {
|
|
41730
41745
|
error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
|
|
41731
41746
|
};
|
|
@@ -41736,6 +41751,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41736
41751
|
rows: []
|
|
41737
41752
|
};
|
|
41738
41753
|
}
|
|
41754
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41739
41755
|
var rows = [];
|
|
41740
41756
|
var xlsxLines;
|
|
41741
41757
|
var emptyCols = _calculateEmptyCols(cols);
|
|
@@ -41747,7 +41763,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41747
41763
|
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)]
|
|
41748
41764
|
};
|
|
41749
41765
|
}
|
|
41750
|
-
if (!cols) {
|
|
41766
|
+
if (!cols || cols.length === 0) {
|
|
41751
41767
|
cols = _buildCols(xlsxLines[0]);
|
|
41752
41768
|
}
|
|
41753
41769
|
var errors = _validateFormat(xlsxLines, hasHeader, cols, options);
|
|
@@ -41767,6 +41783,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41767
41783
|
var AgGridUtils = {
|
|
41768
41784
|
fromCSV,
|
|
41769
41785
|
fromXLSX,
|
|
41786
|
+
getFlattenColumnsWithoutGroups,
|
|
41770
41787
|
toCSV,
|
|
41771
41788
|
toXLSX
|
|
41772
41789
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -41493,6 +41493,18 @@ let Error$1 = class Error {
|
|
|
41493
41493
|
}
|
|
41494
41494
|
};
|
|
41495
41495
|
|
|
41496
|
+
var getFlattenColumnsWithoutGroups = columns => {
|
|
41497
|
+
if (columns == null) {
|
|
41498
|
+
console.warn("Columns list shouldn't be null or undefined");
|
|
41499
|
+
return [];
|
|
41500
|
+
}
|
|
41501
|
+
return columns.flatMap(columnOrGroup => {
|
|
41502
|
+
if (columnOrGroup == null) {
|
|
41503
|
+
console.warn('Null or undefined values found in columns list');
|
|
41504
|
+
}
|
|
41505
|
+
return columnOrGroup !== null && columnOrGroup !== void 0 && columnOrGroup.children ? getFlattenColumnsWithoutGroups(columnOrGroup.children) : columnOrGroup;
|
|
41506
|
+
}).filter(column => column != null);
|
|
41507
|
+
};
|
|
41496
41508
|
var _buildEmptyFieldError = (rowLineNumber, expectedCols, colIndex) => {
|
|
41497
41509
|
var errorSummary = "Empty field";
|
|
41498
41510
|
var errorLoc = "Line ".concat(rowLineNumber, ", Column ").concat(colIndex + 1, " (\"").concat(expectedCols[colIndex].field, "\")");
|
|
@@ -41635,9 +41647,9 @@ var _buildRows = (rows, hasHeader, cols) => {
|
|
|
41635
41647
|
};
|
|
41636
41648
|
var fromCSV = function fromCSV(dataStr) {
|
|
41637
41649
|
var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
41638
|
-
var
|
|
41650
|
+
var nestedCols = arguments.length > 2 ? arguments[2] : undefined;
|
|
41639
41651
|
var options = arguments.length > 3 ? arguments[3] : undefined;
|
|
41640
|
-
if (!hasHeader && !
|
|
41652
|
+
if (!hasHeader && !nestedCols) {
|
|
41641
41653
|
return {
|
|
41642
41654
|
error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
|
|
41643
41655
|
};
|
|
@@ -41648,6 +41660,7 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
41648
41660
|
rows: []
|
|
41649
41661
|
};
|
|
41650
41662
|
}
|
|
41663
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41651
41664
|
var rows = [];
|
|
41652
41665
|
var csvLines;
|
|
41653
41666
|
var emptyCols = _calculateEmptyCols(cols);
|
|
@@ -41658,7 +41671,7 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
41658
41671
|
error: [err]
|
|
41659
41672
|
};
|
|
41660
41673
|
}
|
|
41661
|
-
if (!cols) {
|
|
41674
|
+
if (!cols || cols.length === 0) {
|
|
41662
41675
|
cols = _buildCols(csvLines[0]);
|
|
41663
41676
|
}
|
|
41664
41677
|
var errors = _validateFormat(csvLines, hasHeader, cols, options);
|
|
@@ -41687,12 +41700,13 @@ var _generateRows = function _generateRows(rows, cols) {
|
|
|
41687
41700
|
var rowSep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '\n';
|
|
41688
41701
|
return rows.map(row => _generateRow(row, cols, colSep)).join(rowSep);
|
|
41689
41702
|
};
|
|
41690
|
-
var toCSV = (rows,
|
|
41691
|
-
if (
|
|
41703
|
+
var toCSV = (rows, nestedCols, options) => {
|
|
41704
|
+
if (nestedCols == null || nestedCols.length === 0) {
|
|
41692
41705
|
return {
|
|
41693
41706
|
error: ["Cols must be defined"]
|
|
41694
41707
|
};
|
|
41695
41708
|
}
|
|
41709
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41696
41710
|
if (!rows) {
|
|
41697
41711
|
rows = [];
|
|
41698
41712
|
}
|
|
@@ -41710,10 +41724,11 @@ var toCSV = (rows, cols, options) => {
|
|
|
41710
41724
|
|
|
41711
41725
|
// TODO: some metadata of cols & options ('acceptsEmptyFields', columns types, dates format, ...) are not used right
|
|
41712
41726
|
// now, but they could be used in a future version to improve the format of the exported Excel file
|
|
41713
|
-
var toXLSX = (rows,
|
|
41727
|
+
var toXLSX = (rows, nestedCols, options) => {
|
|
41714
41728
|
if (!rows) {
|
|
41715
41729
|
rows = [];
|
|
41716
41730
|
}
|
|
41731
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41717
41732
|
options = _objectSpread2(_objectSpread2({}, DEFAULT_XLSX_EXPORT_OPTIONS), options);
|
|
41718
41733
|
var header = options.writeHeader ? cols.map(col => col.field) : null;
|
|
41719
41734
|
return XLSXUtils.write(rows, header);
|
|
@@ -41721,9 +41736,9 @@ var toXLSX = (rows, cols, options) => {
|
|
|
41721
41736
|
var fromXLSX = /*#__PURE__*/function () {
|
|
41722
41737
|
var _ref2 = _asyncToGenerator(function* (fileBlob) {
|
|
41723
41738
|
var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
41724
|
-
var
|
|
41739
|
+
var nestedCols = arguments.length > 2 ? arguments[2] : undefined;
|
|
41725
41740
|
var options = arguments.length > 3 ? arguments[3] : undefined;
|
|
41726
|
-
if (!hasHeader && !
|
|
41741
|
+
if (!hasHeader && !nestedCols) {
|
|
41727
41742
|
return {
|
|
41728
41743
|
error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
|
|
41729
41744
|
};
|
|
@@ -41734,6 +41749,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41734
41749
|
rows: []
|
|
41735
41750
|
};
|
|
41736
41751
|
}
|
|
41752
|
+
var cols = getFlattenColumnsWithoutGroups(nestedCols);
|
|
41737
41753
|
var rows = [];
|
|
41738
41754
|
var xlsxLines;
|
|
41739
41755
|
var emptyCols = _calculateEmptyCols(cols);
|
|
@@ -41745,7 +41761,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41745
41761
|
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)]
|
|
41746
41762
|
};
|
|
41747
41763
|
}
|
|
41748
|
-
if (!cols) {
|
|
41764
|
+
if (!cols || cols.length === 0) {
|
|
41749
41765
|
cols = _buildCols(xlsxLines[0]);
|
|
41750
41766
|
}
|
|
41751
41767
|
var errors = _validateFormat(xlsxLines, hasHeader, cols, options);
|
|
@@ -41765,6 +41781,7 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
41765
41781
|
var AgGridUtils = {
|
|
41766
41782
|
fromCSV,
|
|
41767
41783
|
fromXLSX,
|
|
41784
|
+
getFlattenColumnsWithoutGroups,
|
|
41768
41785
|
toCSV,
|
|
41769
41786
|
toXLSX
|
|
41770
41787
|
};
|