@lingk/sync 1.1.14 → 1.1.16

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.
@@ -3648,7 +3648,7 @@ module.exports =
3648
3648
  f = Math.floor(Math.log(a) / Math.log(c));return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
3649
3649
  }
3650
3650
 
3651
- var extensionBlacklist = ['xls', 'xlsx', 'xml', 'zip', 'tar', 'gz'];
3651
+ var extensionBlacklist = ['xml', 'zip', 'tar', 'gz'];
3652
3652
 
3653
3653
  var FlatFile = function (_Component) {
3654
3654
  _inherits(FlatFile, _Component);
@@ -3697,6 +3697,11 @@ module.exports =
3697
3697
  }
3698
3698
  };
3699
3699
 
3700
+ _this.parseJsonLines = function (content) {
3701
+ var firstLine = content.substring(0, content.indexOf('\n'));
3702
+ return '[' + firstLine + ']';
3703
+ };
3704
+
3700
3705
  _this.parseCSV = function (file, csv) {
3701
3706
  return new Promise(function (resolve, reject) {
3702
3707
  _papaparse2.default.parse(csv || file, {
@@ -3734,36 +3739,39 @@ module.exports =
3734
3739
  var blacklisted = extensionBlacklist.includes(extension);
3735
3740
  if (!blacklisted) {
3736
3741
  (function () {
3737
-
3738
3742
  var isXLS = extension === 'xlsx' || extension === 'xls';
3739
3743
 
3740
3744
  var reader = new FileReader();
3741
3745
  reader.onload = function (e) {
3742
3746
 
3747
+ // PARSE METADATA
3743
3748
  var data = e.target.result;
3744
3749
  var csv = null;
3745
3750
  if (isXLS) {
3746
- var i;
3747
-
3748
3751
  (function () {
3749
- var binary = '';
3750
- var bytes = new Uint8Array(data);
3751
- for (i = 0; i < length; i++) {
3752
+ var sheetCounter = 0;
3753
+ var binary = data;
3754
+ /*const bytes = new Uint8Array(data)
3755
+ for (var i = 0; i < length; i++) {
3752
3756
  binary += String.fromCharCode(bytes[i]);
3753
- }
3757
+ }*/
3754
3758
  var workbook = _xlsx2.default.read(binary, { type: 'binary' });
3755
- workbook.SheetNames.forEach(function (sn) {
3756
- if (sn !== 'Export Summary') {
3757
- csv = _xlsx2.default.utils.sheet_to_csv(workbook.Sheets[sn]);
3758
- _this.parseCSV(file, csv).then(function (xlsMeta) {
3759
- meta = meta.concat(xlsMeta);
3760
- counter += 1;
3761
- if (counter === fs.length) {
3762
- _this.setState({ meta: meta });
3763
- _this.props.onDrop();
3764
- }
3765
- });
3766
- }
3759
+ var sheetNames = workbook.SheetNames.filter(function (sn) {
3760
+ return sn !== 'Export Summary';
3761
+ });
3762
+ sheetNames.forEach(function (sn) {
3763
+ csv = _xlsx2.default.utils.sheet_to_csv(workbook.Sheets[sn]);
3764
+ _this.parseCSV(file, csv).then(function (xlsMeta) {
3765
+ meta = meta.concat(Object.assign({}, xlsMeta, {
3766
+ sheetName: sn
3767
+ }));
3768
+ sheetCounter += 1;
3769
+ counter += 1;
3770
+ if (counter >= fs.length && sheetCounter === sheetNames.length) {
3771
+ _this.setState({ meta: meta });
3772
+ _this.props.onDrop();
3773
+ }
3774
+ });
3767
3775
  });
3768
3776
  })();
3769
3777
  } else if (extension === 'csv') {
@@ -3775,8 +3783,12 @@ module.exports =
3775
3783
  _this.props.onDrop();
3776
3784
  }
3777
3785
  });
3778
- } else if (extension === 'json') {
3779
- var fileMeta = _this.parseJsonFile(data, file);
3786
+ } else if (extension === 'json' || extension === 'jsonl') {
3787
+ var d = data;
3788
+ if (extension === 'jsonl') {
3789
+ d = _this.parseJsonLines(data);
3790
+ }
3791
+ var fileMeta = _this.parseJsonFile(d, file);
3780
3792
  if (fileMeta) {
3781
3793
  meta = meta.concat(fileMeta);
3782
3794
  counter += 1;
@@ -3787,7 +3799,8 @@ module.exports =
3787
3799
  }
3788
3800
  }
3789
3801
 
3790
- fileContents = fileContents.concat(data);
3802
+ // ADD TO CONTENTS, TO UPLOAD
3803
+ fileContents = fileContents.concat(file);
3791
3804
  contentCounter += 1;
3792
3805
  if (contentCounter === fs.length) {
3793
3806
  _this.setState({ fileContents: fileContents });
@@ -3795,7 +3808,7 @@ module.exports =
3795
3808
  }; // end file reader on load callback
3796
3809
 
3797
3810
  if (isXLS) {
3798
- reader.readAsArrayBuffer(file); // read as binary string???
3811
+ reader.readAsBinaryString(file); // read as array buffer???
3799
3812
  } else {
3800
3813
  reader.readAsText(file);
3801
3814
  }
@@ -3858,15 +3871,32 @@ module.exports =
3858
3871
  var hasFile = meta && meta.length > 0;
3859
3872
 
3860
3873
  var fileSchema = [];
3861
- if (this.props.fileSchema && this.props.fileSchema.length) {
3862
- fileSchema = [].concat(_toConsumableArray(this.props.fileSchema));
3874
+ var fileSchemaNames = [];
3875
+ this.props.fileSchema && this.props.fileSchema.forEach(function (f) {
3876
+ if (!fileSchemaNames.includes(f.name)) {
3877
+ fileSchema.push(f);
3878
+ fileSchemaNames.push(f.name);
3879
+ }
3880
+ });
3881
+ if (fileSchema && fileSchema.length) {
3863
3882
  fileSchema = fileSchema.sort(function (a, b) {
3864
3883
  var term = sortFileTableBy;
3865
- if (term === 'uploadedTime') {}
3884
+ if (term === 'uploadedTime') {
3885
+ return a[term] < b[term];
3886
+ }
3866
3887
  return a[term] > b[term];
3867
3888
  });
3868
3889
  }
3869
3890
 
3891
+ var droppedFiles = [];
3892
+ var droppedFileNames = [];
3893
+ meta && meta.forEach(function (f) {
3894
+ if (!droppedFileNames.includes(f.name)) {
3895
+ droppedFiles.push(f);
3896
+ droppedFileNames.push(f.name);
3897
+ }
3898
+ });
3899
+
3870
3900
  return _react2.default.createElement(
3871
3901
  'div',
3872
3902
  null,
@@ -3880,7 +3910,7 @@ module.exports =
3880
3910
  !dropError ? _react2.default.createElement(
3881
3911
  'p',
3882
3912
  null,
3883
- 'Drop one or more CSV files here, or click to select files to upload.'
3913
+ 'Drop one or more files here, or click to select files to upload.'
3884
3914
  ) : _react2.default.createElement(
3885
3915
  'p',
3886
3916
  { style: { color: '#c9302c', fontWeight: 'bold' } },
@@ -3927,7 +3957,7 @@ module.exports =
3927
3957
  _react2.default.createElement(
3928
3958
  'ul',
3929
3959
  { style: { padding: 0 } },
3930
- meta.map(function (f, i) {
3960
+ droppedFiles.map(function (f, i) {
3931
3961
  return _react2.default.createElement(
3932
3962
  'li',
3933
3963
  { key: i, style: { listStyle: 'none' } },