ui-kit-ck-consultant 0.6.11 → 0.6.13

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/dist/index.js CHANGED
@@ -884,32 +884,55 @@ var Table = /*#__PURE__*/function (_React$Component) {
884
884
  };
885
885
 
886
886
  _this.getCSV = function (callback) {
887
+ extractText = function extractText(node) {
888
+ if (typeof node === 'string') return node.trim();
889
+ if (Array.isArray(node)) return node.map(_this.extractText).join(' ');
890
+ if (node.props && node.props.children) return _this.extractText(node.props.children);
891
+ return '';
892
+ };
893
+
887
894
  var dataCSV = '';
888
895
 
889
896
  if (_this.props && _this.props.children) {
890
- _this.getArray(_this.props.children).forEach(function (children) {
891
- if (children.props && children.props.children) {
892
- _this.getArray(children.props.children).forEach(function (line) {
893
- if (line.props && line.props.children) {
894
- _this.getArray(line.props.children).forEach(function (column) {
895
- if (column && column.props && column.props.children && column.props.children.props && column.props.children.props.children && column.props.children.props.children.props && column.props.children.props.children.props.children && column.props.children.props.children.props.children.props && column.props.children.props.children.props.children.props.text) {
896
- dataCSV += column.props.children.props.text + ";";
897
- } else if (column && column.props && column.props.children && column.props.children.props && column.props.children.props.children && column.props.children.props.children.props && column.props.children.props.children.props.text) {
898
- dataCSV += column.props.children.props.text + ";";
899
- } else if (column && column.props && column.props.children && column.props.children.props && column.props.children.props.text) {
900
- dataCSV += column.props.children.props.text + ";";
901
- } else if (column && column.props && column.props.children) {
902
- dataCSV += column.props.children.toString() + ";";
903
- } else {
904
- dataCSV += ';';
905
- }
906
- });
897
+ var table = _this.getArray(_this.props.children).find(function (child) {
898
+ return child.type === 'table';
899
+ });
900
+
901
+ if (table) {
902
+ var thead = _this.getArray(table.props.children).find(function (child) {
903
+ return child.type === 'thead';
904
+ });
905
+
906
+ var tbody = _this.getArray(table.props.children).find(function (child) {
907
+ return child.type === 'tbody';
908
+ });
907
909
 
908
- dataCSV += '\n';
910
+ if (thead) {
911
+ var headerRow = _this.getArray(thead.props.children).find(function (row) {
912
+ return row.type === 'tr';
913
+ });
914
+
915
+ if (headerRow) {
916
+ var headers = _this.getArray(headerRow.props.children).map(function (th) {
917
+ return th.props && th.props.children ? _this.extractText(th.props.children) : '';
918
+ }).join(';');
919
+
920
+ dataCSV += headers + '\n';
921
+ }
922
+ }
923
+
924
+ if (tbody) {
925
+ _this.getArray(tbody.props.children).forEach(function (row) {
926
+ if (row.type === 'tr') {
927
+ var rowData = _this.getArray(row.props.children).map(function (td) {
928
+ return td.props && td.props.children ? _this.extractText(td.props.children) : '';
929
+ }).join(';');
930
+
931
+ dataCSV += rowData + '\n';
909
932
  }
910
933
  });
911
934
  }
912
- });
935
+ }
913
936
  }
914
937
 
915
938
  var link = document.createElement('a');